Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

Show tool i18n name on chat pannel (#4724)

xxhong164d6e47b9a0
diff --git a/web/app/components/app/chat/thought/index.tsx b/web/app/components/app/chat/thought/index.tsx
index 78551424da3..462cf87fbc2 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<string, string | Emoji>
@@ -27,6 +31,9 @@ const Thought: FC<IThoughtProps> = ({
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<IThoughtProps> = ({
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 324fcde7bca..91423578288 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<Props> = ({
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<Props> = ({
</span>
<span
className='text-xs font-medium text-gray-700 truncate'
- title={toolName}
+ title={toolLabel}
>
- {toolName}
+ {toolLabel}
</span>
<ChevronDown
className={cn(isShowDetail && 'rotate-180', 'ml-1 w-3 h-3 text-gray-500 select-none cursor-pointer shrink-0')}
diff --git a/web/app/components/app/chat/type.ts b/web/app/components/app/chat/type.ts
index 9c96e36e8c0..0deae18cd97 100644
--- a/web/app/components/app/chat/type.ts
+++ b/web/app/components/app/chat/type.ts
@@ -1,3 +1,4 @@
+import type { TypeWithI18N } from '../../header/account-setting/model-provider-page/declarations'
import type { Annotation, MessageRating } from '@/models/log'
import type { VisionFile } from '@/types/app'
@@ -19,6 +20,7 @@ export type DisplayScene = 'web' | 'console'
export type ToolInfoInThought = {
name: string
+ label: string
input: string
output: string
isFinished: boolean
@@ -29,6 +31,7 @@ export type ThoughtItem = {
tool: string // plugin or dataset. May has multi.
thought: string
tool_input: string
+ tool_labels?: { [key: string]: TypeWithI18N }
message_id: string
observation: string
position: number