From 164d6e47b9a09b311fdcb753168649b95e54dfcb Mon Sep 17 00:00:00 2001 From: xxhong Date: Tue, 28 May 2024 10:58:02 +0000 Subject: [PATCH] Show tool i18n name on chat pannel (#4724) --- web/app/components/app/chat/thought/index.tsx | 8 ++++++++ web/app/components/app/chat/thought/tool.tsx | 7 ++++--- web/app/components/app/chat/type.ts | 3 +++ 3 files changed, 15 insertions(+), 3 deletions(-) diff --git a/web/app/components/app/chat/thought/index.tsx b/web/app/components/app/chat/thought/index.tsx index 78551424da..462cf87fbc 100644 --- a/web/app/components/app/chat/thought/index.tsx +++ b/web/app/components/app/chat/thought/index.tsx @@ -1,10 +1,14 @@ 'use client' import type { FC } from 'react' import React from 'react' +import { useContext } from 'use-context-selector' import type { ThoughtItem, ToolInfoInThought } from '../type' import Tool from '@/app/components/app/chat/thought/tool' import type { Emoji } from '@/app/components/tools/types' +import I18n from '@/context/i18n' +import { getLanguage } from '@/i18n/language' + export type IThoughtProps = { thought: ThoughtItem allToolIcons: Record @@ -27,6 +31,9 @@ const Thought: FC = ({ allToolIcons, isFinished, }) => { + const { locale } = useContext(I18n) + const language = getLanguage(locale) + const [toolNames, isValueArray]: [string[], boolean] = (() => { try { if (Array.isArray(JSON.parse(thought.tool))) @@ -40,6 +47,7 @@ const Thought: FC = ({ const toolThoughtList = toolNames.map((toolName, index) => { return { name: toolName, + label: thought.tool_labels?.[toolName][language] ?? toolName, input: getValue(thought.tool_input, isValueArray, index), output: getValue(thought.observation, isValueArray, index), isFinished, diff --git a/web/app/components/app/chat/thought/tool.tsx b/web/app/components/app/chat/thought/tool.tsx index 324fcde7bc..9142357828 100644 --- a/web/app/components/app/chat/thought/tool.tsx +++ b/web/app/components/app/chat/thought/tool.tsx @@ -49,8 +49,9 @@ const Tool: FC = ({ allToolIcons = {}, }) => { const { t } = useTranslation() - const { name, input, isFinished, output } = payload + const { name, label, input, isFinished, output } = payload const toolName = name.startsWith('dataset_') ? t('dataset.knowledge') : name + const toolLabel = name.startsWith('dataset_') ? t('dataset.knowledge') : label const [isShowDetail, setIsShowDetail] = useState(false) const icon = getIcon(name, allToolIcons) as any return ( @@ -74,9 +75,9 @@ const Tool: FC = ({ - {toolName} + {toolLabel}