Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added docSite/assets/imgs/getfile_id.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docSite/content/docs/development/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,15 +77,15 @@ weight: 520
"price": 0,
"prompt": ""
},
"CQModel": { // 问题分类模型
"CQModel": { // Classify Question: 问题分类模型
"model": "gpt-3.5-turbo-16k",
"functionCall": true,
"name": "GPT35-16k",
"maxToken": 16000,
"price": 0,
"prompt": ""
},
"QGModel": { // 生成下一步指引模型
"QGModel": { // Question Generation: 生成下一步指引模型
"model": "gpt-3.5-turbo",
"name": "GPT35-4k",
"maxToken": 4000,
Expand Down
21 changes: 17 additions & 4 deletions docSite/content/docs/development/openApi.md
Original file line number Diff line number Diff line change
Expand Up @@ -225,9 +225,10 @@ data: [{"moduleName":"KB Search","price":1.2000000000000002,"model":"Embedding-2
此部分 API 需使用全局通用的 API Key。
{{% /alert %}}

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

![](/imgs/getKbId.png)

### 知识库添加数据

Expand All @@ -248,6 +249,8 @@ curl --location --request POST 'https://fastgpt.run/api/core/dataset/data/pushDa
        {
            "a": "test",
            "q": "1111",
"file_id": "关联的文件ID/URL/manual/mark",
"source": "来源名称",
        },
        {
            "a": "test2",
Expand All @@ -271,7 +274,8 @@ curl --location --request POST 'https://fastgpt.run/api/core/dataset/data/pushDa
"data": [
{
"q": "生成索引的内容,index 模式下最大 tokens 为3000,建议不超过 1000",
"a": "预期回答/补充"
"a": "预期回答/补充",
"file_id": "如果推送数据到手动录入,这里可以留空; 如果希望关联到某个文件中,需要填写对应文件的ID; 如果希望加入到手动标注中,可设置为: mark",
},
{
"q": "生成索引的内容,qa 模式下最大 tokens 为10000,建议 8000 左右",
Expand All @@ -292,7 +296,16 @@ curl --location --request POST 'https://fastgpt.run/api/core/dataset/data/pushDa
"code": 200,
"statusText": "",
"data": {
"insertLen": 1 // 最终插入成功的数量,可能因为超出 tokens 或者插入异常,index 可以重复插入,会自动去重
"insertLen": 1, // 最终插入成功的数量
"overToken": [], // 超出 token 的
"fileIdInvalid": [ // file_id 无效的
{
"a": "飞飞dsaf飞",
"q": "测试是32否收到",
"file_id": "32dwe"
}
],
"error": [] // 其他错误
}
}
```
Expand Down
4 changes: 3 additions & 1 deletion docSite/content/docs/installation/upgrading/447.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,6 @@ curl --location --request POST 'https://{{host}}/api/admin/initv447' \
### Fast GPT V4.4.7

1. 优化了数据库文件 crud。
2. 兼容链接读取,作为 source。
2. 兼容链接读取,作为 source。
3. 区分手动录入和标注,可追数据至某个文件。
4. 升级 openai sdk。
28 changes: 8 additions & 20 deletions packages/core/ai/config.ts
Original file line number Diff line number Diff line change
@@ -1,28 +1,16 @@
import { UserModelSchema } from '../user/type';
import { Configuration, OpenAIApi } from 'openai';
import OpenAI from 'openai';

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

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

export const getAIChatApi = (props?: UserModelSchema['openaiAccount']) => {
return new OpenAIApi(
new Configuration({
basePath: props?.baseUrl || baseUrl,
apiKey: props?.key || systemAIChatKey
})
);
};

/* openai axios config */
export const axiosConfig = (props?: UserModelSchema['openaiAccount']) => {
return {
baseURL: props?.baseUrl || baseUrl, // 此处仅对非 npm 模块有效
httpsAgent: global.httpsAgent,
headers: {
Authorization: `Bearer ${props?.key || systemAIChatKey}`,
auth: process.env.OPENAI_BASE_URL_AUTH || ''
}
};
export const getAIApi = (props?: UserModelSchema['openaiAccount'], timeout = 6000) => {
return new OpenAI({
apiKey: props?.key || systemAIChatKey,
baseURL: props?.baseUrl || baseUrl,
httpAgent: global.httpsAgent,
timeout
});
};
7 changes: 6 additions & 1 deletion packages/core/ai/constant.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export { ChatCompletionRequestMessageRoleEnum } from 'openai';
export enum ChatCompletionRequestMessageRoleEnum {
'System' = 'system',
'User' = 'user',
'Assistant' = 'assistant',
'Function' = 'function'
}
6 changes: 3 additions & 3 deletions packages/core/ai/functions/createQuestionGuide.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChatCompletionRequestMessage } from '../type';
import { getAIChatApi } from '../config';
import { getAIApi } from '../config';

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

Expand All @@ -10,8 +10,8 @@ export async function createQuestionGuide({
messages: ChatCompletionRequestMessage[];
model: string;
}) {
const chatAPI = getAIChatApi();
const { data } = await chatAPI.createChatCompletion({
const ai = getAIApi();
const data = await ai.chat.completions.create({
model: model,
temperature: 0,
max_tokens: 200,
Expand Down
7 changes: 6 additions & 1 deletion packages/core/ai/type.d.ts
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
export type { CreateChatCompletionRequest, ChatCompletionRequestMessage } from 'openai';
import OpenAI from 'openai';
export type ChatCompletionRequestMessage = OpenAI.Chat.CreateChatCompletionRequestMessage;
export type ChatCompletion = OpenAI.Chat.ChatCompletion;
export type CreateChatCompletionRequest = OpenAI.Chat.ChatCompletionCreateParams;

export type StreamChatType = Stream<OpenAI.Chat.ChatCompletionChunk>;
7 changes: 4 additions & 3 deletions packages/core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
"name": "@fastgpt/core",
"version": "1.0.0",
"dependencies": {
"openai": "^3.3.0",
"tunnel": "^0.0.6",
"@fastgpt/common": "workspace:*",
"@fastgpt/support": "workspace:*"
"@fastgpt/support": "workspace:*",
"encoding": "^0.1.13",
"openai": "^4.11.1",
"tunnel": "^0.0.6"
},
"devDependencies": {
"@types/tunnel": "^0.0.4"
Expand Down
Loading