Commit d55ccc9f by Archer Committed by GitHub

Doc (#2910)

* feat: add app chat openapi (#2908)

* add chat openapi

* create question guide openapi

* change auth method

* add chat openapi doc

* delete unused code

* feat: chat openapi doc

* rerank doc

* add chat detail openapi & doc

* update chat openapi doc

---------

Co-authored-by: heheer <heheer@sealos.io>
Co-authored-by: heheer <1239331448@qq.com>
parent 27ef4dc8
...@@ -77,7 +77,7 @@ https://github.com/labring/FastGPT/assets/15308462/7d3a38df-eb0e-4388-9250-2409b ...@@ -77,7 +77,7 @@ https://github.com/labring/FastGPT/assets/15308462/7d3a38df-eb0e-4388-9250-2409b
`4` OpenAPI 接口 `4` OpenAPI 接口
- [x] completions 接口 (chat 模式对齐 GPT 接口) - [x] completions 接口 (chat 模式对齐 GPT 接口)
- [x] 知识库 CRUD - [x] 知识库 CRUD
- [ ] 对话 CRUD - [x] 对话 CRUD
`5` 运营能力 `5` 运营能力
- [x] 免登录分享窗口 - [x] 免登录分享窗口
......
...@@ -227,6 +227,27 @@ weight: 708 ...@@ -227,6 +227,27 @@ weight: 708
} }
``` ```
### ReRank 接入(硅基流动)
有免费的 `bge-reranker-v2-m3` 模型可以使用。
1. 注册硅基流动账号: https://siliconflow.cn/
2. 进入控制台,获取 API key: https://cloud.siliconflow.cn/account/ak
3. 修改 FastGPT 配置文件
```json
{
"reRankModels": [
{
"model": "BAAI/bge-reranker-v2-m3", // 这里的model需要对应 siliconflow 的模型名
"name": "BAAI/bge-reranker-v2-m3",
"requestUrl": "https://api.siliconflow.cn/v1/rerank",
"requestAuth": "siliconflow 上申请的 key"
}
]
}
```
### ReRank 接入(Cohere) ### ReRank 接入(Cohere)
这个重排模型对中文不是很好,不如 bge 的好用。 这个重排模型对中文不是很好,不如 bge 的好用。
...@@ -239,7 +260,7 @@ weight: 708 ...@@ -239,7 +260,7 @@ weight: 708
"reRankModels": [ "reRankModels": [
{ {
"model": "rerank-multilingual-v2.0", // 这里的model需要对应 cohere 的模型名 "model": "rerank-multilingual-v2.0", // 这里的model需要对应 cohere 的模型名
"name": "检索重排", // 随意 "name": "rerank-multilingual-v2.0",
"requestUrl": "https://api.cohere.ai/v1/rerank", "requestUrl": "https://api.cohere.ai/v1/rerank",
"requestAuth": "Coherer上申请的key" "requestAuth": "Coherer上申请的key"
} }
......
...@@ -22,7 +22,7 @@ weight: 853 ...@@ -22,7 +22,7 @@ weight: 853
**新例子** **新例子**
```bash ```bash
curl --location --request POST 'https://api.fastgpt.in/api/support/wallet/usage/createTrainingUsage' \ curl --location --request POST 'http://localhost:3000/api/support/wallet/usage/createTrainingUsage' \
--header 'Authorization: Bearer {{apikey}}' \ --header 'Authorization: Bearer {{apikey}}' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--data-raw '{ --data-raw '{
...@@ -34,7 +34,7 @@ curl --location --request POST 'https://api.fastgpt.in/api/support/wallet/usage/ ...@@ -34,7 +34,7 @@ curl --location --request POST 'https://api.fastgpt.in/api/support/wallet/usage/
**x例子** **x例子**
```bash ```bash
curl --location --request POST 'https://api.fastgpt.in/api/support/wallet/bill/createTrainingBill' \ curl --location --request POST 'http://localhost:3000/api/support/wallet/bill/createTrainingBill' \
--header 'Authorization: Bearer {{apikey}}' \ --header 'Authorization: Bearer {{apikey}}' \
--header 'Content-Type: application/json' \ --header 'Content-Type: application/json' \
--data-raw '{ --data-raw '{
......
export type UpdateChatFeedbackProps = { export type UpdateChatFeedbackProps = {
appId: string; appId: string;
chatId: string; chatId: string;
chatItemId: string; dataId: string;
shareId?: string; shareId?: string;
teamId?: string; teamId?: string;
teamToken?: string; teamToken?: string;
......
...@@ -100,7 +100,7 @@ export type ChatItemSchema = (UserChatItemType | SystemChatItemType | AIChatItem ...@@ -100,7 +100,7 @@ export type ChatItemSchema = (UserChatItemType | SystemChatItemType | AIChatItem
}; };
export type AdminFbkType = { export type AdminFbkType = {
dataId: string; feedbackDataId: string;
datasetId: string; datasetId: string;
collectionId: string; collectionId: string;
q: string; q: string;
......
...@@ -55,22 +55,22 @@ export const adaptStringValue = (value: any): ChatItemValueItemType[] => { ...@@ -55,22 +55,22 @@ export const adaptStringValue = (value: any): ChatItemValueItemType[] => {
export const addCustomFeedbacks = async ({ export const addCustomFeedbacks = async ({
appId, appId,
chatId, chatId,
chatItemId, dataId,
feedbacks feedbacks
}: { }: {
appId: string; appId: string;
chatId?: string; chatId?: string;
chatItemId?: string; dataId?: string;
feedbacks: string[]; feedbacks: string[];
}) => { }) => {
if (!chatId || !chatItemId) return; if (!chatId || !dataId) return;
try { try {
await MongoChatItem.findOneAndUpdate( await MongoChatItem.findOneAndUpdate(
{ {
appId, appId,
chatId, chatId,
dataId: chatItemId dataId
}, },
{ {
$push: { customFeedbacks: { $each: feedbacks } } $push: { customFeedbacks: { $each: feedbacks } }
......
...@@ -17,7 +17,7 @@ export const dispatchCustomFeedback = (props: Record<string, any>): Response => ...@@ -17,7 +17,7 @@ export const dispatchCustomFeedback = (props: Record<string, any>): Response =>
const { const {
runningAppInfo: { id: appId }, runningAppInfo: { id: appId },
chatId, chatId,
responseChatItemId: chatItemId, responseChatItemId: dataId,
stream, stream,
workflowStreamResponse, workflowStreamResponse,
params: { system_textareaInput: feedbackText = '' } params: { system_textareaInput: feedbackText = '' }
...@@ -27,13 +27,13 @@ export const dispatchCustomFeedback = (props: Record<string, any>): Response => ...@@ -27,13 +27,13 @@ export const dispatchCustomFeedback = (props: Record<string, any>): Response =>
addCustomFeedbacks({ addCustomFeedbacks({
appId, appId,
chatId, chatId,
chatItemId, dataId,
feedbacks: [feedbackText] feedbacks: [feedbackText]
}); });
}, 60000); }, 60000);
if (stream) { if (stream) {
if (!chatId || !chatItemId) { if (!chatId || !dataId) {
workflowStreamResponse?.({ workflowStreamResponse?.({
event: SseResponseEventEnum.fastAnswer, event: SseResponseEventEnum.fastAnswer,
data: textAdaptGptResponse({ data: textAdaptGptResponse({
......
...@@ -8,7 +8,7 @@ import { updateChatUserFeedback } from '@/web/core/chat/api'; ...@@ -8,7 +8,7 @@ import { updateChatUserFeedback } from '@/web/core/chat/api';
const FeedbackModal = ({ const FeedbackModal = ({
appId, appId,
chatId, chatId,
chatItemId, dataId,
teamId, teamId,
teamToken, teamToken,
shareId, shareId,
...@@ -18,7 +18,7 @@ const FeedbackModal = ({ ...@@ -18,7 +18,7 @@ const FeedbackModal = ({
}: { }: {
appId: string; appId: string;
chatId: string; chatId: string;
chatItemId: string; dataId: string;
shareId?: string; shareId?: string;
teamId?: string; teamId?: string;
teamToken?: string; teamToken?: string;
...@@ -35,7 +35,7 @@ const FeedbackModal = ({ ...@@ -35,7 +35,7 @@ const FeedbackModal = ({
return updateChatUserFeedback({ return updateChatUserFeedback({
appId, appId,
chatId, chatId,
chatItemId, dataId,
shareId, shareId,
teamId, teamId,
teamToken, teamToken,
......
import React, { useState } from 'react'; import React from 'react';
import { ModalBody, useTheme, ModalFooter, Button, Box, Card, Flex, Grid } from '@chakra-ui/react'; import { ModalBody, useTheme, ModalFooter, Button, Box, Card, Flex, Grid } from '@chakra-ui/react';
import { useTranslation } from 'next-i18next'; import { useTranslation } from 'next-i18next';
import Avatar from '@fastgpt/web/components/common/Avatar'; import Avatar from '@fastgpt/web/components/common/Avatar';
...@@ -13,7 +13,7 @@ import EmptyTip from '@fastgpt/web/components/common/EmptyTip'; ...@@ -13,7 +13,7 @@ import EmptyTip from '@fastgpt/web/components/common/EmptyTip';
const InputDataModal = dynamic(() => import('@/pages/dataset/detail/components/InputDataModal')); const InputDataModal = dynamic(() => import('@/pages/dataset/detail/components/InputDataModal'));
export type AdminMarkType = { export type AdminMarkType = {
dataId?: string; feedbackDataId?: string;
datasetId?: string; datasetId?: string;
collectionId?: string; collectionId?: string;
q: string; q: string;
...@@ -137,7 +137,7 @@ const SelectMarkCollection = ({ ...@@ -137,7 +137,7 @@ const SelectMarkCollection = ({
}); });
}} }}
collectionId={adminMarkData.collectionId} collectionId={adminMarkData.collectionId}
dataId={adminMarkData.dataId} dataId={adminMarkData.feedbackDataId}
defaultValue={{ defaultValue={{
q: adminMarkData.q, q: adminMarkData.q,
a: adminMarkData.a a: adminMarkData.a
...@@ -153,7 +153,7 @@ const SelectMarkCollection = ({ ...@@ -153,7 +153,7 @@ const SelectMarkCollection = ({
} }
onSuccess({ onSuccess({
dataId: data.dataId, feedbackDataId: data.dataId,
datasetId: adminMarkData.datasetId, datasetId: adminMarkData.datasetId,
collectionId: adminMarkData.collectionId, collectionId: adminMarkData.collectionId,
q: data.q, q: data.q,
......
...@@ -142,10 +142,10 @@ const ChatBox = ( ...@@ -142,10 +142,10 @@ const ChatBox = (
const [feedbackId, setFeedbackId] = useState<string>(); const [feedbackId, setFeedbackId] = useState<string>();
const [readFeedbackData, setReadFeedbackData] = useState<{ const [readFeedbackData, setReadFeedbackData] = useState<{
chatItemId: string; dataId: string;
content: string; content: string;
}>(); }>();
const [adminMarkData, setAdminMarkData] = useState<AdminMarkType & { chatItemId: string }>(); const [adminMarkData, setAdminMarkData] = useState<AdminMarkType & { dataId: string }>();
const [questionGuides, setQuestionGuide] = useState<string[]>([]); const [questionGuides, setQuestionGuide] = useState<string[]>([]);
const { const {
...@@ -660,16 +660,16 @@ const ChatBox = ( ...@@ -660,16 +660,16 @@ const ChatBox = (
if (chat.adminFeedback) { if (chat.adminFeedback) {
setAdminMarkData({ setAdminMarkData({
chatItemId: chat.dataId, dataId: chat.dataId,
datasetId: chat.adminFeedback.datasetId, datasetId: chat.adminFeedback.datasetId,
collectionId: chat.adminFeedback.collectionId, collectionId: chat.adminFeedback.collectionId,
dataId: chat.adminFeedback.dataId, feedbackDataId: chat.adminFeedback.feedbackDataId,
q: chat.adminFeedback.q || q || '', q: chat.adminFeedback.q || q || '',
a: chat.adminFeedback.a a: chat.adminFeedback.a
}); });
} else { } else {
setAdminMarkData({ setAdminMarkData({
chatItemId: chat.dataId, dataId: chat.dataId,
q, q,
a: formatChatValue2InputType(chat.value).text a: formatChatValue2InputType(chat.value).text
}); });
...@@ -703,7 +703,7 @@ const ChatBox = ( ...@@ -703,7 +703,7 @@ const ChatBox = (
chatId, chatId,
teamId, teamId,
teamToken, teamToken,
chatItemId: chat.dataId, dataId: chat.dataId,
shareId, shareId,
outLinkUid, outLinkUid,
userGoodFeedback: isGoodFeedback ? undefined : 'yes' userGoodFeedback: isGoodFeedback ? undefined : 'yes'
...@@ -725,7 +725,7 @@ const ChatBox = ( ...@@ -725,7 +725,7 @@ const ChatBox = (
teamId, teamId,
teamToken, teamToken,
chatId, chatId,
chatItemId: chat.dataId, dataId: chat.dataId,
userGoodFeedback: undefined userGoodFeedback: undefined
}); });
}; };
...@@ -750,7 +750,7 @@ const ChatBox = ( ...@@ -750,7 +750,7 @@ const ChatBox = (
updateChatUserFeedback({ updateChatUserFeedback({
appId, appId,
chatId, chatId,
chatItemId: chat.dataId, dataId: chat.dataId,
shareId, shareId,
teamId, teamId,
teamToken, teamToken,
...@@ -767,7 +767,7 @@ const ChatBox = ( ...@@ -767,7 +767,7 @@ const ChatBox = (
return () => { return () => {
if (!chat.dataId) return; if (!chat.dataId) return;
setReadFeedbackData({ setReadFeedbackData({
chatItemId: chat.dataId || '', dataId: chat.dataId || '',
content: chat.userBadFeedback || '' content: chat.userBadFeedback || ''
}); });
}; };
...@@ -778,7 +778,7 @@ const ChatBox = ( ...@@ -778,7 +778,7 @@ const ChatBox = (
closeCustomFeedback({ closeCustomFeedback({
appId, appId,
chatId, chatId,
chatItemId: chat.dataId, dataId: chat.dataId,
index: i index: i
}); });
// update dom // update dom
...@@ -945,7 +945,7 @@ const ChatBox = ( ...@@ -945,7 +945,7 @@ const ChatBox = (
text={t('common:core.app.feedback.Custom feedback')} text={t('common:core.app.feedback.Custom feedback')}
/> />
{item.customFeedbacks.map((text, i) => ( {item.customFeedbacks.map((text, i) => (
<Box key={`${text}${i}`}> <Box key={i}>
<MyTooltip <MyTooltip
label={t('common:core.app.feedback.close custom feedback')} label={t('common:core.app.feedback.close custom feedback')}
> >
...@@ -1035,7 +1035,7 @@ const ChatBox = ( ...@@ -1035,7 +1035,7 @@ const ChatBox = (
teamId={teamId} teamId={teamId}
teamToken={teamToken} teamToken={teamToken}
chatId={chatId} chatId={chatId}
chatItemId={feedbackId} dataId={feedbackId}
shareId={shareId} shareId={shareId}
outLinkUid={outLinkUid} outLinkUid={outLinkUid}
onClose={() => setFeedbackId(undefined)} onClose={() => setFeedbackId(undefined)}
...@@ -1057,7 +1057,7 @@ const ChatBox = ( ...@@ -1057,7 +1057,7 @@ const ChatBox = (
onCloseFeedback={() => { onCloseFeedback={() => {
setChatHistories((state) => setChatHistories((state) =>
state.map((chatItem) => state.map((chatItem) =>
chatItem.dataId === readFeedbackData.chatItemId chatItem.dataId === readFeedbackData.dataId
? { ...chatItem, userBadFeedback: undefined } ? { ...chatItem, userBadFeedback: undefined }
: chatItem : chatItem
) )
...@@ -1067,7 +1067,7 @@ const ChatBox = ( ...@@ -1067,7 +1067,7 @@ const ChatBox = (
updateChatUserFeedback({ updateChatUserFeedback({
appId, appId,
chatId, chatId,
chatItemId: readFeedbackData.chatItemId dataId: readFeedbackData.dataId
}); });
} catch (error) {} } catch (error) {}
setReadFeedbackData(undefined); setReadFeedbackData(undefined);
...@@ -1078,21 +1078,21 @@ const ChatBox = ( ...@@ -1078,21 +1078,21 @@ const ChatBox = (
{!!adminMarkData && ( {!!adminMarkData && (
<SelectMarkCollection <SelectMarkCollection
adminMarkData={adminMarkData} adminMarkData={adminMarkData}
setAdminMarkData={(e) => setAdminMarkData({ ...e, chatItemId: adminMarkData.chatItemId })} setAdminMarkData={(e) => setAdminMarkData({ ...e, dataId: adminMarkData.dataId })}
onClose={() => setAdminMarkData(undefined)} onClose={() => setAdminMarkData(undefined)}
onSuccess={(adminFeedback) => { onSuccess={(adminFeedback) => {
if (!appId || !chatId || !adminMarkData.chatItemId) return; if (!appId || !chatId || !adminMarkData.dataId) return;
updateChatAdminFeedback({ updateChatAdminFeedback({
appId, appId,
chatId, chatId,
chatItemId: adminMarkData.chatItemId, dataId: adminMarkData.dataId,
...adminFeedback ...adminFeedback
}); });
// update dom // update dom
setChatHistories((state) => setChatHistories((state) =>
state.map((chatItem) => state.map((chatItem) =>
chatItem.dataId === adminMarkData.chatItemId chatItem.dataId === adminMarkData.dataId
? { ? {
...chatItem, ...chatItem,
adminFeedback adminFeedback
...@@ -1105,12 +1105,12 @@ const ChatBox = ( ...@@ -1105,12 +1105,12 @@ const ChatBox = (
updateChatUserFeedback({ updateChatUserFeedback({
appId, appId,
chatId, chatId,
chatItemId: readFeedbackData.chatItemId, dataId: readFeedbackData.dataId,
userBadFeedback: undefined userBadFeedback: undefined
}); });
setChatHistories((state) => setChatHistories((state) =>
state.map((chatItem) => state.map((chatItem) =>
chatItem.dataId === readFeedbackData.chatItemId chatItem.dataId === readFeedbackData.dataId
? { ...chatItem, userBadFeedback: undefined } ? { ...chatItem, userBadFeedback: undefined }
: chatItem : chatItem
) )
......
...@@ -84,12 +84,12 @@ export type DeleteChatItemProps = OutLinkChatAuthProps & { ...@@ -84,12 +84,12 @@ export type DeleteChatItemProps = OutLinkChatAuthProps & {
export type AdminUpdateFeedbackParams = AdminFbkType & { export type AdminUpdateFeedbackParams = AdminFbkType & {
appId: string; appId: string;
chatId: string; chatId: string;
chatItemId: string; dataId: string;
}; };
export type CloseCustomFeedbackParams = { export type CloseCustomFeedbackParams = {
appId: string; appId: string;
chatId: string; chatId: string;
chatItemId: string; dataId: string;
index: number; index: number;
}; };
...@@ -13,7 +13,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< ...@@ -13,7 +13,8 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const { tmbId, teamId } = await authChatCert({ const { tmbId, teamId } = await authChatCert({
req, req,
authToken: true authToken: true,
authApiKey: true
}); });
const qgModel = global.llmModels[0]; const qgModel = global.llmModels[0];
......
...@@ -36,7 +36,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { ...@@ -36,7 +36,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) {
}; };
} }
if (appId) { if (appId) {
const { tmbId } = await authCert({ req, authToken: true }); const { tmbId } = await authCert({ req, authToken: true, authApiKey: true });
return { return {
tmbId, tmbId,
......
...@@ -17,6 +17,7 @@ async function handler(req: ApiRequestProps<{}, DelHistoryProps>, res: NextApiRe ...@@ -17,6 +17,7 @@ async function handler(req: ApiRequestProps<{}, DelHistoryProps>, res: NextApiRe
await authChatCrud({ await authChatCrud({
req, req,
authToken: true, authToken: true,
authApiKey: true,
...req.query, ...req.query,
per: WritePermissionVal per: WritePermissionVal
}); });
......
...@@ -10,10 +10,10 @@ import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant'; ...@@ -10,10 +10,10 @@ import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try { try {
await connectToDatabase(); await connectToDatabase();
const { appId, chatId, chatItemId, datasetId, dataId, q, a } = const { appId, chatId, dataId, datasetId, feedbackDataId, q, a } =
req.body as AdminUpdateFeedbackParams; req.body as AdminUpdateFeedbackParams;
if (!chatItemId || !datasetId || !dataId || !q) { if (!dataId || !datasetId || !feedbackDataId || !q) {
throw new Error('missing parameter'); throw new Error('missing parameter');
} }
...@@ -29,12 +29,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -29,12 +29,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
{ {
appId, appId,
chatId, chatId,
dataId: chatItemId dataId
}, },
{ {
adminFeedback: { adminFeedback: {
datasetId, datasetId,
dataId, dataId: feedbackDataId,
q, q,
a a
} }
......
...@@ -6,14 +6,15 @@ import type { CloseCustomFeedbackParams } from '@/global/core/chat/api.d'; ...@@ -6,14 +6,15 @@ import type { CloseCustomFeedbackParams } from '@/global/core/chat/api.d';
import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema'; import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema';
import { authChatCrud } from '@/service/support/permission/auth/chat'; import { authChatCrud } from '@/service/support/permission/auth/chat';
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant'; import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
import { mongoSessionRun } from '@fastgpt/service/common/mongo/sessionRun';
/* remove custom feedback */ /* remove custom feedback */
export default async function handler(req: NextApiRequest, res: NextApiResponse) { export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try { try {
await connectToDatabase(); await connectToDatabase();
const { appId, chatId, chatItemId, index } = req.body as CloseCustomFeedbackParams; const { appId, chatId, dataId, index } = req.body as CloseCustomFeedbackParams;
if (!chatItemId || !appId || !chatId || !chatItemId) { if (!dataId || !appId || !chatId) {
throw new Error('missing parameter'); throw new Error('missing parameter');
} }
...@@ -26,10 +27,22 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -26,10 +27,22 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
}); });
await authCert({ req, authToken: true }); await authCert({ req, authToken: true });
await mongoSessionRun(async (session) => {
await MongoChatItem.findOneAndUpdate( await MongoChatItem.findOneAndUpdate(
{ appId, chatId, dataId: chatItemId }, { appId, chatId, dataId },
{ $unset: { [`customFeedbacks.${index}`]: 1 } } { $unset: { [`customFeedbacks.${index}`]: 1 } },
{
session
}
); );
await MongoChatItem.findOneAndUpdate(
{ appId, chatId, dataId },
{ $pull: { customFeedbacks: null } },
{
session
}
);
});
jsonRes(res); jsonRes(res);
} catch (err) { } catch (err) {
......
...@@ -11,7 +11,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -11,7 +11,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
const { const {
appId, appId,
chatId, chatId,
chatItemId, dataId,
shareId, shareId,
teamId, teamId,
teamToken, teamToken,
...@@ -36,15 +36,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -36,15 +36,15 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
per: ReadPermissionVal per: ReadPermissionVal
}); });
if (!chatItemId) { if (!dataId) {
throw new Error('chatItemId is required'); throw new Error('dataId is required');
} }
await MongoChatItem.findOneAndUpdate( await MongoChatItem.findOneAndUpdate(
{ {
appId, appId,
chatId, chatId,
dataId: chatItemId dataId
}, },
{ {
$unset: { $unset: {
......
...@@ -43,7 +43,7 @@ async function handler( ...@@ -43,7 +43,7 @@ async function handler(
}; };
} }
if (appId) { if (appId) {
const { tmbId } = await authCert({ req, authToken: true }); const { tmbId } = await authCert({ req, authToken: true, authApiKey: true });
return { return {
tmbId, tmbId,
appId, appId,
......
...@@ -26,7 +26,14 @@ async function handler( ...@@ -26,7 +26,14 @@ async function handler(
req: ApiRequestProps<getPaginationRecordsBody, getPaginationRecordsQuery>, req: ApiRequestProps<getPaginationRecordsBody, getPaginationRecordsQuery>,
res: ApiResponseType<any> res: ApiResponseType<any>
): Promise<getPaginationRecordsResponse> { ): Promise<getPaginationRecordsResponse> {
const { chatId, appId, offset, pageSize = 10, loadCustomFeedbacks, type } = req.body; const {
appId,
chatId,
offset,
pageSize = 10,
loadCustomFeedbacks,
type = GetChatTypeEnum.normal
} = req.body;
if (!appId || !chatId) { if (!appId || !chatId) {
return { return {
...@@ -40,6 +47,7 @@ async function handler( ...@@ -40,6 +47,7 @@ async function handler(
authChatCrud({ authChatCrud({
req, req,
authToken: true, authToken: true,
authApiKey: true,
...req.body, ...req.body,
per: ReadPermissionVal per: ReadPermissionVal
}) })
......
...@@ -37,6 +37,7 @@ async function handler( ...@@ -37,6 +37,7 @@ async function handler(
await authChatCrud({ await authChatCrud({
req, req,
authToken: true, authToken: true,
authApiKey: true,
...req.query, ...req.query,
per: ReadPermissionVal per: ReadPermissionVal
}); });
...@@ -44,6 +45,7 @@ async function handler( ...@@ -44,6 +45,7 @@ async function handler(
await authApp({ await authApp({
req, req,
authToken: true, authToken: true,
authApiKey: true,
appId, appId,
per: ManagePermissionVal per: ManagePermissionVal
}); });
......
...@@ -29,6 +29,7 @@ async function handler( ...@@ -29,6 +29,7 @@ async function handler(
authApp({ authApp({
req, req,
authToken: true, authToken: true,
authApiKey: true,
appId, appId,
per: ReadPermissionVal per: ReadPermissionVal
}), }),
......
import type { NextApiRequest, NextApiResponse } from 'next'; import type { NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response'; import { jsonRes } from '@fastgpt/service/common/response';
import { connectToDatabase } from '@/service/mongo';
import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema'; import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema';
import { authChatCrud } from '@/service/support/permission/auth/chat'; import { authChatCrud } from '@/service/support/permission/auth/chat';
import type { DeleteChatItemProps } from '@/global/core/chat/api.d'; import type { DeleteChatItemProps } from '@/global/core/chat/api.d';
...@@ -9,7 +8,7 @@ import { ApiRequestProps } from '@fastgpt/service/type/next'; ...@@ -9,7 +8,7 @@ import { ApiRequestProps } from '@fastgpt/service/type/next';
import { WritePermissionVal } from '@fastgpt/global/support/permission/constant'; import { WritePermissionVal } from '@fastgpt/global/support/permission/constant';
async function handler(req: ApiRequestProps<{}, DeleteChatItemProps>, res: NextApiResponse) { async function handler(req: ApiRequestProps<{}, DeleteChatItemProps>, res: NextApiResponse) {
const { appId, chatId, contentId, shareId, outLinkUid } = req.query; const { appId, chatId, contentId } = req.query;
if (!contentId || !chatId) { if (!contentId || !chatId) {
return jsonRes(res); return jsonRes(res);
...@@ -18,6 +17,7 @@ async function handler(req: ApiRequestProps<{}, DeleteChatItemProps>, res: NextA ...@@ -18,6 +17,7 @@ async function handler(req: ApiRequestProps<{}, DeleteChatItemProps>, res: NextA
await authChatCrud({ await authChatCrud({
req, req,
authToken: true, authToken: true,
authApiKey: true,
...req.query, ...req.query,
per: WritePermissionVal per: WritePermissionVal
}); });
......
...@@ -24,7 +24,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse) ...@@ -24,7 +24,11 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse)
throw new Error('model or voice not found'); throw new Error('model or voice not found');
} }
const { teamId, tmbId, authType } = await authChatCert({ req, authToken: true }); const { teamId, tmbId, authType } = await authChatCert({
req,
authToken: true,
authApiKey: true
});
const ttsModel = getAudioSpeechModel(ttsConfig.model); const ttsModel = getAudioSpeechModel(ttsConfig.model);
const voiceData = ttsModel.voices?.find((item) => item.value === ttsConfig.voice); const voiceData = ttsModel.voices?.find((item) => item.value === ttsConfig.voice);
......
import type { NextApiRequest, NextApiResponse } from 'next'; import type { NextApiResponse } from 'next';
import { jsonRes } from '@fastgpt/service/common/response'; import { jsonRes } from '@fastgpt/service/common/response';
import { UpdateHistoryProps } from '@/global/core/chat/api.d'; import { UpdateHistoryProps } from '@/global/core/chat/api.d';
import { MongoChat } from '@fastgpt/service/core/chat/chatSchema'; import { MongoChat } from '@fastgpt/service/core/chat/chatSchema';
...@@ -13,6 +13,7 @@ async function handler(req: ApiRequestProps<UpdateHistoryProps>, res: NextApiRes ...@@ -13,6 +13,7 @@ async function handler(req: ApiRequestProps<UpdateHistoryProps>, res: NextApiRes
await authChatCrud({ await authChatCrud({
req, req,
authToken: true, authToken: true,
authApiKey: true,
...req.body, ...req.body,
per: WritePermissionVal per: WritePermissionVal
}); });
......
...@@ -18,7 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< ...@@ -18,7 +18,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
const { const {
appId, appId,
chatId, chatId,
responseChatItemId: chatItemId, responseChatItemId: dataId,
defaultFeedback, defaultFeedback,
customFeedback customFeedback
} = req.body as Props; } = req.body as Props;
...@@ -38,12 +38,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< ...@@ -38,12 +38,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
addCustomFeedbacks({ addCustomFeedbacks({
appId, appId,
chatId, chatId,
chatItemId, dataId,
feedbacks: [feedback] feedbacks: [feedback]
}); });
}, 60000); }, 60000);
if (!chatId || !chatItemId) { if (!chatId || !dataId) {
return res.json({ return res.json({
response: `\\n\\n**自动反馈调试**: ${feedback}\\n\\n` response: `\\n\\n**自动反馈调试**: ${feedback}\\n\\n`
}); });
......
...@@ -20,7 +20,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< ...@@ -20,7 +20,7 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
customFeedback, customFeedback,
appId, appId,
chatId, chatId,
responseChatItemId: chatItemId, responseChatItemId: dataId,
customInputs customInputs
} = req.body as Props; } = req.body as Props;
...@@ -37,12 +37,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse< ...@@ -37,12 +37,12 @@ export default async function handler(req: NextApiRequest, res: NextApiResponse<
addCustomFeedbacks({ addCustomFeedbacks({
appId, appId,
chatId, chatId,
chatItemId, dataId,
feedbacks: [feedbackText] feedbacks: [feedbackText]
}); });
}, 60000); }, 60000);
if (!chatId || !chatItemId) { if (!chatId || !dataId) {
return res.json({ return res.json({
[NodeOutputKeyEnum.answerText]: `\\n\\n**自动反馈调试**: "${feedbackText}"\\n\\n`, [NodeOutputKeyEnum.answerText]: `\\n\\n**自动反馈调试**: "${feedbackText}"\\n\\n`,
text: feedbackText text: feedbackText
......
import { create } from 'zustand'; import { create } from 'zustand';
import { devtools, persist } from 'zustand/middleware'; import { devtools } from 'zustand/middleware';
import { immer } from 'zustand/middleware/immer'; import { immer } from 'zustand/middleware/immer';
export type MarkDataStore = { export type MarkDataStore = {
chatItemId: string; dataId: string;
datasetId?: string; datasetId?: string;
collectionId?: string; collectionId?: string;
q: string; q: string;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment