mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-14 11:35:56 +08:00
Show tool i18n name on chat pannel (#4724)
This commit is contained in:
parent
88b4d69278
commit
164d6e47b9
@ -1,10 +1,14 @@
|
|||||||
'use client'
|
'use client'
|
||||||
import type { FC } from 'react'
|
import type { FC } from 'react'
|
||||||
import React from 'react'
|
import React from 'react'
|
||||||
|
import { useContext } from 'use-context-selector'
|
||||||
import type { ThoughtItem, ToolInfoInThought } from '../type'
|
import type { ThoughtItem, ToolInfoInThought } from '../type'
|
||||||
import Tool from '@/app/components/app/chat/thought/tool'
|
import Tool from '@/app/components/app/chat/thought/tool'
|
||||||
import type { Emoji } from '@/app/components/tools/types'
|
import type { Emoji } from '@/app/components/tools/types'
|
||||||
|
|
||||||
|
import I18n from '@/context/i18n'
|
||||||
|
import { getLanguage } from '@/i18n/language'
|
||||||
|
|
||||||
export type IThoughtProps = {
|
export type IThoughtProps = {
|
||||||
thought: ThoughtItem
|
thought: ThoughtItem
|
||||||
allToolIcons: Record<string, string | Emoji>
|
allToolIcons: Record<string, string | Emoji>
|
||||||
@ -27,6 +31,9 @@ const Thought: FC<IThoughtProps> = ({
|
|||||||
allToolIcons,
|
allToolIcons,
|
||||||
isFinished,
|
isFinished,
|
||||||
}) => {
|
}) => {
|
||||||
|
const { locale } = useContext(I18n)
|
||||||
|
const language = getLanguage(locale)
|
||||||
|
|
||||||
const [toolNames, isValueArray]: [string[], boolean] = (() => {
|
const [toolNames, isValueArray]: [string[], boolean] = (() => {
|
||||||
try {
|
try {
|
||||||
if (Array.isArray(JSON.parse(thought.tool)))
|
if (Array.isArray(JSON.parse(thought.tool)))
|
||||||
@ -40,6 +47,7 @@ const Thought: FC<IThoughtProps> = ({
|
|||||||
const toolThoughtList = toolNames.map((toolName, index) => {
|
const toolThoughtList = toolNames.map((toolName, index) => {
|
||||||
return {
|
return {
|
||||||
name: toolName,
|
name: toolName,
|
||||||
|
label: thought.tool_labels?.[toolName][language] ?? toolName,
|
||||||
input: getValue(thought.tool_input, isValueArray, index),
|
input: getValue(thought.tool_input, isValueArray, index),
|
||||||
output: getValue(thought.observation, isValueArray, index),
|
output: getValue(thought.observation, isValueArray, index),
|
||||||
isFinished,
|
isFinished,
|
||||||
|
@ -49,8 +49,9 @@ const Tool: FC<Props> = ({
|
|||||||
allToolIcons = {},
|
allToolIcons = {},
|
||||||
}) => {
|
}) => {
|
||||||
const { t } = useTranslation()
|
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 toolName = name.startsWith('dataset_') ? t('dataset.knowledge') : name
|
||||||
|
const toolLabel = name.startsWith('dataset_') ? t('dataset.knowledge') : label
|
||||||
const [isShowDetail, setIsShowDetail] = useState(false)
|
const [isShowDetail, setIsShowDetail] = useState(false)
|
||||||
const icon = getIcon(name, allToolIcons) as any
|
const icon = getIcon(name, allToolIcons) as any
|
||||||
return (
|
return (
|
||||||
@ -74,9 +75,9 @@ const Tool: FC<Props> = ({
|
|||||||
</span>
|
</span>
|
||||||
<span
|
<span
|
||||||
className='text-xs font-medium text-gray-700 truncate'
|
className='text-xs font-medium text-gray-700 truncate'
|
||||||
title={toolName}
|
title={toolLabel}
|
||||||
>
|
>
|
||||||
{toolName}
|
{toolLabel}
|
||||||
</span>
|
</span>
|
||||||
<ChevronDown
|
<ChevronDown
|
||||||
className={cn(isShowDetail && 'rotate-180', 'ml-1 w-3 h-3 text-gray-500 select-none cursor-pointer shrink-0')}
|
className={cn(isShowDetail && 'rotate-180', 'ml-1 w-3 h-3 text-gray-500 select-none cursor-pointer shrink-0')}
|
||||||
|
@ -1,3 +1,4 @@
|
|||||||
|
import type { TypeWithI18N } from '../../header/account-setting/model-provider-page/declarations'
|
||||||
import type { Annotation, MessageRating } from '@/models/log'
|
import type { Annotation, MessageRating } from '@/models/log'
|
||||||
import type { VisionFile } from '@/types/app'
|
import type { VisionFile } from '@/types/app'
|
||||||
|
|
||||||
@ -19,6 +20,7 @@ export type DisplayScene = 'web' | 'console'
|
|||||||
|
|
||||||
export type ToolInfoInThought = {
|
export type ToolInfoInThought = {
|
||||||
name: string
|
name: string
|
||||||
|
label: string
|
||||||
input: string
|
input: string
|
||||||
output: string
|
output: string
|
||||||
isFinished: boolean
|
isFinished: boolean
|
||||||
@ -29,6 +31,7 @@ export type ThoughtItem = {
|
|||||||
tool: string // plugin or dataset. May has multi.
|
tool: string // plugin or dataset. May has multi.
|
||||||
thought: string
|
thought: string
|
||||||
tool_input: string
|
tool_input: string
|
||||||
|
tool_labels?: { [key: string]: TypeWithI18N }
|
||||||
message_id: string
|
message_id: string
|
||||||
observation: string
|
observation: string
|
||||||
position: number
|
position: number
|
||||||
|
Loading…
x
Reference in New Issue
Block a user