diff --git a/docSite/content/zh-cn/docs/development/openapi/chat.md b/docSite/content/zh-cn/docs/development/openapi/chat.md index a7acf8a91c29..9f61a97c1ae5 100644 --- a/docSite/content/zh-cn/docs/development/openapi/chat.md +++ b/docSite/content/zh-cn/docs/development/openapi/chat.md @@ -526,7 +526,8 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/getHistories --data-raw '{ "appId": "appId", "offset": 0, - "pageSize": 20 + "pageSize": 20, + "source: "api" }' ``` @@ -540,6 +541,7 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/getHistories - appId - 应用 Id - offset - 偏移量,即从第几条数据开始取 - pageSize - 记录数量 +- source - 对话源 {{% /alert %}} {{< /markdownify >}} diff --git a/projects/app/src/global/core/chat/api.d.ts b/projects/app/src/global/core/chat/api.d.ts index 9f016e9c5ef5..2d604c29972c 100644 --- a/projects/app/src/global/core/chat/api.d.ts +++ b/projects/app/src/global/core/chat/api.d.ts @@ -4,6 +4,7 @@ import type { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/ch import { AppTypeEnum } from '@fastgpt/global/core/app/constants'; import { RequestPaging } from '@/types'; import { GetChatTypeEnum } from '@/global/core/chat/constants'; +import { ChatSourceEnum } from '@fastgpt/global/core/chat/constants'; export type GetChatSpeechProps = { ttsConfig: AppTTSConfigType; input: string; @@ -56,6 +57,7 @@ export type InitChatResponse = { /* ---------- history ----------- */ export type GetHistoriesProps = OutLinkChatAuthProps & { appId?: string; + source?: `${ChatSourceEnum}`; }; export type UpdateHistoryProps = OutLinkChatAuthProps & { diff --git a/projects/app/src/pages/api/core/app/list.ts b/projects/app/src/pages/api/core/app/list.ts index f0cdca48ab19..8b80b0b280d1 100644 --- a/projects/app/src/pages/api/core/app/list.ts +++ b/projects/app/src/pages/api/core/app/list.ts @@ -39,6 +39,7 @@ async function handler(req: ApiRequestProps): Promise): Promise, res: ApiResponseType ): Promise> { - const { appId, shareId, outLinkUid, teamId, teamToken, offset, pageSize } = - req.body as getHistoriesBody; + const { + appId, + shareId, + outLinkUid, + teamId, + teamToken, + offset, + pageSize, + source = ChatSourceEnum.online + } = req.body as getHistoriesBody; const match = await (async () => { if (shareId && outLinkUid) { @@ -47,7 +55,7 @@ async function handler( return { tmbId, appId, - source: ChatSourceEnum.online + source: source }; } })(); diff --git a/projects/app/src/pages/api/v1/chat/completions.ts b/projects/app/src/pages/api/v1/chat/completions.ts index 2ab925271c6c..54efb006bc5a 100644 --- a/projects/app/src/pages/api/v1/chat/completions.ts +++ b/projects/app/src/pages/api/v1/chat/completions.ts @@ -536,12 +536,13 @@ const authHeaderRequest = async ({ const { app } = await (async () => { if (authType === AuthUserTypeEnum.apikey) { - if (!apiKeyAppId) { + const currentAppId = apiKeyAppId || appId; + if (!currentAppId) { return Promise.reject( 'Key is error. You need to use the app key rather than the account key.' ); } - const app = await MongoApp.findById(apiKeyAppId); + const app = await MongoApp.findById(currentAppId); if (!app) { return Promise.reject('app is empty');