Browse Source

agent tool in chat

tags/0.10.0-beta1^2
StyleZhang 1 year ago
parent
commit
0da06128e3

+ 0
- 4
web/app/components/base/chat/chat/answer/agent-content.tsx View File

import { Markdown } from '@/app/components/base/markdown' import { Markdown } from '@/app/components/base/markdown'
import Thought from '@/app/components/base/chat/chat/thought' import Thought from '@/app/components/base/chat/chat/thought'
import ImageGallery from '@/app/components/base/image-gallery' import ImageGallery from '@/app/components/base/image-gallery'
import type { Emoji } from '@/app/components/tools/types'


type AgentContentProps = { type AgentContentProps = {
item: ChatItem item: ChatItem
responding?: boolean responding?: boolean
allToolIcons?: Record<string, string | Emoji>
} }
const AgentContent: FC<AgentContentProps> = ({ const AgentContent: FC<AgentContentProps> = ({
item, item,
responding, responding,
allToolIcons,
}) => { }) => {
const { const {
annotation, annotation,
{!!thought.tool && ( {!!thought.tool && (
<Thought <Thought
thought={thought} thought={thought}
allToolIcons={allToolIcons || {}}
isFinished={!!thought.observation || !responding} isFinished={!!thought.observation || !responding}
/> />
)} )}

+ 0
- 4
web/app/components/base/chat/chat/answer/index.tsx View File

import LoadingAnim from '@/app/components/base/chat/chat/loading-anim' import LoadingAnim from '@/app/components/base/chat/chat/loading-anim'
import Citation from '@/app/components/base/chat/chat/citation' import Citation from '@/app/components/base/chat/chat/citation'
import { EditTitle } from '@/app/components/app/annotation/edit-annotation-modal/edit-item' import { EditTitle } from '@/app/components/app/annotation/edit-annotation-modal/edit-item'
import type { Emoji } from '@/app/components/tools/types'
import type { AppData } from '@/models/share' import type { AppData } from '@/models/share'
import cn from '@/utils/classnames' import cn from '@/utils/classnames'


config?: ChatConfig config?: ChatConfig
answerIcon?: ReactNode answerIcon?: ReactNode
responding?: boolean responding?: boolean
allToolIcons?: Record<string, string | Emoji>
showPromptLog?: boolean showPromptLog?: boolean
chatAnswerContainerInner?: string chatAnswerContainerInner?: string
hideProcessDetail?: boolean hideProcessDetail?: boolean
config, config,
answerIcon, answerIcon,
responding, responding,
allToolIcons,
showPromptLog, showPromptLog,
chatAnswerContainerInner, chatAnswerContainerInner,
hideProcessDetail, hideProcessDetail,
<AgentContent <AgentContent
item={item} item={item}
responding={responding} responding={responding}
allToolIcons={allToolIcons}
/> />
) )
} }

+ 71
- 0
web/app/components/base/chat/chat/answer/tool-detail.tsx View File

import { useState } from 'react'
import { useTranslation } from 'react-i18next'
import {
RiArrowDownSLine,
RiArrowRightSLine,
RiHammerFill,
RiLoader2Line,
} from '@remixicon/react'
import type { ToolInfoInThought } from '../type'
import cn from '@/utils/classnames'

type ToolDetailProps = {
payload: ToolInfoInThought
}
const ToolDetail = ({
payload,
}: ToolDetailProps) => {
const { t } = useTranslation()
const { name, label, input, isFinished, output } = payload
const toolLabel = name.startsWith('dataset_') ? t('dataset.knowledge') : label
const [expand, setExpand] = useState(false)

return (
<div
className={cn(
'rounded-xl',
!expand && 'border-l-[0.25px] border-components-panel-border bg-workflow-process-bg',
expand && 'border-[0.5px] border-components-panel-border-subtle bg-background-section-burn',
)}
>
<div
className={cn(
'flex items-center system-xs-medium text-text-tertiary px-2.5 py-2 cursor-pointer',
expand && 'pb-1.5',
)}
onClick={() => setExpand(!expand)}
>
{isFinished && <RiHammerFill className='mr-1 w-3.5 h-3.5' />}
{!isFinished && <RiLoader2Line className='mr-1 w-3.5 h-3.5 animate-spin' />}
{t(`tools.thought.${isFinished ? 'used' : 'using'}`)}
<div className='mx-1 text-text-secondary'>{toolLabel}</div>
{!expand && <RiArrowRightSLine className='w-4 h-4' />}
{expand && <RiArrowDownSLine className='ml-auto w-4 h-4' />}
</div>
{
expand && (
<>
<div className='mb-0.5 mx-1 rounded-[10px] bg-components-panel-on-panel-item-bg text-text-secondary'>
<div className='flex items-center justify-between px-2 pt-1 h-7 system-xs-semibold-uppercase'>
{t('tools.thought.requestTitle')}
</div>
<div className='pt-1 px-3 pb-2 code-xs-regular'>
{input}
</div>
</div>
<div className='mx-1 mb-1 rounded-[10px] bg-components-panel-on-panel-item-bg text-text-secondary'>
<div className='flex items-center justify-between px-2 pt-1 h-7 system-xs-semibold-uppercase'>
{t('tools.thought.responseTitle')}
</div>
<div className='pt-1 px-3 pb-2 code-xs-regular'>
{output}
</div>
</div>
</>
)
}
</div>
)
}

export default ToolDetail

+ 0
- 3
web/app/components/base/chat/chat/context.tsx View File

| 'showPromptLog' | 'showPromptLog'
| 'questionIcon' | 'questionIcon'
| 'answerIcon' | 'answerIcon'
| 'allToolIcons'
| 'onSend' | 'onSend'
| 'onAnnotationEdited' | 'onAnnotationEdited'
| 'onAnnotationAdded' | 'onAnnotationAdded'
showPromptLog, showPromptLog,
questionIcon, questionIcon,
answerIcon, answerIcon,
allToolIcons,
onSend, onSend,
onAnnotationEdited, onAnnotationEdited,
onAnnotationAdded, onAnnotationAdded,
showPromptLog, showPromptLog,
questionIcon, questionIcon,
answerIcon, answerIcon,
allToolIcons,
onSend, onSend,
onAnnotationEdited, onAnnotationEdited,
onAnnotationAdded, onAnnotationAdded,

+ 0
- 3
web/app/components/base/chat/chat/index.tsx View File

showPromptLog, showPromptLog,
questionIcon, questionIcon,
answerIcon, answerIcon,
allToolIcons,
onAnnotationAdded, onAnnotationAdded,
onAnnotationEdited, onAnnotationEdited,
onAnnotationRemoved, onAnnotationRemoved,
showPromptLog={showPromptLog} showPromptLog={showPromptLog}
questionIcon={questionIcon} questionIcon={questionIcon}
answerIcon={answerIcon} answerIcon={answerIcon}
allToolIcons={allToolIcons}
onSend={onSend} onSend={onSend}
onAnnotationAdded={onAnnotationAdded} onAnnotationAdded={onAnnotationAdded}
onAnnotationEdited={onAnnotationEdited} onAnnotationEdited={onAnnotationEdited}
config={config} config={config}
answerIcon={answerIcon} answerIcon={answerIcon}
responding={isLast && isResponding} responding={isLast && isResponding}
allToolIcons={allToolIcons}
showPromptLog={showPromptLog} showPromptLog={showPromptLog}
chatAnswerContainerInner={chatAnswerContainerInner} chatAnswerContainerInner={chatAnswerContainerInner}
hideProcessDetail={hideProcessDetail} hideProcessDetail={hideProcessDetail}

+ 2
- 6
web/app/components/base/chat/chat/thought/index.tsx View File

import type { FC } from 'react' import type { FC } from 'react'
import React from 'react' import React from 'react'
import type { ThoughtItem, ToolInfoInThought } from '../type' import type { ThoughtItem, ToolInfoInThought } from '../type'
import Tool from '@/app/components/base/chat/chat/thought/tool'
import type { Emoji } from '@/app/components/tools/types'
import ToolDetail from '@/app/components/base/chat/chat/answer/tool-detail'


export type IThoughtProps = { export type IThoughtProps = {
thought: ThoughtItem thought: ThoughtItem
allToolIcons: Record<string, string | Emoji>
isFinished: boolean isFinished: boolean
} }




const Thought: FC<IThoughtProps> = ({ const Thought: FC<IThoughtProps> = ({
thought, thought,
allToolIcons,
isFinished, isFinished,
}) => { }) => {
const [toolNames, isValueArray]: [string[], boolean] = (() => { const [toolNames, isValueArray]: [string[], boolean] = (() => {
return ( return (
<div className='my-2 space-y-2'> <div className='my-2 space-y-2'>
{toolThoughtList.map((item: ToolInfoInThought, index) => ( {toolThoughtList.map((item: ToolInfoInThought, index) => (
<Tool
<ToolDetail
key={index} key={index}
payload={item} payload={item}
allToolIcons={allToolIcons}
/> />
))} ))}
</div> </div>

+ 2
- 2
web/i18n/en-US/tools.ts View File

thought: { thought: {
using: 'Using', using: 'Using',
used: 'Used', used: 'Used',
requestTitle: 'Request to',
responseTitle: 'Response from',
requestTitle: 'Request',
responseTitle: 'Response',
}, },
setBuiltInTools: { setBuiltInTools: {
info: 'Info', info: 'Info',

+ 2
- 2
web/i18n/zh-Hans/tools.ts View File

thought: { thought: {
using: '正在使用', using: '正在使用',
used: '已使用', used: '已使用',
requestTitle: '请求来自',
responseTitle: '响应来自',
requestTitle: '请求',
responseTitle: '响应',
}, },
setBuiltInTools: { setBuiltInTools: {
info: '信息', info: '信息',

+ 1
- 0
web/tailwind.config.js View File

backgroundImage: { backgroundImage: {
'chatbot-bg': 'var(--color-chatbot-bg)', 'chatbot-bg': 'var(--color-chatbot-bg)',
'chat-bubble-bg': 'var(--color-chat-bubble-bg)', 'chat-bubble-bg': 'var(--color-chat-bubble-bg)',
'workflow-process-bg': 'var(--color-workflow-process-bg)',
}, },
}, },
}, },

+ 1
- 0
web/themes/dark.css View File

--color-chatbot-bg: linear-gradient(180deg, rgba(34, 34, 37, 0.90) 0%, rgba(29, 29, 32, 0.90) 90.48%); --color-chatbot-bg: linear-gradient(180deg, rgba(34, 34, 37, 0.90) 0%, rgba(29, 29, 32, 0.90) 90.48%);
--color-chat-bubble-bg: linear-gradient(180deg, rgba(200, 206, 218, 0.08) 0%, rgba(200, 206, 218, 0.02) 100%); --color-chat-bubble-bg: linear-gradient(180deg, rgba(200, 206, 218, 0.08) 0%, rgba(200, 206, 218, 0.02) 100%);
--color-third-party-Github: #FFFFFF; --color-third-party-Github: #FFFFFF;
--color-workflow-process-bg: linear-gradient(90deg, rgba(24, 24, 27, 0.25) 0%, rgba(24, 24, 27, 0.04) 100%);
} }

+ 1
- 0
web/themes/light.css View File

--color-chatbot-bg: linear-gradient(180deg, rgba(249, 250, 251, 0.90) 0%, rgba(242, 244, 247, 0.90) 90.48%); --color-chatbot-bg: linear-gradient(180deg, rgba(249, 250, 251, 0.90) 0%, rgba(242, 244, 247, 0.90) 90.48%);
--color-chat-bubble-bg: linear-gradient(180deg, #FFF 0%, rgba(255, 255, 255, 0.60) 100%); --color-chat-bubble-bg: linear-gradient(180deg, #FFF 0%, rgba(255, 255, 255, 0.60) 100%);
--color-third-party-Github: #1B1F24; --color-third-party-Github: #1B1F24;
--color-workflow-process-bg: linear-gradient(90deg, rgba(200, 206, 218, 0.20) 0%, rgba(200, 206, 218, 0.04) 100%);
} }

Loading…
Cancel
Save