Skip to content

Commit

Permalink
app list open-api & completion with appid & get history source (#3011)
Browse files Browse the repository at this point in the history
* app list open-api & completion with appid & get history source

* change default value position
  • Loading branch information
newfish-cmyk authored Oct 29, 2024
1 parent efc4e86 commit 9877128
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 6 deletions.
4 changes: 3 additions & 1 deletion docSite/content/zh-cn/docs/development/openapi/chat.md
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}'
```

Expand All @@ -540,6 +541,7 @@ curl --location --request POST 'http://localhost:3000/api/core/chat/getHistories
- appId - 应用 Id
- offset - 偏移量,即从第几条数据开始取
- pageSize - 记录数量
- source - 对话源
{{% /alert %}}

{{< /markdownify >}}
Expand Down
2 changes: 2 additions & 0 deletions projects/app/src/global/core/chat/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,6 +57,7 @@ export type InitChatResponse = {
/* ---------- history ----------- */
export type GetHistoriesProps = OutLinkChatAuthProps & {
appId?: string;
source?: `${ChatSourceEnum}`;
};

export type UpdateHistoryProps = OutLinkChatAuthProps & {
Expand Down
2 changes: 2 additions & 0 deletions projects/app/src/pages/api/core/app/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ async function handler(req: ApiRequestProps<ListAppBody>): Promise<AppListItemTy
return await authApp({
req,
authToken: true,
authApiKey: true,
appId: parentId,
per: ReadPermissionVal
});
Expand All @@ -47,6 +48,7 @@ async function handler(req: ApiRequestProps<ListAppBody>): Promise<AppListItemTy
...(await authUserPer({
req,
authToken: true,
authApiKey: true,
per: ReadPermissionVal
})),
app: undefined
Expand Down
14 changes: 11 additions & 3 deletions projects/app/src/pages/api/core/chat/getHistories.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,16 @@ async function handler(
req: ApiRequestProps<getHistoriesBody, getHistoriesQuery>,
res: ApiResponseType<any>
): Promise<PaginationResponse<getHistoriesResponse>> {
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) {
Expand Down Expand Up @@ -47,7 +55,7 @@ async function handler(
return {
tmbId,
appId,
source: ChatSourceEnum.online
source: source
};
}
})();
Expand Down
5 changes: 3 additions & 2 deletions projects/app/src/pages/api/v1/chat/completions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down

0 comments on commit 9877128

Please sign in to comment.