Skip to content

Commit

Permalink
feat: function call prompt version (#331)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Sep 21, 2023
1 parent 7e0deb2 commit e367265
Show file tree
Hide file tree
Showing 12 changed files with 363 additions and 119 deletions.
16 changes: 16 additions & 0 deletions client/data/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,5 +62,21 @@
"name": "GPT35-16k",
"maxToken": 16000,
"price": 0
},
"ExtractModel": {
"model": "gpt-3.5-turbo-16k",
"functionCall": false,
"name": "GPT35-16k",
"maxToken": 16000,
"price": 0,
"prompt": ""
},
"CQModel": {
"model": "gpt-3.5-turbo-16k",
"functionCall": false,
"name": "GPT35-16k",
"maxToken": 16000,
"price": 0,
"prompt": ""
}
}
2 changes: 1 addition & 1 deletion client/public/docs/versionIntro.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
### Fast GPT V4.4.3
### Fast GPT V4.4.4

1. 去除 - 限定词。目前旧应用仍生效,9/25 后全面去除,请及时替换。
2. 新增 - 引用模板/引用提示词设置,可以 DIY 引用内容的格式,从而更好的适配场景。
Expand Down
5 changes: 3 additions & 2 deletions client/src/components/ChatBox/ResponseTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ const ResponseTags = ({

return responseData.length === 0 ? null : (
<Flex alignItems={'center'} mt={2} flexWrap={'wrap'}>
{chatAccount === 1 ? (
{chatAccount === 1 && (
<>
{quoteList.length > 0 && (
<MyTooltip label="查看引用">
Expand All @@ -83,7 +83,8 @@ const ResponseTags = ({
</MyTooltip>
)}
</>
) : (
)}
{chatAccount > 1 && (
<Tag colorSchema="blue" {...TagStyles}>
多组 AI 对话
</Tag>
Expand Down
21 changes: 20 additions & 1 deletion client/src/pages/api/system/getInitData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { readFileSync } from 'fs';
import {
type QAModelItemType,
type ChatModelItemType,
type VectorModelItemType
type VectorModelItemType,
FunctionModelItemType
} from '@/types/model';

export type InitDateResponse = {
Expand Down Expand Up @@ -83,6 +84,22 @@ const defaultQAModel = {
maxToken: 16000,
price: 0
};
const defaultExtractModel: FunctionModelItemType = {
model: 'gpt-3.5-turbo-16k',
name: 'GPT35-16k',
maxToken: 16000,
price: 0,
prompt: '',
functionCall: true
};
const defaultCQModel: FunctionModelItemType = {
model: 'gpt-3.5-turbo-16k',
name: 'GPT35-16k',
maxToken: 16000,
price: 0,
prompt: '',
functionCall: true
};

const defaultVectorModels: VectorModelItemType[] = [
{
Expand Down Expand Up @@ -114,6 +131,8 @@ export async function getInitConfig() {
global.feConfigs = res.FeConfig ? { ...defaultFeConfigs, ...res.FeConfig } : defaultFeConfigs;
global.chatModels = res.ChatModels || defaultChatModels;
global.qaModel = res.QAModel || defaultQAModel;
global.extractModel = res.ExtractModel || defaultExtractModel;
global.cqModel = res.CQModel || defaultCQModel;
global.vectorModels = res.VectorModels || defaultVectorModels;
} catch (error) {
setDefaultData();
Expand Down
42 changes: 42 additions & 0 deletions client/src/prompts/core/agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,3 +14,45 @@ A2:
我的文本:"""{{text}}"""`,
defaultTheme: '它们可能包含多个主题内容'
};

export const Prompt_ExtractJson = `你可以从 "对话记录" 中提取指定信息,并返回一个 JSON 对象,JSON 对象要求:
1. JSON 对象仅包含字段说明中的值。
2. 字段说明中的 required 决定 JSON 对象是否必须存在该字段。
3. 必须存在的字段,值可以为空字符串或根据提取要求来设置,不能随机生成值。
提取要求:
"""
{{description}}
"""
字段说明:
"""
{{json}}
"""
对话记录:
"""
{{text}}
"""
`;

export const Prompt_CQJson = `我会给你几个问题类型,请参考额外的背景知识(可能为空)和对话内容,判断我本次的问题类型,并返回对应类型的 ID,格式为 JSON 字符串:
"""
'{"type":"问题类型的 ID"}'
"""
问题类型:
"""
{{typeList}}
"""
额外背景知识:
"""
{{systemPrompt}}
"""
对话内容:
"""
{{text}}
"""
`;
68 changes: 36 additions & 32 deletions client/src/service/events/pushBill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,40 +20,44 @@ export const pushTaskBill = async ({
shareId?: string;
response: ChatHistoryItemResType[];
}) => {
const total = response.reduce((sum, item) => sum + item.price, 0);
try {
const total = response.reduce((sum, item) => sum + item.price, 0);

await Promise.allSettled([
Bill.create({
userId,
appName,
appId,
total,
await Promise.allSettled([
Bill.create({
userId,
appName,
appId,
total,
source,
list: response.map((item) => ({
moduleName: item.moduleName,
amount: item.price || 0,
model: item.model,
tokenLen: item.tokens
}))
}),
User.findByIdAndUpdate(userId, {
$inc: { balance: -total }
}),
...(shareId
? [
updateShareChatBill({
shareId,
total
})
]
: [])
]);

addLog.info(`finish completions`, {
source,
list: response.map((item) => ({
moduleType: item.moduleType,
amount: item.price || 0,
model: item.model,
tokenLen: item.tokens
}))
}),
User.findByIdAndUpdate(userId, {
$inc: { balance: -total }
}),
...(shareId
? [
updateShareChatBill({
shareId,
total
})
]
: [])
]);

addLog.info(`finish completions`, {
source,
userId,
price: formatPrice(total)
});
userId,
price: formatPrice(total)
});
} catch (error) {
addLog.error(`pushTaskBill error`, error);
}
};

export const updateShareChatBill = async ({
Expand Down
19 changes: 1 addition & 18 deletions client/src/service/models/bill.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,24 +31,7 @@ const BillSchema = new Schema({
default: BillSourceEnum.fastgpt
},
list: {
type: [
{
moduleName: {
type: String,
required: true
},
amount: {
type: Number,
required: true
},
model: {
type: String
},
tokenLen: {
type: Number
}
}
],
type: Array,
default: []
}
});
Expand Down
Loading

0 comments on commit e367265

Please sign in to comment.