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 { ModelFeatureEnum } from '@/app/components/header/account-setting/model-provider-page/declarations'
import { useFeatures } from '@/app/components/base/features/hooks'
import type { InputForm } from '@/app/components/base/chat/chat/type'
type ChatItemProps = {
modelAndParameter: ModelAndParameter
@ -60,6 +61,7 @@ const ChatItem: FC<ChatItemProps> = ({
annotation_reply: features.annotationReply,
} as ChatConfig
}, [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 {
chatList,
chatListRef,
@ -71,7 +73,7 @@ const ChatItem: FC<ChatItemProps> = ({
config,
{
inputs,
promptVariables: modelConfig.configs.prompt_variables,
inputsForm,
},
[],
taskId => stopChatMessageResponding(appId, taskId),

View File

@ -13,23 +13,29 @@ import {
import type { DebugWithMultipleModelContextType } from './context'
import { useEventEmitterContextContext } from '@/context/event-emitter'
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 { useFeatures } from '@/app/components/base/features/hooks'
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 { mode } = useDebugConfigurationContext()
const {
mode,
inputs,
modelConfig,
} = useDebugConfigurationContext()
const speech2text = useFeatures(s => s.features.speech2text)
const file = useFeatures(s => s.features.file)
const {
multipleModelConfigs,
checkCanSend,
} = useDebugWithMultipleModelContext()
const { eventEmitter } = useEventEmitterContextContext()
const isChatMode = mode === 'chat' || mode === 'agent-chat'
const handleSend = useCallback((message: string, files?: VisionFile[]) => {
const handleSend = useCallback((message: string, files?: FileEntity[]) => {
if (checkCanSend && !checkCanSend())
return
@ -93,6 +99,7 @@ const DebugWithMultipleModel = () => {
}, [twoLine, threeLine, fourLine])
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 (
<div className='flex flex-col h-full'>
@ -132,6 +139,8 @@ const DebugWithMultipleModel = () => {
onSend={handleSend}
speechToTextConfig={speech2text as any}
visionConfig={file}
inputs={inputs}
inputsForm={inputsForm}
/>
</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 { useFeatures } from '@/app/components/base/features/hooks'
import { getLastAnswer } from '@/app/components/base/chat/utils'
import type { InputForm } from '@/app/components/base/chat/chat/type'
type DebugWithSingleModelProps = {
checkCanSend?: () => boolean
@ -62,6 +63,7 @@ const DebugWithSingleModel = forwardRef<DebugWithSingleModelRefType, DebugWithSi
annotation_reply: features.annotationReply,
} as ChatConfig
}, [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 {
chatList,
chatListRef,
@ -78,7 +80,7 @@ const DebugWithSingleModel = forwardRef<DebugWithSingleModelRefType, DebugWithSi
config,
{
inputs,
promptVariables: modelConfig.configs.prompt_variables,
inputsForm,
},
[],
taskId => stopChatMessageResponding(appId, taskId),
@ -166,6 +168,8 @@ const DebugWithSingleModel = forwardRef<DebugWithSingleModelRefType, DebugWithSi
onFeatureBarClick={setShowAppConfigureFeaturesModal}
suggestedQuestions={suggestedQuestions}
onSend={doSend}
inputs={inputs}
inputsForm={inputsForm}
onRegenerate={doRegenerate}
onStopResponding={handleStop}
showPromptLog

View File

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