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
ff2043c0
authored
Jun 18, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: maxToken setting
parent
ee9afa31
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
54 additions
and
6 deletions
+54
-6
client/src/constants/model.ts
+1
-0
client/src/pages/api/openapi/v1/chat/completions.ts
+1
-0
client/src/pages/model/components/detail/components/Settings.tsx
+35
-5
client/src/service/models/model.ts
+5
-0
client/src/service/utils/chat/index.ts
+1
-0
client/src/service/utils/chat/openai.ts
+10
-1
client/src/types/mongoSchema.d.ts
+1
-0
No files found.
client/src/constants/model.ts
View file @
ff2043c0
...
@@ -83,6 +83,7 @@ export const defaultModel: ModelSchema = {
...
@@ -83,6 +83,7 @@ export const defaultModel: ModelSchema = {
searchEmptyText
:
''
,
searchEmptyText
:
''
,
systemPrompt
:
''
,
systemPrompt
:
''
,
temperature
:
0
,
temperature
:
0
,
maxToken
:
4000
,
chatModel
:
OpenAiChatEnum
.
GPT35
chatModel
:
OpenAiChatEnum
.
GPT35
},
},
share
:
{
share
:
{
...
...
client/src/pages/api/openapi/v1/chat/completions.ts
View file @
ff2043c0
...
@@ -180,6 +180,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
...
@@ -180,6 +180,7 @@ export default withNextCors(async function handler(req: NextApiRequest, res: Nex
await
modelServiceToolMap
[
model
.
chat
.
chatModel
].
chatCompletion
({
await
modelServiceToolMap
[
model
.
chat
.
chatModel
].
chatCompletion
({
apiKey
:
userOpenAiKey
||
apiKey
,
apiKey
:
userOpenAiKey
||
apiKey
,
temperature
:
+
temperature
,
temperature
:
+
temperature
,
maxToken
:
model
.
chat
.
maxToken
,
messages
:
completePrompts
,
messages
:
completePrompts
,
stream
,
stream
,
res
res
...
...
client/src/pages/model/components/detail/components/Settings.tsx
View file @
ff2043c0
...
@@ -36,11 +36,6 @@ const Settings = ({ modelId }: { modelId: string }) => {
...
@@ -36,11 +36,6 @@ const Settings = ({ modelId }: { modelId: string }) => {
const
[
btnLoading
,
setBtnLoading
]
=
useState
(
false
);
const
[
btnLoading
,
setBtnLoading
]
=
useState
(
false
);
const
[
refresh
,
setRefresh
]
=
useState
(
false
);
const
[
refresh
,
setRefresh
]
=
useState
(
false
);
const
isOwner
=
useMemo
(
()
=>
modelDetail
.
userId
===
userInfo
?.
_id
,
[
modelDetail
.
userId
,
userInfo
?.
_id
]
);
const
{
const
{
register
,
register
,
setValue
,
setValue
,
...
@@ -52,6 +47,20 @@ const Settings = ({ modelId }: { modelId: string }) => {
...
@@ -52,6 +47,20 @@ const Settings = ({ modelId }: { modelId: string }) => {
defaultValues
:
modelDetail
defaultValues
:
modelDetail
});
});
const
isOwner
=
useMemo
(
()
=>
modelDetail
.
userId
===
userInfo
?.
_id
,
[
modelDetail
.
userId
,
userInfo
?.
_id
]
);
const
tokenLimit
=
useMemo
(()
=>
{
const
max
=
ChatModelMap
[
getValues
(
'chat.chatModel'
)]?.
contextMaxToken
||
4000
;
if
(
max
<
getValues
(
'chat.maxToken'
))
{
setValue
(
'chat.maxToken'
,
max
);
}
return
max
;
},
[
getValues
,
setValue
,
refresh
]);
// 提交保存模型修改
// 提交保存模型修改
const
saveSubmitSuccess
=
useCallback
(
const
saveSubmitSuccess
=
useCallback
(
async
(
data
:
ModelSchema
)
=>
{
async
(
data
:
ModelSchema
)
=>
{
...
@@ -256,6 +265,27 @@ const Settings = ({ modelId }: { modelId: string }) => {
...
@@ -256,6 +265,27 @@ const Settings = ({ modelId }: { modelId: string }) => {
/>
/>
</
Box
>
</
Box
>
</
Flex
>
</
Flex
>
<
Flex
alignItems=
{
'center'
}
mt=
{
12
}
mb=
{
10
}
>
<
Box
w=
{
[
'60px'
,
'100px'
,
'140px'
]
}
flexShrink=
{
0
}
>
最大长度
</
Box
>
<
Box
flex=
{
1
}
ml=
{
'10px'
}
>
<
MySlider
markList=
{
[
{
label
:
'100'
,
value
:
100
},
{
label
:
`${tokenLimit}`
,
value
:
tokenLimit
}
]
}
width=
{
[
'100%'
,
'260px'
]
}
min=
{
100
}
max=
{
tokenLimit
}
activeVal=
{
getValues
(
'chat.maxToken'
)
}
setVal=
{
(
val
)
=>
{
setValue
(
'chat.maxToken'
,
val
);
setRefresh
(
!
refresh
);
}
}
/>
</
Box
>
</
Flex
>
<
Flex
mt=
{
10
}
alignItems=
{
'flex-start'
}
>
<
Flex
mt=
{
10
}
alignItems=
{
'flex-start'
}
>
<
Box
w=
{
[
'60px'
,
'100px'
,
'140px'
]
}
flexShrink=
{
0
}
>
<
Box
w=
{
[
'60px'
,
'100px'
,
'140px'
]
}
flexShrink=
{
0
}
>
提示词
提示词
...
...
client/src/service/models/model.ts
View file @
ff2043c0
...
@@ -47,6 +47,11 @@ const ModelSchema = new Schema({
...
@@ -47,6 +47,11 @@ const ModelSchema = new Schema({
type
:
String
,
type
:
String
,
default
:
''
default
:
''
},
},
maxToken
:
{
type
:
Number
,
default
:
4000
,
min
:
100
},
temperature
:
{
temperature
:
{
type
:
Number
,
type
:
Number
,
min
:
0
,
min
:
0
,
...
...
client/src/service/utils/chat/index.ts
View file @
ff2043c0
...
@@ -12,6 +12,7 @@ import { textAdaptGptResponse } from '@/utils/adapt';
...
@@ -12,6 +12,7 @@ import { textAdaptGptResponse } from '@/utils/adapt';
export
type
ChatCompletionType
=
{
export
type
ChatCompletionType
=
{
apiKey
:
string
;
apiKey
:
string
;
temperature
:
number
;
temperature
:
number
;
maxToken
?:
number
;
messages
:
ChatItemType
[];
messages
:
ChatItemType
[];
chatId
?:
string
;
chatId
?:
string
;
[
key
:
string
]:
any
;
[
key
:
string
]:
any
;
...
...
client/src/service/utils/chat/openai.ts
View file @
ff2043c0
...
@@ -19,22 +19,31 @@ export const chatResponse = async ({
...
@@ -19,22 +19,31 @@ export const chatResponse = async ({
model
,
model
,
apiKey
,
apiKey
,
temperature
,
temperature
,
maxToken
=
4000
,
messages
,
messages
,
stream
stream
}:
ChatCompletionType
&
{
model
:
`
${
OpenAiChatEnum
}
`
})
=>
{
}:
ChatCompletionType
&
{
model
:
`
${
OpenAiChatEnum
}
`
})
=>
{
const
modelTokenLimit
=
ChatModelMap
[
model
]?.
contextMaxToken
||
4000
;
const
filterMessages
=
ChatContextFilter
({
const
filterMessages
=
ChatContextFilter
({
model
,
model
,
prompts
:
messages
,
prompts
:
messages
,
maxTokens
:
Math
.
ceil
(
ChatModelMap
[
model
].
contextMaxToken
*
0.85
)
maxTokens
:
Math
.
ceil
(
modelTokenLimit
-
300
)
// filter token. not response maxToken
});
});
const
adaptMessages
=
adaptChatItem_openAI
({
messages
:
filterMessages
,
reserveId
:
false
});
const
adaptMessages
=
adaptChatItem_openAI
({
messages
:
filterMessages
,
reserveId
:
false
});
const
chatAPI
=
getOpenAIApi
();
const
chatAPI
=
getOpenAIApi
();
const
promptsToken
=
modelToolMap
[
model
].
countTokens
({
messages
:
filterMessages
});
maxToken
=
maxToken
+
promptsToken
>
modelTokenLimit
?
modelTokenLimit
-
promptsToken
:
maxToken
;
const
response
=
await
chatAPI
.
createChatCompletion
(
const
response
=
await
chatAPI
.
createChatCompletion
(
{
{
model
,
model
,
temperature
:
Number
(
temperature
||
0
),
temperature
:
Number
(
temperature
||
0
),
max_tokens
:
maxToken
,
messages
:
adaptMessages
,
messages
:
adaptMessages
,
frequency_penalty
:
0.5
,
// 越大,重复内容越少
frequency_penalty
:
0.5
,
// 越大,重复内容越少
presence_penalty
:
-
0.5
,
// 越大,越容易出现新内容
presence_penalty
:
-
0.5
,
// 越大,越容易出现新内容
...
...
client/src/types/mongoSchema.d.ts
View file @
ff2043c0
...
@@ -44,6 +44,7 @@ export interface ModelSchema {
...
@@ -44,6 +44,7 @@ export interface ModelSchema {
searchEmptyText
:
string
;
searchEmptyText
:
string
;
systemPrompt
:
string
;
systemPrompt
:
string
;
temperature
:
number
;
temperature
:
number
;
maxToken
:
number
;
chatModel
:
ChatModelType
;
// 聊天时用的模型,训练后就是训练的模型
chatModel
:
ChatModelType
;
// 聊天时用的模型,训练后就是训练的模型
};
};
share
:
{
share
:
{
...
...
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