feat: translate graph and chat text (#1433)
Browse files- web/src/hooks/flow-hooks.ts +4 -2
- web/src/locales/en.ts +12 -1
- web/src/locales/zh-traditional.ts +12 -0
- web/src/locales/zh.ts +11 -0
- web/src/pages/chat/hooks.ts +2 -2
- web/src/pages/flow/canvas/node/begin-node.tsx +4 -2
- web/src/pages/flow/canvas/node/categorize-handle.tsx +6 -1
- web/src/pages/flow/canvas/node/categorize-node.tsx +4 -3
- web/src/pages/flow/canvas/node/index.tsx +6 -2
- web/src/pages/flow/canvas/node/relevant-node.tsx +4 -2
- web/src/pages/flow/flow-sider/index.tsx +1 -1
- web/src/pages/flow/list/index.tsx +1 -1
web/src/hooks/flow-hooks.ts
CHANGED
@@ -1,3 +1,4 @@
|
|
|
|
1 |
import { ResponseType } from '@/interfaces/database/base';
|
2 |
import { DSL, IFlow, IFlowTemplate } from '@/interfaces/database/flow';
|
3 |
import i18n from '@/locales/config';
|
@@ -45,6 +46,7 @@ export const EmptyDsl = {
|
|
45 |
};
|
46 |
|
47 |
export const useFetchFlowTemplates = (): ResponseType<IFlowTemplate[]> => {
|
|
|
48 |
const { data } = useQuery({
|
49 |
queryKey: ['fetchFlowTemplates'],
|
50 |
initialData: [],
|
@@ -53,8 +55,8 @@ export const useFetchFlowTemplates = (): ResponseType<IFlowTemplate[]> => {
|
|
53 |
if (Array.isArray(data?.data)) {
|
54 |
data.data.unshift({
|
55 |
id: uuid(),
|
56 |
-
title: '
|
57 |
-
description: '
|
58 |
dsl: EmptyDsl,
|
59 |
});
|
60 |
}
|
|
|
1 |
+
import { useTranslate } from '@/hooks/commonHooks';
|
2 |
import { ResponseType } from '@/interfaces/database/base';
|
3 |
import { DSL, IFlow, IFlowTemplate } from '@/interfaces/database/flow';
|
4 |
import i18n from '@/locales/config';
|
|
|
46 |
};
|
47 |
|
48 |
export const useFetchFlowTemplates = (): ResponseType<IFlowTemplate[]> => {
|
49 |
+
const { t } = useTranslate('flow');
|
50 |
const { data } = useQuery({
|
51 |
queryKey: ['fetchFlowTemplates'],
|
52 |
initialData: [],
|
|
|
55 |
if (Array.isArray(data?.data)) {
|
56 |
data.data.unshift({
|
57 |
id: uuid(),
|
58 |
+
title: t('blank'),
|
59 |
+
description: t('createFromNothing'),
|
60 |
dsl: EmptyDsl,
|
61 |
});
|
62 |
}
|
web/src/locales/en.ts
CHANGED
@@ -308,6 +308,7 @@ The above is the content you need to summarize.`,
|
|
308 |
ellipse: 'Ellipse',
|
309 |
},
|
310 |
chat: {
|
|
|
311 |
createAssistant: 'Create an Assistant',
|
312 |
assistantSetting: 'Assistant Setting',
|
313 |
promptEngine: 'Prompt Engine',
|
@@ -581,8 +582,18 @@ The above is the content you need to summarize.`,
|
|
581 |
promptText: `Please summarize the following paragraphs. Be careful with the numbers, do not make things up. Paragraphs as following:
|
582 |
{input}
|
583 |
The above is the content you need to summarize.`,
|
584 |
-
|
585 |
createFromTemplates: 'Create from templates',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
586 |
},
|
587 |
footer: {
|
588 |
profile: 'All rights reserved @ React',
|
|
|
308 |
ellipse: 'Ellipse',
|
309 |
},
|
310 |
chat: {
|
311 |
+
newConversation: 'New conversation',
|
312 |
createAssistant: 'Create an Assistant',
|
313 |
assistantSetting: 'Assistant Setting',
|
314 |
promptEngine: 'Prompt Engine',
|
|
|
582 |
promptText: `Please summarize the following paragraphs. Be careful with the numbers, do not make things up. Paragraphs as following:
|
583 |
{input}
|
584 |
The above is the content you need to summarize.`,
|
585 |
+
createGraph: 'Create graph',
|
586 |
createFromTemplates: 'Create from templates',
|
587 |
+
retrieval: 'Retrieval',
|
588 |
+
generate: 'Generate',
|
589 |
+
answer: 'Answer',
|
590 |
+
categorize: 'Categorize',
|
591 |
+
relevant: 'Relevant',
|
592 |
+
rewriteQuestion: 'RewriteQuestion',
|
593 |
+
rewrite: 'Rewrite',
|
594 |
+
Begin: 'Begin',
|
595 |
+
blank: 'Blank',
|
596 |
+
createFromNothing: 'Create from nothing',
|
597 |
},
|
598 |
footer: {
|
599 |
profile: 'All rights reserved @ React',
|
web/src/locales/zh-traditional.ts
CHANGED
@@ -280,6 +280,7 @@ export default {
|
|
280 |
ellipse: '省略',
|
281 |
},
|
282 |
chat: {
|
|
|
283 |
createAssistant: '新建助理',
|
284 |
assistantSetting: '助理設置',
|
285 |
promptEngine: '提示引擎',
|
@@ -529,6 +530,7 @@ export default {
|
|
529 |
run: '運行',
|
530 |
save: '儲存',
|
531 |
title: '標題:',
|
|
|
532 |
beginDescription: '這是流程開始的地方',
|
533 |
answerDescription: `該組件用作機器人與人類之間的介面。它接收使用者的輸入並顯示機器人的計算結果。`,
|
534 |
retrievalDescription: `此元件用於從知識庫中檢索相關資訊。選擇知識庫。如果沒有檢索到任何內容,將傳回「空響應」。`,
|
@@ -544,6 +546,16 @@ export default {
|
|
544 |
以上就是你需要總結的內容。`,
|
545 |
createGraph: '建立圖表',
|
546 |
createFromTemplates: '從模板創建',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
547 |
},
|
548 |
footer: {
|
549 |
profile: '“保留所有權利 @ react”',
|
|
|
280 |
ellipse: '省略',
|
281 |
},
|
282 |
chat: {
|
283 |
+
newConversation: '新會話',
|
284 |
createAssistant: '新建助理',
|
285 |
assistantSetting: '助理設置',
|
286 |
promptEngine: '提示引擎',
|
|
|
530 |
run: '運行',
|
531 |
save: '儲存',
|
532 |
title: '標題:',
|
533 |
+
|
534 |
beginDescription: '這是流程開始的地方',
|
535 |
answerDescription: `該組件用作機器人與人類之間的介面。它接收使用者的輸入並顯示機器人的計算結果。`,
|
536 |
retrievalDescription: `此元件用於從知識庫中檢索相關資訊。選擇知識庫。如果沒有檢索到任何內容,將傳回「空響應」。`,
|
|
|
546 |
以上就是你需要總結的內容。`,
|
547 |
createGraph: '建立圖表',
|
548 |
createFromTemplates: '從模板創建',
|
549 |
+
retrieval: '檢索',
|
550 |
+
generate: '產生',
|
551 |
+
answer: '回答',
|
552 |
+
categorize: '分類',
|
553 |
+
relevant: '相關',
|
554 |
+
rewriteQuestion: '重組',
|
555 |
+
rewrite: '重組',
|
556 |
+
begin: '開始',
|
557 |
+
blank: '空',
|
558 |
+
createFromNothing: '從無到有',
|
559 |
},
|
560 |
footer: {
|
561 |
profile: '“保留所有權利 @ react”',
|
web/src/locales/zh.ts
CHANGED
@@ -297,6 +297,7 @@ export default {
|
|
297 |
ellipse: '省略',
|
298 |
},
|
299 |
chat: {
|
|
|
300 |
createAssistant: '新建助理',
|
301 |
assistantSetting: '助理设置',
|
302 |
promptEngine: '提示引擎',
|
@@ -563,6 +564,16 @@ export default {
|
|
563 |
以上就是你需要总结的内容。`,
|
564 |
createGraph: '创建图表',
|
565 |
createFromTemplates: '从模板创建',
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
566 |
},
|
567 |
footer: {
|
568 |
profile: 'All rights reserved @ React',
|
|
|
297 |
ellipse: '省略',
|
298 |
},
|
299 |
chat: {
|
300 |
+
newConversation: '新会话',
|
301 |
createAssistant: '新建助理',
|
302 |
assistantSetting: '助理设置',
|
303 |
promptEngine: '提示引擎',
|
|
|
564 |
以上就是你需要总结的内容。`,
|
565 |
createGraph: '创建图表',
|
566 |
createFromTemplates: '从模板创建',
|
567 |
+
retrieval: '检索',
|
568 |
+
generate: '生成',
|
569 |
+
answer: '回答',
|
570 |
+
categorize: '分类',
|
571 |
+
relevant: '相关',
|
572 |
+
rewriteQuestion: '重组',
|
573 |
+
rewrite: '重组',
|
574 |
+
begin: '开始',
|
575 |
+
blank: '空',
|
576 |
+
createFromNothing: '从无到有',
|
577 |
},
|
578 |
footer: {
|
579 |
profile: 'All rights reserved @ React',
|
web/src/pages/chat/hooks.ts
CHANGED
@@ -303,14 +303,14 @@ export const useSelectDerivedConversationList = () => {
|
|
303 |
const { conversationList, currentDialog } = chatModel;
|
304 |
const { dialogId } = useGetChatSearchParams();
|
305 |
const prologue = currentDialog?.prompt_config?.prologue ?? '';
|
306 |
-
|
307 |
const addTemporaryConversation = useCallback(() => {
|
308 |
setList((pre) => {
|
309 |
if (dialogId) {
|
310 |
const nextList = [
|
311 |
{
|
312 |
id: '',
|
313 |
-
name: '
|
314 |
dialog_id: dialogId,
|
315 |
message: [
|
316 |
{
|
|
|
303 |
const { conversationList, currentDialog } = chatModel;
|
304 |
const { dialogId } = useGetChatSearchParams();
|
305 |
const prologue = currentDialog?.prompt_config?.prologue ?? '';
|
306 |
+
const { t } = useTranslate('chat');
|
307 |
const addTemporaryConversation = useCallback(() => {
|
308 |
setList((pre) => {
|
309 |
if (dialogId) {
|
310 |
const nextList = [
|
311 |
{
|
312 |
id: '',
|
313 |
+
name: t('newConversation'),
|
314 |
dialog_id: dialogId,
|
315 |
message: [
|
316 |
{
|
web/src/pages/flow/canvas/node/begin-node.tsx
CHANGED
@@ -1,13 +1,15 @@
|
|
|
|
1 |
import { Flex } from 'antd';
|
2 |
import classNames from 'classnames';
|
|
|
3 |
import { Handle, NodeProps, Position } from 'reactflow';
|
4 |
import { Operator, operatorMap } from '../../constant';
|
5 |
import { NodeData } from '../../interface';
|
6 |
-
|
7 |
import styles from './index.less';
|
8 |
|
9 |
// TODO: do not allow other nodes to connect to this node
|
10 |
export function BeginNode({ id, data, selected }: NodeProps<NodeData>) {
|
|
|
11 |
return (
|
12 |
<section
|
13 |
className={classNames(styles.ragNode, {
|
@@ -27,7 +29,7 @@ export function BeginNode({ id, data, selected }: NodeProps<NodeData>) {
|
|
27 |
className={styles.handle}
|
28 |
></Handle>
|
29 |
<Flex vertical align="center" justify="center" gap={6}>
|
30 |
-
<span className={styles.type}>{data.label}</span>
|
31 |
</Flex>
|
32 |
<section className={styles.bottomBox}>
|
33 |
<div className={styles.nodeName}>{data.name}</div>
|
|
|
1 |
+
import { useTranslate } from '@/hooks/commonHooks';
|
2 |
import { Flex } from 'antd';
|
3 |
import classNames from 'classnames';
|
4 |
+
import lowerFirst from 'lodash/lowerFirst';
|
5 |
import { Handle, NodeProps, Position } from 'reactflow';
|
6 |
import { Operator, operatorMap } from '../../constant';
|
7 |
import { NodeData } from '../../interface';
|
|
|
8 |
import styles from './index.less';
|
9 |
|
10 |
// TODO: do not allow other nodes to connect to this node
|
11 |
export function BeginNode({ id, data, selected }: NodeProps<NodeData>) {
|
12 |
+
const { t } = useTranslate('flow');
|
13 |
return (
|
14 |
<section
|
15 |
className={classNames(styles.ragNode, {
|
|
|
29 |
className={styles.handle}
|
30 |
></Handle>
|
31 |
<Flex vertical align="center" justify="center" gap={6}>
|
32 |
+
<span className={styles.type}>{t(lowerFirst(data.label))}</span>
|
33 |
</Flex>
|
34 |
<section className={styles.bottomBox}>
|
35 |
<div className={styles.nodeName}>{data.name}</div>
|
web/src/pages/flow/canvas/node/categorize-handle.tsx
CHANGED
@@ -1,6 +1,8 @@
|
|
1 |
import { Handle, Position } from 'reactflow';
|
2 |
// import { v4 as uuid } from 'uuid';
|
3 |
|
|
|
|
|
4 |
import styles from './index.less';
|
5 |
|
6 |
const DEFAULT_HANDLE_STYLE = {
|
@@ -18,6 +20,7 @@ interface IProps {
|
|
18 |
}
|
19 |
|
20 |
const CategorizeHandle = ({ top, right, text, idx }: IProps) => {
|
|
|
21 |
return (
|
22 |
<Handle
|
23 |
type="source"
|
@@ -33,7 +36,9 @@ const CategorizeHandle = ({ top, right, text, idx }: IProps) => {
|
|
33 |
color: 'black',
|
34 |
}}
|
35 |
>
|
36 |
-
<span className={styles.categorizeAnchorPointText}>
|
|
|
|
|
37 |
</Handle>
|
38 |
);
|
39 |
};
|
|
|
1 |
import { Handle, Position } from 'reactflow';
|
2 |
// import { v4 as uuid } from 'uuid';
|
3 |
|
4 |
+
import { useTranslate } from '@/hooks/commonHooks';
|
5 |
+
import lowerFirst from 'lodash/lowerFirst';
|
6 |
import styles from './index.less';
|
7 |
|
8 |
const DEFAULT_HANDLE_STYLE = {
|
|
|
20 |
}
|
21 |
|
22 |
const CategorizeHandle = ({ top, right, text, idx }: IProps) => {
|
23 |
+
const { t } = useTranslate('flow');
|
24 |
return (
|
25 |
<Handle
|
26 |
type="source"
|
|
|
36 |
color: 'black',
|
37 |
}}
|
38 |
>
|
39 |
+
<span className={styles.categorizeAnchorPointText}>
|
40 |
+
{lowerFirst(t(text))}
|
41 |
+
</span>
|
42 |
</Handle>
|
43 |
);
|
44 |
};
|
web/src/pages/flow/canvas/node/categorize-node.tsx
CHANGED
@@ -1,6 +1,8 @@
|
|
|
|
1 |
import { Flex } from 'antd';
|
2 |
import classNames from 'classnames';
|
3 |
import get from 'lodash/get';
|
|
|
4 |
import { Handle, NodeProps, Position } from 'reactflow';
|
5 |
import {
|
6 |
CategorizeAnchorPointPositions,
|
@@ -11,13 +13,12 @@ import { NodeData } from '../../interface';
|
|
11 |
import OperatorIcon from '../../operator-icon';
|
12 |
import CategorizeHandle from './categorize-handle';
|
13 |
import NodeDropdown from './dropdown';
|
14 |
-
|
15 |
import styles from './index.less';
|
16 |
|
17 |
export function CategorizeNode({ id, data, selected }: NodeProps<NodeData>) {
|
18 |
const categoryData = get(data, 'form.category_description') ?? {};
|
19 |
const style = operatorMap[data.label as Operator];
|
20 |
-
|
21 |
return (
|
22 |
<section
|
23 |
className={classNames(styles.ragNode, {
|
@@ -66,7 +67,7 @@ export function CategorizeNode({ id, data, selected }: NodeProps<NodeData>) {
|
|
66 |
name={data.label as Operator}
|
67 |
fontSize={24}
|
68 |
></OperatorIcon>
|
69 |
-
<span className={styles.type}>{data.label}</span>
|
70 |
<NodeDropdown id={id}></NodeDropdown>
|
71 |
</Flex>
|
72 |
<section className={styles.bottomBox}>
|
|
|
1 |
+
import { useTranslate } from '@/hooks/commonHooks';
|
2 |
import { Flex } from 'antd';
|
3 |
import classNames from 'classnames';
|
4 |
import get from 'lodash/get';
|
5 |
+
import lowerFirst from 'lodash/lowerFirst';
|
6 |
import { Handle, NodeProps, Position } from 'reactflow';
|
7 |
import {
|
8 |
CategorizeAnchorPointPositions,
|
|
|
13 |
import OperatorIcon from '../../operator-icon';
|
14 |
import CategorizeHandle from './categorize-handle';
|
15 |
import NodeDropdown from './dropdown';
|
|
|
16 |
import styles from './index.less';
|
17 |
|
18 |
export function CategorizeNode({ id, data, selected }: NodeProps<NodeData>) {
|
19 |
const categoryData = get(data, 'form.category_description') ?? {};
|
20 |
const style = operatorMap[data.label as Operator];
|
21 |
+
const { t } = useTranslate('flow');
|
22 |
return (
|
23 |
<section
|
24 |
className={classNames(styles.ragNode, {
|
|
|
67 |
name={data.label as Operator}
|
68 |
fontSize={24}
|
69 |
></OperatorIcon>
|
70 |
+
<span className={styles.type}>{t(lowerFirst(data.label))}</span>
|
71 |
<NodeDropdown id={id}></NodeDropdown>
|
72 |
</Flex>
|
73 |
<section className={styles.bottomBox}>
|
web/src/pages/flow/canvas/node/index.tsx
CHANGED
@@ -1,5 +1,7 @@
|
|
|
|
1 |
import { Flex } from 'antd';
|
2 |
import classNames from 'classnames';
|
|
|
3 |
import pick from 'lodash/pick';
|
4 |
import { Handle, NodeProps, Position } from 'reactflow';
|
5 |
import { Operator, operatorMap } from '../../constant';
|
@@ -15,7 +17,7 @@ export function RagNode({
|
|
15 |
selected,
|
16 |
}: NodeProps<NodeData>) {
|
17 |
const style = operatorMap[data.label as Operator];
|
18 |
-
|
19 |
return (
|
20 |
<section
|
21 |
className={classNames(styles.ragNode, {
|
@@ -53,7 +55,9 @@ export function RagNode({
|
|
53 |
className={styles.type}
|
54 |
style={{ fontSize: style.fontSize ?? 14 }}
|
55 |
>
|
56 |
-
{data.label === Operator.RewriteQuestion
|
|
|
|
|
57 |
</span>
|
58 |
<NodeDropdown id={id}></NodeDropdown>
|
59 |
</Flex>
|
|
|
1 |
+
import { useTranslate } from '@/hooks/commonHooks';
|
2 |
import { Flex } from 'antd';
|
3 |
import classNames from 'classnames';
|
4 |
+
import lowerFirst from 'lodash/lowerFirst';
|
5 |
import pick from 'lodash/pick';
|
6 |
import { Handle, NodeProps, Position } from 'reactflow';
|
7 |
import { Operator, operatorMap } from '../../constant';
|
|
|
17 |
selected,
|
18 |
}: NodeProps<NodeData>) {
|
19 |
const style = operatorMap[data.label as Operator];
|
20 |
+
const { t } = useTranslate('flow');
|
21 |
return (
|
22 |
<section
|
23 |
className={classNames(styles.ragNode, {
|
|
|
55 |
className={styles.type}
|
56 |
style={{ fontSize: style.fontSize ?? 14 }}
|
57 |
>
|
58 |
+
{data.label === Operator.RewriteQuestion
|
59 |
+
? t(lowerFirst('Rewrite'))
|
60 |
+
: t(lowerFirst(data.label))}
|
61 |
</span>
|
62 |
<NodeDropdown id={id}></NodeDropdown>
|
63 |
</Flex>
|
web/src/pages/flow/canvas/node/relevant-node.tsx
CHANGED
@@ -1,5 +1,7 @@
|
|
|
|
1 |
import { Flex } from 'antd';
|
2 |
import classNames from 'classnames';
|
|
|
3 |
import pick from 'lodash/pick';
|
4 |
import { Handle, NodeProps, Position } from 'reactflow';
|
5 |
import { Operator, operatorMap } from '../../constant';
|
@@ -12,7 +14,7 @@ import styles from './index.less';
|
|
12 |
|
13 |
export function RelevantNode({ id, data, selected }: NodeProps<NodeData>) {
|
14 |
const style = operatorMap[data.label as Operator];
|
15 |
-
|
16 |
return (
|
17 |
<section
|
18 |
className={classNames(styles.ragNode, {
|
@@ -52,7 +54,7 @@ export function RelevantNode({ id, data, selected }: NodeProps<NodeData>) {
|
|
52 |
className={styles.type}
|
53 |
style={{ fontSize: style.fontSize ?? 14 }}
|
54 |
>
|
55 |
-
{data.label}
|
56 |
</span>
|
57 |
<NodeDropdown id={id}></NodeDropdown>
|
58 |
</Flex>
|
|
|
1 |
+
import { useTranslate } from '@/hooks/commonHooks';
|
2 |
import { Flex } from 'antd';
|
3 |
import classNames from 'classnames';
|
4 |
+
import lowerFirst from 'lodash/lowerFirst';
|
5 |
import pick from 'lodash/pick';
|
6 |
import { Handle, NodeProps, Position } from 'reactflow';
|
7 |
import { Operator, operatorMap } from '../../constant';
|
|
|
14 |
|
15 |
export function RelevantNode({ id, data, selected }: NodeProps<NodeData>) {
|
16 |
const style = operatorMap[data.label as Operator];
|
17 |
+
const { t } = useTranslate('flow');
|
18 |
return (
|
19 |
<section
|
20 |
className={classNames(styles.ragNode, {
|
|
|
54 |
className={styles.type}
|
55 |
style={{ fontSize: style.fontSize ?? 14 }}
|
56 |
>
|
57 |
+
{t(lowerFirst(data.label))}
|
58 |
</span>
|
59 |
<NodeDropdown id={id}></NodeDropdown>
|
60 |
</Flex>
|
web/src/pages/flow/flow-sider/index.tsx
CHANGED
@@ -53,7 +53,7 @@ const FlowSide = ({ setCollapsed, collapsed }: IProps) => {
|
|
53 |
<OperatorIcon name={x.name}></OperatorIcon>
|
54 |
<section>
|
55 |
<Tooltip title={t(`${lowerFirst(x.name)}Description`)}>
|
56 |
-
<b>{x.name}</b>
|
57 |
</Tooltip>
|
58 |
</section>
|
59 |
</Flex>
|
|
|
53 |
<OperatorIcon name={x.name}></OperatorIcon>
|
54 |
<section>
|
55 |
<Tooltip title={t(`${lowerFirst(x.name)}Description`)}>
|
56 |
+
<b>{t(lowerFirst(x.name))}</b>
|
57 |
</Tooltip>
|
58 |
</section>
|
59 |
</Flex>
|
web/src/pages/flow/list/index.tsx
CHANGED
@@ -27,7 +27,7 @@ const FlowList = () => {
|
|
27 |
icon={<PlusOutlined />}
|
28 |
onClick={showFlowSettingModal}
|
29 |
>
|
30 |
-
{t('
|
31 |
</Button>
|
32 |
</Flex>
|
33 |
<Spin spinning={loading}>
|
|
|
27 |
icon={<PlusOutlined />}
|
28 |
onClick={showFlowSettingModal}
|
29 |
>
|
30 |
+
{t('createGraph')}
|
31 |
</Button>
|
32 |
</Flex>
|
33 |
<Spin spinning={loading}>
|