debug chat

This commit is contained in:
StyleZhang 2024-09-26 11:54:23 +08:00
parent c89cefe526
commit 296253a365
4 changed files with 21 additions and 6 deletions

View File

@ -28,6 +28,7 @@ import Avatar from '@/app/components/base/avatar'
import { useAppContext } from '@/context/app-context' import { useAppContext } from '@/context/app-context'
import { ModelFeatureEnum } from '@/app/components/header/account-setting/model-provider-page/declarations' import { ModelFeatureEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import { useFeatures } from '@/app/components/base/features/hooks' import { useFeatures } from '@/app/components/base/features/hooks'
import type { InputForm } from '@/app/components/base/chat/chat/type'
type ChatItemProps = { type ChatItemProps = {
modelAndParameter: ModelAndParameter modelAndParameter: ModelAndParameter
@ -60,6 +61,7 @@ const ChatItem: FC<ChatItemProps> = ({
annotation_reply: features.annotationReply, annotation_reply: features.annotationReply,
} as ChatConfig } as ChatConfig
}, [configTemplate, features]) }, [configTemplate, features])
const inputsForm = modelConfig.configs.prompt_variables.filter(item => item.type !== 'api').map(item => ({ ...item, label: item.name, variable: item.key })) as InputForm[]
const { const {
chatList, chatList,
chatListRef, chatListRef,
@ -71,7 +73,7 @@ const ChatItem: FC<ChatItemProps> = ({
config, config,
{ {
inputs, inputs,
promptVariables: modelConfig.configs.prompt_variables, inputsForm,
}, },
[], [],
taskId => stopChatMessageResponding(appId, taskId), taskId => stopChatMessageResponding(appId, taskId),

View File

@ -13,23 +13,29 @@ import {
import type { DebugWithMultipleModelContextType } from './context' import type { DebugWithMultipleModelContextType } from './context'
import { useEventEmitterContextContext } from '@/context/event-emitter' import { useEventEmitterContextContext } from '@/context/event-emitter'
import ChatInputArea from '@/app/components/base/chat/chat/chat-input-area' import ChatInputArea from '@/app/components/base/chat/chat/chat-input-area'
import type { VisionFile } from '@/app/components/base/chat/types'
import { useDebugConfigurationContext } from '@/context/debug-configuration' import { useDebugConfigurationContext } from '@/context/debug-configuration'
import { useFeatures } from '@/app/components/base/features/hooks' import { useFeatures } from '@/app/components/base/features/hooks'
import { useStore as useAppStore } from '@/app/components/app/store' import { useStore as useAppStore } from '@/app/components/app/store'
import type { FileEntity } from '@/app/components/base/file-uploader/types'
import type { InputForm } from '@/app/components/base/chat/chat/type'
const DebugWithMultipleModel = () => { const DebugWithMultipleModel = () => {
const { mode } = useDebugConfigurationContext() const {
mode,
inputs,
modelConfig,
} = useDebugConfigurationContext()
const speech2text = useFeatures(s => s.features.speech2text) const speech2text = useFeatures(s => s.features.speech2text)
const file = useFeatures(s => s.features.file) const file = useFeatures(s => s.features.file)
const { const {
multipleModelConfigs, multipleModelConfigs,
checkCanSend, checkCanSend,
} = useDebugWithMultipleModelContext() } = useDebugWithMultipleModelContext()
const { eventEmitter } = useEventEmitterContextContext() const { eventEmitter } = useEventEmitterContextContext()
const isChatMode = mode === 'chat' || mode === 'agent-chat' const isChatMode = mode === 'chat' || mode === 'agent-chat'
const handleSend = useCallback((message: string, files?: VisionFile[]) => { const handleSend = useCallback((message: string, files?: FileEntity[]) => {
if (checkCanSend && !checkCanSend()) if (checkCanSend && !checkCanSend())
return return
@ -93,6 +99,7 @@ const DebugWithMultipleModel = () => {
}, [twoLine, threeLine, fourLine]) }, [twoLine, threeLine, fourLine])
const setShowAppConfigureFeaturesModal = useAppStore(s => s.setShowAppConfigureFeaturesModal) const setShowAppConfigureFeaturesModal = useAppStore(s => s.setShowAppConfigureFeaturesModal)
const inputsForm = modelConfig.configs.prompt_variables.filter(item => item.type !== 'api').map(item => ({ ...item, label: item.name, variable: item.key })) as InputForm[]
return ( return (
<div className='flex flex-col h-full'> <div className='flex flex-col h-full'>
@ -132,6 +139,8 @@ const DebugWithMultipleModel = () => {
onSend={handleSend} onSend={handleSend}
speechToTextConfig={speech2text as any} speechToTextConfig={speech2text as any}
visionConfig={file} visionConfig={file}
inputs={inputs}
inputsForm={inputsForm}
/> />
</div> </div>
)} )}

View File

@ -25,6 +25,7 @@ import { ModelFeatureEnum } from '@/app/components/header/account-setting/model-
import { useStore as useAppStore } from '@/app/components/app/store' import { useStore as useAppStore } from '@/app/components/app/store'
import { useFeatures } from '@/app/components/base/features/hooks' import { useFeatures } from '@/app/components/base/features/hooks'
import { getLastAnswer } from '@/app/components/base/chat/utils' import { getLastAnswer } from '@/app/components/base/chat/utils'
import type { InputForm } from '@/app/components/base/chat/chat/type'
type DebugWithSingleModelProps = { type DebugWithSingleModelProps = {
checkCanSend?: () => boolean checkCanSend?: () => boolean
@ -62,6 +63,7 @@ const DebugWithSingleModel = forwardRef<DebugWithSingleModelRefType, DebugWithSi
annotation_reply: features.annotationReply, annotation_reply: features.annotationReply,
} as ChatConfig } as ChatConfig
}, [configTemplate, features]) }, [configTemplate, features])
const inputsForm = modelConfig.configs.prompt_variables.filter(item => item.type !== 'api').map(item => ({ ...item, label: item.name, variable: item.key })) as InputForm[]
const { const {
chatList, chatList,
chatListRef, chatListRef,
@ -78,7 +80,7 @@ const DebugWithSingleModel = forwardRef<DebugWithSingleModelRefType, DebugWithSi
config, config,
{ {
inputs, inputs,
promptVariables: modelConfig.configs.prompt_variables, inputsForm,
}, },
[], [],
taskId => stopChatMessageResponding(appId, taskId), taskId => stopChatMessageResponding(appId, taskId),
@ -166,6 +168,8 @@ const DebugWithSingleModel = forwardRef<DebugWithSingleModelRefType, DebugWithSi
onFeatureBarClick={setShowAppConfigureFeaturesModal} onFeatureBarClick={setShowAppConfigureFeaturesModal}
suggestedQuestions={suggestedQuestions} suggestedQuestions={suggestedQuestions}
onSend={doSend} onSend={doSend}
inputs={inputs}
inputsForm={inputsForm}
onRegenerate={doRegenerate} onRegenerate={doRegenerate}
onStopResponding={handleStop} onStopResponding={handleStop}
showPromptLog showPromptLog

View File

@ -296,7 +296,7 @@ export function $splitNodeContainingQuery(match: MenuTextMatch): TextNode | null
} }
export function textToEditorState(text: string) { export function textToEditorState(text: string) {
const paragraph = text ? text.split('\n') : [] const paragraph = text ? text.split('\n') : ['']
return JSON.stringify({ return JSON.stringify({
root: { root: {