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
dab70378
authored
Jun 14, 2023
by
archer
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
feat: gpt35-16k
parent
0a0febd2
Hide whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
30 additions
and
26 deletions
+30
-26
client/src/constants/model.ts
+3
-3
client/src/pages/api/openapi/kb/pushData.ts
+2
-1
client/src/pages/api/openapi/plugin/openaiEmbedding.ts
+2
-1
client/src/pages/api/openapi/text/gptMessagesSlice.ts
+2
-1
client/src/pages/kb/components/SelectFileModal.tsx
+4
-4
client/src/service/events/generateQA.ts
+1
-1
client/src/service/utils/auth.ts
+1
-1
client/src/store/chat.ts
+1
-1
client/src/utils/file.ts
+2
-1
client/src/utils/plugin/openai.ts
+12
-12
No files found.
client/src/constants/model.ts
View file @
dab70378
...
...
@@ -7,7 +7,7 @@ export const embeddingPrice = 0.1;
export
type
EmbeddingModelType
=
'text-embedding-ada-002'
;
export
enum
OpenAiChatEnum
{
'GPT35'
=
'gpt-3.5-turbo'
,
'GPT35'
=
'gpt-3.5-turbo
-16k
'
,
'GPT4'
=
'gpt-4'
,
'GPT432k'
=
'gpt-4-32k'
}
...
...
@@ -30,8 +30,8 @@ export const ChatModelMap = {
[
OpenAiChatEnum
.
GPT35
]:
{
chatModel
:
OpenAiChatEnum
.
GPT35
,
name
:
'ChatGpt'
,
contextMaxToken
:
4096
,
systemMaxToken
:
27
00
,
contextMaxToken
:
16000
,
systemMaxToken
:
80
00
,
maxTemperature
:
1.2
,
price
:
2.5
},
...
...
client/src/pages/api/openapi/kb/pushData.ts
View file @
dab70378
...
...
@@ -8,6 +8,7 @@ import { TrainingModeEnum } from '@/constants/plugin';
import
{
startQueue
}
from
'@/service/utils/tools'
;
import
{
PgClient
}
from
'@/service/pg'
;
import
{
modelToolMap
}
from
'@/utils/plugin'
;
import
{
OpenAiChatEnum
}
from
'@/constants/model'
;
type
DateItemType
=
{
a
:
string
;
q
:
string
;
source
?:
string
};
...
...
@@ -76,7 +77,7 @@ export async function pushDataToKb({
const
text
=
item
.
q
+
item
.
a
;
// count token
const
token
=
modelToolMap
[
'gpt-3.5-turbo'
].
countTokens
({
const
token
=
modelToolMap
[
OpenAiChatEnum
.
GPT35
].
countTokens
({
messages
:
[{
obj
:
'System'
,
value
:
item
.
q
}]
});
...
...
client/src/pages/api/openapi/plugin/openaiEmbedding.ts
View file @
dab70378
...
...
@@ -7,6 +7,7 @@ import { embeddingModel } from '@/constants/model';
import
{
axiosConfig
}
from
'@/service/utils/tools'
;
import
{
pushGenerateVectorBill
}
from
'@/service/events/pushBill'
;
import
{
ApiKeyType
}
from
'@/service/utils/auth'
;
import
{
OpenAiChatEnum
}
from
'@/constants/model'
;
type
Props
=
{
input
:
string
[];
...
...
@@ -42,7 +43,7 @@ export async function openaiEmbedding({
type
=
'chat'
}:
{
userId
:
string
;
mustPay
?:
boolean
}
&
Props
)
{
const
{
userOpenAiKey
,
systemAuthKey
}
=
await
getApiKey
({
model
:
'gpt-3.5-turbo'
,
model
:
OpenAiChatEnum
.
GPT35
,
userId
,
mustPay
,
type
...
...
client/src/pages/api/openapi/text/gptMessagesSlice.ts
View file @
dab70378
...
...
@@ -4,8 +4,9 @@ import { jsonRes } from '@/service/response';
import
{
authUser
}
from
'@/service/utils/auth'
;
import
type
{
ChatItemSimpleType
}
from
'@/types/chat'
;
import
{
countOpenAIToken
}
from
'@/utils/plugin/openai'
;
import
{
OpenAiChatEnum
}
from
'@/constants/model'
;
type
ModelType
=
'gpt-3.5-turbo'
|
'gpt-4'
|
'gpt-4-32k'
;
type
ModelType
=
`
${
OpenAiChatEnum
}
`
;
type
Props
=
{
messages
:
ChatItemSimpleType
[];
...
...
client/src/pages/kb/components/SelectFileModal.tsx
View file @
dab70378
...
...
@@ -29,14 +29,14 @@ const fileExtension = '.txt,.doc,.docx,.pdf,.md';
const
modeMap
=
{
[
TrainingModeEnum
.
qa
]:
{
maxLen
:
26
00
,
slideLen
:
7
00
,
maxLen
:
90
00
,
slideLen
:
30
00
,
price
:
ChatModelMap
[
OpenAiChatEnum
.
GPT35
].
price
,
isPrompt
:
true
},
[
TrainingModeEnum
.
index
]:
{
maxLen
:
7
00
,
slideLen
:
3
00
,
maxLen
:
20
00
,
slideLen
:
6
00
,
price
:
embeddingPrice
,
isPrompt
:
false
}
...
...
client/src/service/events/generateQA.ts
View file @
dab70378
...
...
@@ -96,7 +96,7 @@ export async function generateQA(): Promise<any> {
obj
:
ChatRoleEnum
.
System
,
value
:
`你是出题人
${
data
.
prompt
||
'下面是"一段长文本"'
}
从中选出
5至2
0个题目和答案.答案详细.按格式返回: Q1:
从中选出
15至3
0个题目和答案.答案详细.按格式返回: Q1:
A1:
Q2:
A2:
...
...
client/src/service/utils/auth.ts
View file @
dab70378
...
...
@@ -177,7 +177,7 @@ export const getApiKey = async ({
};
// 有自己的key
if
(
!
mustPay
&&
keyMap
[
model
].
userOpenAiKey
)
{
if
(
!
mustPay
&&
keyMap
[
model
]
?
.
userOpenAiKey
)
{
return
{
user
,
userOpenAiKey
:
keyMap
[
model
].
userOpenAiKey
,
...
...
client/src/store/chat.ts
View file @
dab70378
...
...
@@ -64,7 +64,7 @@ const defaultShareChatData: ShareChatType = {
avatar
:
'/icon/logo.png'
,
intro
:
''
},
chatModel
:
'gpt-3.5-turbo'
,
chatModel
:
OpenAiChatEnum
.
GPT35
,
history
:
[]
};
...
...
client/src/utils/file.ts
View file @
dab70378
...
...
@@ -2,6 +2,7 @@ import mammoth from 'mammoth';
import
Papa
from
'papaparse'
;
import
{
getOpenAiEncMap
}
from
'./plugin/openai'
;
import
{
getErrText
}
from
'./tools'
;
import
{
OpenAiChatEnum
}
from
'@/constants/model'
;
/**
* 读取 txt 文件内容
...
...
@@ -156,7 +157,7 @@ export const splitText_token = ({
slideLen
:
number
;
})
=>
{
try
{
const
enc
=
getOpenAiEncMap
()[
'gpt-3.5-turbo'
];
const
enc
=
getOpenAiEncMap
()[
OpenAiChatEnum
.
GPT35
];
// filter empty text. encode sentence
const
encodeText
=
enc
.
encode
(
text
);
...
...
client/src/utils/plugin/openai.ts
View file @
dab70378
...
...
@@ -11,17 +11,17 @@ const graphemer = new Graphemer();
export
const
getOpenAiEncMap
=
()
=>
{
if
(
typeof
window
!==
'undefined'
)
{
window
.
OpenAiEncMap
=
window
.
OpenAiEncMap
||
{
'gpt-3.5-turbo'
:
encoding_for_model
(
'gpt-3.5-turbo'
,
{
[
OpenAiChatEnum
.
GPT35
]
:
encoding_for_model
(
'gpt-3.5-turbo'
,
{
'<|im_start|>'
:
100264
,
'<|im_end|>'
:
100265
,
'<|im_sep|>'
:
100266
}),
'gpt-4'
:
encoding_for_model
(
'gpt-4'
,
{
[
OpenAiChatEnum
.
GPT4
]
:
encoding_for_model
(
'gpt-4'
,
{
'<|im_start|>'
:
100264
,
'<|im_end|>'
:
100265
,
'<|im_sep|>'
:
100266
}),
'gpt-4-32k'
:
encoding_for_model
(
'gpt-4-32k'
,
{
[
OpenAiChatEnum
.
GPT432k
]
:
encoding_for_model
(
'gpt-4-32k'
,
{
'<|im_start|>'
:
100264
,
'<|im_end|>'
:
100265
,
'<|im_sep|>'
:
100266
...
...
@@ -31,17 +31,17 @@ export const getOpenAiEncMap = () => {
}
if
(
typeof
global
!==
'undefined'
)
{
global
.
OpenAiEncMap
=
global
.
OpenAiEncMap
||
{
'gpt-3.5-turbo'
:
encoding_for_model
(
'gpt-3.5-turbo'
,
{
[
OpenAiChatEnum
.
GPT35
]
:
encoding_for_model
(
'gpt-3.5-turbo'
,
{
'<|im_start|>'
:
100264
,
'<|im_end|>'
:
100265
,
'<|im_sep|>'
:
100266
}),
'gpt-4'
:
encoding_for_model
(
'gpt-4'
,
{
[
OpenAiChatEnum
.
GPT4
]
:
encoding_for_model
(
'gpt-4'
,
{
'<|im_start|>'
:
100264
,
'<|im_end|>'
:
100265
,
'<|im_sep|>'
:
100266
}),
'gpt-4-32k'
:
encoding_for_model
(
'gpt-4-32k'
,
{
[
OpenAiChatEnum
.
GPT432k
]
:
encoding_for_model
(
'gpt-4-32k'
,
{
'<|im_start|>'
:
100264
,
'<|im_end|>'
:
100265
,
'<|im_sep|>'
:
100266
...
...
@@ -50,17 +50,17 @@ export const getOpenAiEncMap = () => {
return
global
.
OpenAiEncMap
;
}
return
{
'gpt-3.5-turbo'
:
encoding_for_model
(
'gpt-3.5-turbo'
,
{
[
OpenAiChatEnum
.
GPT35
]
:
encoding_for_model
(
'gpt-3.5-turbo'
,
{
'<|im_start|>'
:
100264
,
'<|im_end|>'
:
100265
,
'<|im_sep|>'
:
100266
}),
'gpt-4'
:
encoding_for_model
(
'gpt-4'
,
{
[
OpenAiChatEnum
.
GPT4
]
:
encoding_for_model
(
'gpt-4'
,
{
'<|im_start|>'
:
100264
,
'<|im_end|>'
:
100265
,
'<|im_sep|>'
:
100266
}),
'gpt-4-32k'
:
encoding_for_model
(
'gpt-4-32k'
,
{
[
OpenAiChatEnum
.
GPT432k
]
:
encoding_for_model
(
'gpt-4-32k'
,
{
'<|im_start|>'
:
100264
,
'<|im_end|>'
:
100265
,
'<|im_sep|>'
:
100266
...
...
@@ -97,9 +97,9 @@ export function countOpenAIToken({
content
:
string
;
name
?:
string
;
}[],
model
:
'gpt-3.5-turbo'
|
'gpt-4'
|
'gpt-4-32k'
model
:
`
${
OpenAiChatEnum
}
`
)
{
const
isGpt3
=
model
===
'gpt-3.5-turbo'
;
const
isGpt3
=
model
.
startsWith
(
'gpt-3.5-turbo'
)
;
const
msgSep
=
isGpt3
?
'\n'
:
''
;
const
roleSep
=
isGpt3
?
'\n'
:
'<|im_sep|>'
;
...
...
@@ -147,7 +147,7 @@ export function countOpenAIToken({
}
export
const
openAiSliceTextByToken
=
({
model
=
'gpt-3.5-turbo'
,
model
=
OpenAiChatEnum
.
GPT35
,
text
,
length
}:
{
...
...
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