Skip to content

Commit bcf9491

Browse files
authored
v4.4.7-2 (#388)
1 parent d0041a9 commit bcf9491

File tree

51 files changed

+855
-463
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+855
-463
lines changed

docSite/assets/imgs/getfile_id.png

177 KB
Loading

docSite/content/docs/development/configuration.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,15 @@ weight: 520
7777
"price": 0,
7878
"prompt": ""
7979
},
80-
"CQModel": { // 问题分类模型
80+
"CQModel": { // Classify Question: 问题分类模型
8181
"model": "gpt-3.5-turbo-16k",
8282
"functionCall": true,
8383
"name": "GPT35-16k",
8484
"maxToken": 16000,
8585
"price": 0,
8686
"prompt": ""
8787
},
88-
"QGModel": { // 生成下一步指引模型
88+
"QGModel": { // Question Generation: 生成下一步指引模型
8989
"model": "gpt-3.5-turbo",
9090
"name": "GPT35-4k",
9191
"maxToken": 4000,

docSite/content/docs/development/openApi.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -225,9 +225,10 @@ data: [{"moduleName":"KB Search","price":1.2000000000000002,"model":"Embedding-2
225225
此部分 API 需使用全局通用的 API Key。
226226
{{% /alert %}}
227227

228-
### 如何获取知识库ID(kbId)
228+
| 如何获取知识库ID(kbId) | 如何获取文件ID(file_id) |
229+
| --------------------- | --------------------- |
230+
| ![](/imgs/getKbId.png) | ![](/imgs/getfile_id.png) |
229231

230-
![](/imgs/getKbId.png)
231232

232233
### 知识库添加数据
233234

@@ -248,6 +249,8 @@ curl --location --request POST 'https://fastgpt.run/api/core/dataset/data/pushDa
248249
        {
249250
            "a": "test",
250251
            "q": "1111",
252+
"file_id": "关联的文件ID/URL/manual/mark",
253+
"source": "来源名称",
251254
        },
252255
        {
253256
            "a": "test2",
@@ -271,7 +274,8 @@ curl --location --request POST 'https://fastgpt.run/api/core/dataset/data/pushDa
271274
"data": [
272275
{
273276
"q": "生成索引的内容,index 模式下最大 tokens 为3000,建议不超过 1000",
274-
"a": "预期回答/补充"
277+
"a": "预期回答/补充",
278+
"file_id": "如果推送数据到手动录入,这里可以留空; 如果希望关联到某个文件中,需要填写对应文件的ID; 如果希望加入到手动标注中,可设置为: mark",
275279
},
276280
{
277281
"q": "生成索引的内容,qa 模式下最大 tokens 为10000,建议 8000 左右",
@@ -292,7 +296,16 @@ curl --location --request POST 'https://fastgpt.run/api/core/dataset/data/pushDa
292296
"code": 200,
293297
"statusText": "",
294298
"data": {
295-
"insertLen": 1 // 最终插入成功的数量,可能因为超出 tokens 或者插入异常,index 可以重复插入,会自动去重
299+
"insertLen": 1, // 最终插入成功的数量
300+
"overToken": [], // 超出 token 的
301+
"fileIdInvalid": [ // file_id 无效的
302+
{
303+
"a": "飞飞dsaf飞",
304+
"q": "测试是32否收到",
305+
"file_id": "32dwe"
306+
}
307+
],
308+
"error": [] // 其他错误
296309
}
297310
}
298311
```

docSite/content/docs/installation/upgrading/447.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,6 @@ curl --location --request POST 'https://{{host}}/api/admin/initv447' \
2626
### Fast GPT V4.4.7
2727

2828
1. 优化了数据库文件 crud。
29-
2. 兼容链接读取,作为 source。
29+
2. 兼容链接读取,作为 source。
30+
3. 区分手动录入和标注,可追数据至某个文件。
31+
4. 升级 openai sdk。

packages/core/ai/config.ts

Lines changed: 8 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,16 @@
11
import { UserModelSchema } from '../user/type';
2-
import { Configuration, OpenAIApi } from 'openai';
2+
import OpenAI from 'openai';
33

44
export const openaiBaseUrl = process.env.OPENAI_BASE_URL || 'https://api.openai.com/v1';
55
export const baseUrl = process.env.ONEAPI_URL || openaiBaseUrl;
66

77
export const systemAIChatKey = process.env.CHAT_API_KEY || '';
88

9-
export const getAIChatApi = (props?: UserModelSchema['openaiAccount']) => {
10-
return new OpenAIApi(
11-
new Configuration({
12-
basePath: props?.baseUrl || baseUrl,
13-
apiKey: props?.key || systemAIChatKey
14-
})
15-
);
16-
};
17-
18-
/* openai axios config */
19-
export const axiosConfig = (props?: UserModelSchema['openaiAccount']) => {
20-
return {
21-
baseURL: props?.baseUrl || baseUrl, // 此处仅对非 npm 模块有效
22-
httpsAgent: global.httpsAgent,
23-
headers: {
24-
Authorization: `Bearer ${props?.key || systemAIChatKey}`,
25-
auth: process.env.OPENAI_BASE_URL_AUTH || ''
26-
}
27-
};
9+
export const getAIApi = (props?: UserModelSchema['openaiAccount'], timeout = 6000) => {
10+
return new OpenAI({
11+
apiKey: props?.key || systemAIChatKey,
12+
baseURL: props?.baseUrl || baseUrl,
13+
httpAgent: global.httpsAgent,
14+
timeout
15+
});
2816
};

packages/core/ai/constant.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
export { ChatCompletionRequestMessageRoleEnum } from 'openai';
1+
export enum ChatCompletionRequestMessageRoleEnum {
2+
'System' = 'system',
3+
'User' = 'user',
4+
'Assistant' = 'assistant',
5+
'Function' = 'function'
6+
}

packages/core/ai/functions/createQuestionGuide.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { ChatCompletionRequestMessage } from '../type';
2-
import { getAIChatApi } from '../config';
2+
import { getAIApi } from '../config';
33

44
export const Prompt_QuestionGuide = `我不太清楚问你什么问题,请帮我生成 3 个问题,引导我继续提问。问题的长度应小于20个字符,按 JSON 格式返回: ["问题1", "问题2", "问题3"]`;
55

@@ -10,8 +10,8 @@ export async function createQuestionGuide({
1010
messages: ChatCompletionRequestMessage[];
1111
model: string;
1212
}) {
13-
const chatAPI = getAIChatApi();
14-
const { data } = await chatAPI.createChatCompletion({
13+
const ai = getAIApi();
14+
const data = await ai.chat.completions.create({
1515
model: model,
1616
temperature: 0,
1717
max_tokens: 200,

packages/core/ai/type.d.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,6 @@
1-
export type { CreateChatCompletionRequest, ChatCompletionRequestMessage } from 'openai';
1+
import OpenAI from 'openai';
2+
export type ChatCompletionRequestMessage = OpenAI.Chat.CreateChatCompletionRequestMessage;
3+
export type ChatCompletion = OpenAI.Chat.ChatCompletion;
4+
export type CreateChatCompletionRequest = OpenAI.Chat.ChatCompletionCreateParams;
5+
6+
export type StreamChatType = Stream<OpenAI.Chat.ChatCompletionChunk>;

packages/core/package.json

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
"name": "@fastgpt/core",
33
"version": "1.0.0",
44
"dependencies": {
5-
"openai": "^3.3.0",
6-
"tunnel": "^0.0.6",
75
"@fastgpt/common": "workspace:*",
8-
"@fastgpt/support": "workspace:*"
6+
"@fastgpt/support": "workspace:*",
7+
"encoding": "^0.1.13",
8+
"openai": "^4.11.1",
9+
"tunnel": "^0.0.6"
910
},
1011
"devDependencies": {
1112
"@types/tunnel": "^0.0.4"

0 commit comments

Comments
 (0)