Skip to content

Commit

Permalink
Add modal to show completion response data (labring#324)
Browse files Browse the repository at this point in the history
  • Loading branch information
c121914yu authored Sep 19, 2023
1 parent ce7da2d commit ac4355d
Show file tree
Hide file tree
Showing 24 changed files with 485 additions and 155 deletions.
22 changes: 22 additions & 0 deletions client/public/locales/en/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@
"share": "Share",
"test": "Test Chat "
},
"response": {
"module cq": "Question classification list",
"module cq result": "Classification Result",
"module extract description": "Extract Description",
"module extract result": "Extract Result",
"module historyPreview": "Messages",
"module http body": "Body",
"module http result": "Response",
"module http url": "Request Url",
"module limit": "Count Limit",
"module maxToken": "MaxTokens",
"module model": "Model",
"module name": "Name",
"module price": "Price",
"module question": "Question",
"module quoteList": "Quotes",
"module runningTime": "Time",
"module similarity": "Similarity",
"module temperature": "Temperature",
"module time": "Running Time",
"module tokens": "Tokens"
},
"retry": "Retry"
},
"common": {
Expand Down
24 changes: 23 additions & 1 deletion client/public/locales/zh/common.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,28 @@
"share": "外部链接调用",
"test": "测试"
},
"response": {
"module cq": "问题分类列表",
"module cq result": "分类结果",
"module extract description": "提取要求描述",
"module extract result": "提取结果",
"module historyPreview": "完整记录",
"module http body": "请求体",
"module http result": "响应体",
"module http url": "请求地址",
"module limit": "单次搜索上限",
"module maxToken": "最大 Tokens",
"module model": "模型",
"module name": "模型名",
"module price": "计费",
"module question": "问题",
"module quoteList": "引用内容",
"module runningTime": "运行时长",
"module similarity": "相似度",
"module temperature": "温度",
"module time": "运行时长",
"module tokens": "Tokens"
},
"retry": "重新生成"
},
"common": {
Expand Down Expand Up @@ -228,7 +250,7 @@
"Help Document": "帮助文档"
},
"template": {
"Quote Content Tip": "该配置只有传入引用内容(知识库搜索)时生效。\n可以自定义引用内容的结构,以更好的适配不同场景。可以使用 {{q}}, {{a}}, {{source}} 来作为 “检索内容”、“预期内容”和“来源”,他们都是可选的,下面是默认值:\n{{default}}",
"Quote Content Tip": "该配置只有传入引用内容(知识库搜索)时生效。\n可以自定义引用内容的结构,以更好的适配不同场景。可以使用一些变量来进行模板配置:\n{{q}} - 检索内容, {{a}} - 预期内容, {{source}} - 来源,{{file_id}} - 来源文件名,{{index}} - 第n个引用,他们都是可选的,下面是默认值:\n{{default}}",
"Quote Prompt Tip": "该配置只有传入引用内容(知识库搜索)时生效。\n可以用 {{quote}} 来插入引用内容,使用 {{question}} 来插入问题。下面是默认值:\n{{default}}"
},
"user": {
Expand Down
7 changes: 5 additions & 2 deletions client/src/api/service/plugins.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
import { GET, POST } from './request';
import { POST } from './request';

export const textCensor = (data: { text: string }) =>
POST<{ code?: number; message: string }>('/plugins/censor/text_baidu', data)
.then((res) => {
if (res?.code === 5000) {
return Promise.reject(res.message);
return Promise.reject(res);
}
})
.catch((err) => {
if (err?.code === 5000) {
return Promise.reject(err.message);
}
return Promise.resolve('');
});
73 changes: 43 additions & 30 deletions client/src/components/ChatBox/ResponseTags.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,18 @@ const ResponseTags = ({
} = useDisclosure();

const {
chatAccount,
quoteList = [],
historyPreview = [],
runningTime = 0
} = useMemo(() => {
const chatData = responseData.find((item) => item.moduleType === FlowModuleTypeEnum.chatNode);
if (!chatData) return {};
return {
quoteList: chatData.quoteList,
historyPreview: chatData.historyPreview,
runningTime: responseData.reduce((sum, item) => sum + (item.runningTime || 0), 0)
chatAccount: responseData.filter((item) => item.moduleType === FlowModuleTypeEnum.chatNode)
.length,
quoteList: chatData?.quoteList,
historyPreview: chatData?.historyPreview,
runningTime: responseData.reduce((sum, item) => sum + (item.runningTime || 0), 0).toFixed(2)
};
}, [responseData]);

Expand All @@ -54,36 +56,47 @@ const ResponseTags = ({

return responseData.length === 0 ? null : (
<Flex alignItems={'center'} mt={2} flexWrap={'wrap'}>
{quoteList.length > 0 && (
<MyTooltip label="查看引用">
<Tag
colorSchema="blue"
cursor={'pointer'}
{...TagStyles}
onClick={() => setQuoteModalData(quoteList)}
>
{quoteList.length}条引用
</Tag>
</MyTooltip>
{chatAccount === 1 ? (
<>
{quoteList.length > 0 && (
<MyTooltip label="查看引用">
<Tag
colorSchema="blue"
cursor={'pointer'}
{...TagStyles}
onClick={() => setQuoteModalData(quoteList)}
>
{quoteList.length}条引用
</Tag>
</MyTooltip>
)}
{historyPreview.length > 0 && (
<MyTooltip label={'点击查看完整对话记录'}>
<Tag
colorSchema="green"
cursor={'pointer'}
{...TagStyles}
onClick={() => setContextModalData(historyPreview)}
>
{historyPreview.length}条上下文
</Tag>
</MyTooltip>
)}
</>
) : (
<Tag colorSchema="blue" {...TagStyles}>
多组 AI 对话
</Tag>
)}
{historyPreview.length > 0 && (
<MyTooltip label={'点击查看完整对话记录'}>
<Tag
colorSchema="green"
cursor={'pointer'}
{...TagStyles}
onClick={() => setContextModalData(historyPreview)}
>
{historyPreview.length}条上下文

{isPc && runningTime > 0 && (
<MyTooltip label={'模块运行时间和'}>
<Tag colorSchema="purple" cursor={'default'} {...TagStyles}>
{runningTime}s
</Tag>
</MyTooltip>
)}
{isPc && runningTime > 0 && (
<Tag colorSchema="purple" cursor={'default'} {...TagStyles}>
{runningTime}s
</Tag>
)}
<MyTooltip label={'点击查看完整响应值'}>
<MyTooltip label={'点击查看完整响应'}>
<Tag colorSchema="gray" cursor={'pointer'} {...TagStyles} onClick={onOpenWholeModal}>
{t('chat.Complete Response')}
</Tag>
Expand Down
Loading

0 comments on commit ac4355d

Please sign in to comment.