Skip to content

Commit

Permalink
4.8.10 perf (#2378)
Browse files Browse the repository at this point in the history
* perf: helpline code

* fix: prompt call stream=false response prefix

* fix: app chat log auth

* perf: new chat i18n

* fix: milvus dataset cannot export data

* perf: doc intro
  • Loading branch information
c121914yu authored Aug 15, 2024
1 parent fdeb159 commit 86c27e8
Show file tree
Hide file tree
Showing 16 changed files with 500 additions and 480 deletions.
8 changes: 7 additions & 1 deletion docSite/content/zh-cn/docs/development/upgrading/4810.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,10 @@ weight: 816
## V4.8.10 更新说明

1. 新增 - 模板市场
2.
2. 新增 - 工作流节点拖动自动对齐吸附
3. 新增 - 用户选择节点(Debug 模式暂未支持)
4. 商业版新增 - 飞书机器人接入
5. 商业版新增 - 公众号接入接入
6. 修复 - Prompt 模式调用工具,stream=false 模式下,会携带 0: 开头标记。
7. 修复 - 对话日志鉴权问题:仅为 APP 管理员的用户,无法查看对话日志详情。
8. 修复 - 选择 Milvus 部署时,无法导出知识库。
Original file line number Diff line number Diff line change
Expand Up @@ -411,6 +411,7 @@ const parseAnswer = (
str = str.trim();
// 首先,使用正则表达式提取TOOL_ID和TOOL_ARGUMENTS
const prefixReg = /^1(:|)/;
const answerPrefixReg = /^0(:|)/;

if (prefixReg.test(str)) {
const toolString = sliceJsonStr(str);
Expand All @@ -432,7 +433,7 @@ const parseAnswer = (
}
} else {
return {
answer: str
answer: str.replace(answerPrefixReg, '')
};
}
};
2 changes: 1 addition & 1 deletion projects/app/src/global/core/chat/api.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ export type InitChatResponse = {
chatId?: string;
appId: string;
userAvatar?: string;
title: string;
title?: string;
variables: Record<string, any>;
history: ChatItemType[];
app: {
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/global/core/chat/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { InitChatResponse } from './api';
import { i18nT } from '@fastgpt/web/i18n/utils';

export const defaultChatData: InitChatResponse = {
chatId: '',
appId: '',
Expand All @@ -12,7 +12,7 @@ export const defaultChatData: InitChatResponse = {
type: AppTypeEnum.simple,
pluginInputs: []
},
title: i18nT('chat:new_chat'),
title: '',
variables: {},
history: []
};
30 changes: 23 additions & 7 deletions projects/app/src/pages/api/core/chat/getResData.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
import { authChatCrud } from '@/service/support/permission/auth/chat';
import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
import {
ManagePermissionVal,
ReadPermissionVal
} from '@fastgpt/global/support/permission/constant';
import { MongoChatItem } from '@fastgpt/service/core/chat/chatItemSchema';
import { ChatRoleEnum } from '@fastgpt/global/core/chat/constants';
import type { ApiRequestProps, ApiResponseType } from '@fastgpt/service/type/next';
import { NextAPI } from '@/service/middleware/entry';
import { ChatHistoryItemResType } from '@fastgpt/global/core/chat/type';
import { OutLinkChatAuthProps } from '@fastgpt/global/support/permission/chat';
import { authApp } from '@fastgpt/service/support/permission/app/auth';

export type getResDataQuery = OutLinkChatAuthProps & {
chatId?: string;
Expand All @@ -25,12 +29,24 @@ async function handler(
if (!appId || !chatId || !dataId) {
return {};
}
await authChatCrud({
req,
authToken: true,
...req.query,
per: ReadPermissionVal
});

// 1. Un login api: share chat, team chat
// 2. Login api: account chat, chat log
try {
await authChatCrud({
req,
authToken: true,
...req.query,
per: ReadPermissionVal
});
} catch (error) {
await authApp({
req,
authToken: true,
appId,
per: ManagePermissionVal
});
}

const chatData = await MongoChatItem.findOne({
appId,
Expand Down
4 changes: 2 additions & 2 deletions projects/app/src/pages/api/core/chat/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import { ReadPermissionVal } from '@fastgpt/global/support/permission/constant';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import { transformPreviewHistories } from '@/global/core/chat/utils';
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { i18nT } from '@fastgpt/web/i18n/utils';

async function handler(
req: NextApiRequest,
res: NextApiResponse
Expand Down Expand Up @@ -62,7 +62,7 @@ async function handler(
return {
chatId,
appId,
title: chat?.title || i18nT('chat:new_chat'),
title: chat?.title,
userAvatar: undefined,
variables: chat?.variables || {},
history: app.type === AppTypeEnum.plugin ? histories : transformPreviewHistories(histories),
Expand Down
140 changes: 67 additions & 73 deletions projects/app/src/pages/api/core/chat/outLink/init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,90 +18,84 @@ import { getAppLatestVersion } from '@fastgpt/service/core/app/controller';
import { FlowNodeTypeEnum } from '@fastgpt/global/core/workflow/node/constant';
import { AppTypeEnum } from '@fastgpt/global/core/app/constants';
import { transformPreviewHistories } from '@/global/core/chat/utils';
import { i18nT } from '@fastgpt/web/i18n/utils';
export default async function handler(req: NextApiRequest, res: NextApiResponse) {
try {
await connectToDatabase();
import { NextAPI } from '@/service/middleware/entry';

let { chatId, shareId, outLinkUid } = req.query as InitOutLinkChatProps;
async function handler(req: NextApiRequest, res: NextApiResponse) {
let { chatId, shareId, outLinkUid } = req.query as InitOutLinkChatProps;

// auth link permission
const { shareChat, uid, appId } = await authOutLink({ shareId, outLinkUid });
// auth link permission
const { shareChat, uid, appId } = await authOutLink({ shareId, outLinkUid });

// auth app permission
const [tmb, chat, app] = await Promise.all([
MongoTeamMember.findById(shareChat.tmbId, '_id userId').populate('userId', 'avatar').lean(),
MongoChat.findOne({ appId, chatId, shareId }).lean(),
MongoApp.findById(appId).lean()
]);
// auth app permission
const [tmb, chat, app] = await Promise.all([
MongoTeamMember.findById(shareChat.tmbId, '_id userId').populate('userId', 'avatar').lean(),
MongoChat.findOne({ appId, chatId, shareId }).lean(),
MongoApp.findById(appId).lean()
]);

if (!app) {
throw new Error(AppErrEnum.unExist);
}

// auth chat permission
if (chat && chat.outLinkUid !== uid) {
throw new Error(ChatErrEnum.unAuthChat);
}
if (!app) {
throw new Error(AppErrEnum.unExist);
}

const [{ histories }, { nodes }] = await Promise.all([
getChatItems({
appId: app._id,
chatId,
limit: 30,
field: `dataId obj value userGoodFeedback userBadFeedback ${
shareChat.responseDetail || app.type === AppTypeEnum.plugin
? `adminFeedback ${DispatchNodeResponseKeyEnum.nodeResponse}`
: ''
} `
}),
getAppLatestVersion(app._id, app)
]);
// auth chat permission
if (chat && chat.outLinkUid !== uid) {
throw new Error(ChatErrEnum.unAuthChat);
}

// pick share response field
app.type !== AppTypeEnum.plugin &&
histories.forEach((item) => {
if (item.obj === ChatRoleEnum.AI) {
item.responseData = filterPublicNodeResponseData({ flowResponses: item.responseData });
}
});
const [{ histories }, { nodes }] = await Promise.all([
getChatItems({
appId: app._id,
chatId,
limit: 30,
field: `dataId obj value userGoodFeedback userBadFeedback ${
shareChat.responseDetail || app.type === AppTypeEnum.plugin
? `adminFeedback ${DispatchNodeResponseKeyEnum.nodeResponse}`
: ''
} `
}),
getAppLatestVersion(app._id, app)
]);

jsonRes<InitChatResponse>(res, {
data: {
chatId,
appId: app._id,
title: chat?.title || i18nT('chat:new_chat'),
//@ts-ignore
userAvatar: tmb?.userId?.avatar,
variables: chat?.variables || {},
history: app.type === AppTypeEnum.plugin ? histories : transformPreviewHistories(histories),
app: {
chatConfig: getAppChatConfig({
chatConfig: app.chatConfig,
systemConfigNode: getGuideModule(nodes),
storeVariables: chat?.variableList,
storeWelcomeText: chat?.welcomeText,
isPublicFetch: false
}),
chatModels: getChatModelNameListByModules(nodes),
name: app.name,
avatar: app.avatar,
intro: app.intro,
type: app.type,
pluginInputs:
app?.modules?.find((node) => node.flowNodeType === FlowNodeTypeEnum.pluginInput)
?.inputs ?? []
}
// pick share response field
app.type !== AppTypeEnum.plugin &&
histories.forEach((item) => {
if (item.obj === ChatRoleEnum.AI) {
item.responseData = filterPublicNodeResponseData({ flowResponses: item.responseData });
}
});
} catch (err) {
jsonRes(res, {
code: 500,
error: err
});
}

jsonRes<InitChatResponse>(res, {
data: {
chatId,
appId: app._id,
title: chat?.title,
//@ts-ignore
userAvatar: tmb?.userId?.avatar,
variables: chat?.variables || {},
history: app.type === AppTypeEnum.plugin ? histories : transformPreviewHistories(histories),
app: {
chatConfig: getAppChatConfig({
chatConfig: app.chatConfig,
systemConfigNode: getGuideModule(nodes),
storeVariables: chat?.variableList,
storeWelcomeText: chat?.welcomeText,
isPublicFetch: false
}),
chatModels: getChatModelNameListByModules(nodes),
name: app.name,
avatar: app.avatar,
intro: app.intro,
type: app.type,
pluginInputs:
app?.modules?.find((node) => node.flowNodeType === FlowNodeTypeEnum.pluginInput)
?.inputs ?? []
}
}
});
}

export default NextAPI(handler);

export const config = {
api: {
responseLimit: '10mb'
Expand Down
Loading

0 comments on commit 86c27e8

Please sign in to comment.