Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
赵月辉
/
fastgpt-migrated
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Unverified
Commit
cdf4b9f3
authored
May 10, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
perf: prompt and gpt4
parent
e3c9b817
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
47 additions
and
24 deletions
+47
-24
src/api/request.ts
+2
-2
src/api/user.ts
+2
-0
src/constants/model.ts
+6
-5
src/pages/api/chat/chat.ts
+2
-2
src/pages/api/user/loginout.ts
+16
-0
src/pages/number/index.tsx
+2
-2
src/pages/promotion/index.tsx
+1
-1
src/service/plugins/searchKb.ts
+3
-3
src/service/utils/auth.ts
+2
-2
src/service/utils/chat/claude.ts
+2
-2
src/service/utils/chat/index.ts
+2
-2
src/utils/user.ts
+7
-3
No files found.
src/api/request.ts
View file @
cdf4b9f3
import
axios
,
{
Method
,
InternalAxiosRequestConfig
,
AxiosResponse
}
from
'axios'
;
import
axios
,
{
Method
,
InternalAxiosRequestConfig
,
AxiosResponse
}
from
'axios'
;
import
{
clear
Token
}
from
'@/utils/user'
;
import
{
clear
Cookie
}
from
'@/utils/user'
;
import
{
TOKEN_ERROR_CODE
}
from
'@/service/errorCode'
;
import
{
TOKEN_ERROR_CODE
}
from
'@/service/errorCode'
;
interface
ConfigType
{
interface
ConfigType
{
...
@@ -58,7 +58,7 @@ function responseError(err: any) {
...
@@ -58,7 +58,7 @@ function responseError(err: any) {
// 有报错响应
// 有报错响应
const
res
=
err
.
response
;
const
res
=
err
.
response
;
if
(
res
.
data
.
code
in
TOKEN_ERROR_CODE
)
{
if
(
res
.
data
.
code
in
TOKEN_ERROR_CODE
)
{
clear
Token
();
clear
Cookie
();
return
Promise
.
reject
({
message
:
'token过期,重新登录'
});
return
Promise
.
reject
({
message
:
'token过期,重新登录'
});
}
}
}
}
...
...
src/api/user.ts
View file @
cdf4b9f3
...
@@ -64,6 +64,8 @@ export const postLogin = ({ username, password }: { username: string; password:
...
@@ -64,6 +64,8 @@ export const postLogin = ({ username, password }: { username: string; password:
password
:
createHashPassword
(
password
)
password
:
createHashPassword
(
password
)
});
});
export
const
loginOut
=
()
=>
GET
(
'/user/loginout'
);
export
const
putUserInfo
=
(
data
:
UserUpdateParams
)
=>
PUT
(
'/user/update'
,
data
);
export
const
putUserInfo
=
(
data
:
UserUpdateParams
)
=>
PUT
(
'/user/update'
,
data
);
export
const
getUserBills
=
(
data
:
RequestPaging
)
=>
export
const
getUserBills
=
(
data
:
RequestPaging
)
=>
...
...
src/constants/model.ts
View file @
cdf4b9f3
...
@@ -29,7 +29,7 @@ export const ChatModelMap = {
...
@@ -29,7 +29,7 @@ export const ChatModelMap = {
name
:
'ChatGpt'
,
name
:
'ChatGpt'
,
contextMaxToken
:
4096
,
contextMaxToken
:
4096
,
systemMaxToken
:
2500
,
systemMaxToken
:
2500
,
maxTemperature
:
1.
5
,
maxTemperature
:
1.
2
,
price
:
3
price
:
3
},
},
[
OpenAiChatEnum
.
GPT4
]:
{
[
OpenAiChatEnum
.
GPT4
]:
{
...
@@ -37,16 +37,16 @@ export const ChatModelMap = {
...
@@ -37,16 +37,16 @@ export const ChatModelMap = {
name
:
'Gpt4'
,
name
:
'Gpt4'
,
contextMaxToken
:
8000
,
contextMaxToken
:
8000
,
systemMaxToken
:
3500
,
systemMaxToken
:
3500
,
maxTemperature
:
1.
5
,
maxTemperature
:
1.
2
,
price
:
3
0
price
:
5
0
},
},
[
OpenAiChatEnum
.
GPT432k
]:
{
[
OpenAiChatEnum
.
GPT432k
]:
{
chatModel
:
OpenAiChatEnum
.
GPT432k
,
chatModel
:
OpenAiChatEnum
.
GPT432k
,
name
:
'Gpt4-32k'
,
name
:
'Gpt4-32k'
,
contextMaxToken
:
32000
,
contextMaxToken
:
32000
,
systemMaxToken
:
6000
,
systemMaxToken
:
6000
,
maxTemperature
:
1.
5
,
maxTemperature
:
1.
2
,
price
:
3
0
price
:
9
0
},
},
[
ClaudeEnum
.
Claude
]:
{
[
ClaudeEnum
.
Claude
]:
{
chatModel
:
ClaudeEnum
.
Claude
,
chatModel
:
ClaudeEnum
.
Claude
,
...
@@ -60,6 +60,7 @@ export const ChatModelMap = {
...
@@ -60,6 +60,7 @@ export const ChatModelMap = {
export
const
chatModelList
:
ChatModelItemType
[]
=
[
export
const
chatModelList
:
ChatModelItemType
[]
=
[
ChatModelMap
[
OpenAiChatEnum
.
GPT35
],
ChatModelMap
[
OpenAiChatEnum
.
GPT35
],
ChatModelMap
[
OpenAiChatEnum
.
GPT4
],
ChatModelMap
[
ClaudeEnum
.
Claude
]
ChatModelMap
[
ClaudeEnum
.
Claude
]
];
];
...
...
src/pages/api/chat/chat.ts
View file @
cdf4b9f3
...
@@ -68,11 +68,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
...
@@ -68,11 +68,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
return
res
.
send
(
searchPrompts
[
0
]?.
value
);
return
res
.
send
(
searchPrompts
[
0
]?.
value
);
}
}
prompts
.
splice
(
prompts
.
length
-
1
,
0
,
...
searchPrompts
);
prompts
.
splice
(
prompts
.
length
-
3
,
0
,
...
searchPrompts
);
}
else
{
}
else
{
// 没有用知识库搜索,仅用系统提示词
// 没有用知识库搜索,仅用系统提示词
model
.
chat
.
systemPrompt
&&
model
.
chat
.
systemPrompt
&&
prompts
.
splice
(
prompts
.
length
-
1
,
0
,
{
prompts
.
splice
(
prompts
.
length
-
3
,
0
,
{
obj
:
ChatRoleEnum
.
System
,
obj
:
ChatRoleEnum
.
System
,
value
:
model
.
chat
.
systemPrompt
value
:
model
.
chat
.
systemPrompt
});
});
...
...
src/pages/api/user/loginout.ts
0 → 100644
View file @
cdf4b9f3
// Next.js API route support: https://nextjs.org/docs/api-routes/introduction
import
type
{
NextApiRequest
,
NextApiResponse
}
from
'next'
;
import
{
jsonRes
}
from
'@/service/response'
;
import
{
clearCookie
}
from
'@/service/utils/tools'
;
export
default
async
function
handler
(
req
:
NextApiRequest
,
res
:
NextApiResponse
<
any
>
)
{
try
{
clearCookie
(
res
);
jsonRes
(
res
);
}
catch
(
err
)
{
jsonRes
(
res
,
{
code
:
500
,
error
:
err
});
}
}
src/pages/number/index.tsx
View file @
cdf4b9f3
...
@@ -7,7 +7,7 @@ import { useToast } from '@/hooks/useToast';
...
@@ -7,7 +7,7 @@ import { useToast } from '@/hooks/useToast';
import
{
useGlobalStore
}
from
'@/store/global'
;
import
{
useGlobalStore
}
from
'@/store/global'
;
import
{
useUserStore
}
from
'@/store/user'
;
import
{
useUserStore
}
from
'@/store/user'
;
import
{
UserType
}
from
'@/types/user'
;
import
{
UserType
}
from
'@/types/user'
;
import
{
clear
Token
}
from
'@/utils/user'
;
import
{
clear
Cookie
}
from
'@/utils/user'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useRouter
}
from
'next/router'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
{
useQuery
}
from
'@tanstack/react-query'
;
import
dynamic
from
'next/dynamic'
;
import
dynamic
from
'next/dynamic'
;
...
@@ -75,7 +75,7 @@ const NumberSetting = () => {
...
@@ -75,7 +75,7 @@ const NumberSetting = () => {
);
);
const
onclickLogOut
=
useCallback
(()
=>
{
const
onclickLogOut
=
useCallback
(()
=>
{
clear
Token
();
clear
Cookie
();
setUserInfo
(
null
);
setUserInfo
(
null
);
router
.
replace
(
'/login'
);
router
.
replace
(
'/login'
);
},
[
router
,
setUserInfo
]);
},
[
router
,
setUserInfo
]);
...
...
src/pages/promotion/index.tsx
View file @
cdf4b9f3
...
@@ -81,7 +81,7 @@ const OpenApi = () => {
...
@@ -81,7 +81,7 @@ const OpenApi = () => {
mr=
{
4
}
mr=
{
4
}
variant=
{
'outline'
}
variant=
{
'outline'
}
onClick=
{
()
=>
{
onClick=
{
()
=>
{
copyData
(
`${location.origin}?inviterId=${userInfo?._id}`
,
'已复制邀请链接'
);
copyData
(
`${location.origin}
/
?inviterId=${userInfo?._id}`
,
'已复制邀请链接'
);
}
}
}
}
>
>
复制邀请链接
复制邀请链接
...
...
src/service/plugins/searchKb.ts
View file @
cdf4b9f3
...
@@ -105,11 +105,11 @@ export const searchKb = async ({
...
@@ -105,11 +105,11 @@ export const searchKb = async ({
:
[
:
[
{
{
obj
:
ChatRoleEnum
.
System
,
obj
:
ChatRoleEnum
.
System
,
value
:
`我们
来
玩问答游戏,规则为:
value
:
`我们
在
玩问答游戏,规则为:
1.你完全忘记你已有的知识
1.你完全忘记你已有的知识
2.你只能回答关于"
${
model
.
name
}
"的问题
2.你只能回答关于"
${
model
.
name
}
"的问题
3.你只能从知识库中选择内容进行回答
3.你只能从知识库中选择内容进行回答
4.如果问题不在知识库中,你
会回答"我不知道。"
4.如果问题不在知识库中,你
必须回答:我不知道。
务必遵守规则`
务必遵守规则`
}
}
])
])
...
@@ -161,7 +161,7 @@ export const searchKb = async ({
...
@@ -161,7 +161,7 @@ export const searchKb = async ({
searchPrompts
:
[
searchPrompts
:
[
{
{
obj
:
ChatRoleEnum
.
System
,
obj
:
ChatRoleEnum
.
System
,
value
:
`知识库:
'
${
filterSystemPrompt
}
'
`
value
:
`知识库:
${
filterSystemPrompt
}
`
},
},
...
fixedPrompts
...
fixedPrompts
]
]
...
...
src/service/utils/auth.ts
View file @
cdf4b9f3
...
@@ -55,11 +55,11 @@ export const getApiKey = async ({
...
@@ -55,11 +55,11 @@ export const getApiKey = async ({
},
},
[
OpenAiChatEnum
.
GPT4
]:
{
[
OpenAiChatEnum
.
GPT4
]:
{
userOpenAiKey
:
user
.
openaiKey
||
''
,
userOpenAiKey
:
user
.
openaiKey
||
''
,
systemAuthKey
:
process
.
env
.
OPENAI
KEY
as
string
systemAuthKey
:
process
.
env
.
GPT4
KEY
as
string
},
},
[
OpenAiChatEnum
.
GPT432k
]:
{
[
OpenAiChatEnum
.
GPT432k
]:
{
userOpenAiKey
:
user
.
openaiKey
||
''
,
userOpenAiKey
:
user
.
openaiKey
||
''
,
systemAuthKey
:
process
.
env
.
OPENAI
KEY
as
string
systemAuthKey
:
process
.
env
.
GPT4
KEY
as
string
},
},
[
ClaudeEnum
.
Claude
]:
{
[
ClaudeEnum
.
Claude
]:
{
userOpenAiKey
:
''
,
userOpenAiKey
:
''
,
...
...
src/service/utils/chat/claude.ts
View file @
cdf4b9f3
...
@@ -25,9 +25,9 @@ export const lafClaudChat = async ({
...
@@ -25,9 +25,9 @@ export const lafClaudChat = async ({
.
filter
((
item
)
=>
item
.
obj
===
'System'
)
.
filter
((
item
)
=>
item
.
obj
===
'System'
)
.
map
((
item
)
=>
item
.
value
)
.
map
((
item
)
=>
item
.
value
)
.
join
(
'\n'
);
.
join
(
'\n'
);
const
systemPromptText
=
systemPrompt
?
`
\n知识库内容:'
${
systemPrompt
}
'
\n`
:
''
;
const
systemPromptText
=
systemPrompt
?
`
你本次知识:
${
systemPrompt
}
\n`
:
''
;
const
prompt
=
`
${
systemPromptText
}
\n
我的问题是:'
${
messages
[
messages
.
length
-
1
].
value
}
'`
;
const
prompt
=
`
${
systemPromptText
}
我的问题是:'
${
messages
[
messages
.
length
-
1
].
value
}
'`
;
const
lafResponse
=
await
axios
.
post
(
const
lafResponse
=
await
axios
.
post
(
'https://hnvacz.laf.run/claude-gpt'
,
'https://hnvacz.laf.run/claude-gpt'
,
...
...
src/service/utils/chat/index.ts
View file @
cdf4b9f3
...
@@ -118,8 +118,8 @@ export const ChatContextFilter = ({
...
@@ -118,8 +118,8 @@ export const ChatContextFilter = ({
messages
:
chats
messages
:
chats
});
});
/* 整体 tokens 超出范围 */
/* 整体 tokens 超出范围
, system必须保留
*/
if
(
tokens
>=
maxTokens
)
{
if
(
tokens
>=
maxTokens
&&
formatPrompts
[
i
].
obj
!==
ChatRoleEnum
.
System
)
{
return
chats
.
slice
(
1
);
return
chats
.
slice
(
1
);
}
}
}
}
...
...
src/utils/user.ts
View file @
cdf4b9f3
import
{
PRICE_SCALE
}
from
'@/constants/common'
;
import
{
PRICE_SCALE
}
from
'@/constants/common'
;
const
tokenKey
=
'fast-gpt-token
'
;
import
{
loginOut
}
from
'@/api/user
'
;
export
const
clearToken
=
()
=>
{
export
const
clearCookie
=
()
=>
{
document
.
cookie
=
'token=; expires=Thu, 01 Jan 1970 00:00:00 UTC; path=/;'
;
try
{
loginOut
();
}
catch
(
error
)
{
error
;
}
};
};
/**
/**
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment