feat(web): agent support deep thinking
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-02-03 16:29:21
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-03-27 18:13:51
|
||||
* @Last Modified time: 2026-03-31 16:50:10
|
||||
*/
|
||||
import { useEffect, useRef, useState, forwardRef, useImperativeHandle, useMemo } from 'react';
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@@ -194,7 +194,7 @@ const Agent = forwardRef<AgentRef, { onFeaturesLoad?: (features: FeaturesConfigF
|
||||
* Open model configuration modal
|
||||
*/
|
||||
const handleModelConfig = () => {
|
||||
modelConfigModalRef.current?.handleOpen('model')
|
||||
modelConfigModalRef.current?.handleOpen('model', { ...defaultModel, model_parameters : values?.model_parameters })
|
||||
}
|
||||
/**
|
||||
* Clear all debugging chat sessions
|
||||
@@ -287,7 +287,7 @@ const Agent = forwardRef<AgentRef, { onFeaturesLoad?: (features: FeaturesConfigF
|
||||
setChatList([{
|
||||
label: filterValue?.name || '',
|
||||
model_config_id: filterValue?.id || '',
|
||||
model_parameters: {...(filterValue?.config || {})} as unknown as ModelConfig,
|
||||
model_parameters: {...(values?.model_parameters || {})} as unknown as ModelConfig,
|
||||
list: []
|
||||
}])
|
||||
form.setFieldValue('capability', filterValue?.capability)
|
||||
@@ -361,7 +361,6 @@ const Agent = forwardRef<AgentRef, { onFeaturesLoad?: (features: FeaturesConfigF
|
||||
|
||||
useEffect(() => {
|
||||
const opening_statement = form.getFieldValue(['features', 'opening_statement'])
|
||||
console.log('opening_statement', opening_statement, defaultModel, chatList)
|
||||
|
||||
if (opening_statement?.enabled && opening_statement?.statement && opening_statement?.statement.trim() !== '') {
|
||||
const assistantMsg: ChatItem = {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-03-13 17:27:52
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-03-26 15:35:13
|
||||
* @Last Modified time: 2026-03-31 16:04:15
|
||||
*/
|
||||
import { type FC, useState, useRef, useEffect } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
@@ -171,6 +171,7 @@ const TestChat: FC<TestChatProps> = ({
|
||||
...lastMsg,
|
||||
content: lastMsg.content + content,
|
||||
meta_data: {
|
||||
...(lastMsg.meta_data || {}),
|
||||
audio_url: audio_url || lastMsg.meta_data?.audio_url,
|
||||
audio_status: audio_status || lastMsg.meta_data?.audio_status,
|
||||
citations: citations || lastMsg.meta_data?.citations
|
||||
@@ -180,6 +181,24 @@ const TestChat: FC<TestChatProps> = ({
|
||||
return newList
|
||||
})
|
||||
}
|
||||
const updateAssistantReasoningMessage = (content: string) => {
|
||||
if (!content) return
|
||||
if (streamLoading) setStreamLoading(false)
|
||||
setChatList(prev => {
|
||||
const newList = [...prev]
|
||||
const lastMsg = newList[newList.length - 1]
|
||||
if (lastMsg?.role === 'assistant') {
|
||||
newList[newList.length - 1] = {
|
||||
...lastMsg,
|
||||
meta_data: {
|
||||
...(lastMsg.meta_data || {}),
|
||||
reasoning_content: (lastMsg.meta_data?.reasoning_content || '') + content
|
||||
}
|
||||
}
|
||||
}
|
||||
return newList
|
||||
})
|
||||
}
|
||||
|
||||
const updateErrorAssistantMessage = (message_length: number) => {
|
||||
if (message_length > 0) return
|
||||
@@ -273,6 +292,10 @@ const TestChat: FC<TestChatProps> = ({
|
||||
case 'start':
|
||||
if (conversation_id && conversationId !== conversation_id) setConversationId(conversation_id)
|
||||
break
|
||||
case 'reasoning':
|
||||
updateAssistantReasoningMessage(content)
|
||||
if (conversation_id && conversationId !== conversation_id) setConversationId(conversation_id)
|
||||
break
|
||||
case 'message':
|
||||
updateAssistantMessage(content)
|
||||
if (conversation_id && conversationId !== conversation_id) setConversationId(conversation_id)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-02-03 16:27:39
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-03-27 17:59:07
|
||||
* @Last Modified time: 2026-03-31 15:02:07
|
||||
*/
|
||||
/**
|
||||
* Chat debugging component for application testing
|
||||
@@ -141,6 +141,36 @@ const Chat: FC<ChatProps> = ({
|
||||
}
|
||||
}
|
||||
/** Update assistant message with streaming content */
|
||||
const updateAssistantReasoningMessage = (content?: string, model_config_id?: string, conversation_id?: string) => {
|
||||
if (!content || !model_config_id) return
|
||||
updateChatList(prev => {
|
||||
const targetIndex = prev.findIndex(item => item.model_config_id === model_config_id);
|
||||
if (targetIndex !== -1) {
|
||||
const modelChatList = [...prev]
|
||||
const curModelChat = modelChatList[targetIndex]
|
||||
const curChatMsgList = curModelChat.list || []
|
||||
const lastMsg = curChatMsgList[curChatMsgList.length - 1]
|
||||
if (lastMsg && lastMsg.role === 'assistant') {
|
||||
modelChatList[targetIndex] = {
|
||||
...modelChatList[targetIndex],
|
||||
conversation_id,
|
||||
list: [
|
||||
...curChatMsgList.slice(0, curChatMsgList.length - 1),
|
||||
{
|
||||
...lastMsg,
|
||||
meta_data: {
|
||||
reasoning_content: (lastMsg.meta_data?.reasoning_content || '') + (content || ''),
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
return [...modelChatList]
|
||||
}
|
||||
return prev;
|
||||
})
|
||||
}
|
||||
/** Update assistant message with streaming content */
|
||||
const updateAssistantMessage = (content?: string, model_config_id?: string, conversation_id?: string, audio_url?: string, citations?: any[]) => {
|
||||
if ((!content && !audio_url && (!citations || citations?.length < 1)) || !model_config_id) return
|
||||
updateChatList(prev => {
|
||||
@@ -160,6 +190,7 @@ const Chat: FC<ChatProps> = ({
|
||||
...lastMsg,
|
||||
content: lastMsg.content + (content || ''),
|
||||
meta_data: {
|
||||
...(lastMsg.meta_data || {}),
|
||||
...(audio_url !== undefined ? { audio_url, audio_status: 'pending' } : {}),
|
||||
citations: citations || lastMsg.meta_data?.citations
|
||||
}
|
||||
@@ -274,6 +305,9 @@ const Chat: FC<ChatProps> = ({
|
||||
};
|
||||
|
||||
switch (item.event) {
|
||||
case 'model_reasoning':
|
||||
updateAssistantReasoningMessage(content, model_config_id, conversation_id)
|
||||
break;
|
||||
case 'model_message':
|
||||
updateAssistantMessage(content, model_config_id, conversation_id, audio_url)
|
||||
break;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-02-03 16:28:07
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-03-25 11:28:02
|
||||
* @Last Modified time: 2026-03-31 16:56:57
|
||||
*/
|
||||
/**
|
||||
* Model Configuration Modal
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
|
||||
import { forwardRef, useImperativeHandle, useState, useEffect } from 'react';
|
||||
import { Form, type SelectProps } from 'antd';
|
||||
import { Form, type SelectProps, Checkbox } from 'antd';
|
||||
import { useTranslation } from 'react-i18next';
|
||||
|
||||
import type { ModelConfig, ModelConfigModalRef, Config, Source } from '../types'
|
||||
@@ -70,7 +70,8 @@ const ModelConfigModal = forwardRef<ModelConfigModalRef, ModelConfigModalProps>(
|
||||
if (source === 'model') {
|
||||
form.setFieldsValue({
|
||||
...(data?.model_parameters || {}),
|
||||
default_model_config_id: data.default_model_config_id || ''
|
||||
default_model_config_id: data.default_model_config_id || '',
|
||||
capability: model?.capability || []
|
||||
})
|
||||
} else if (source === 'chat' || source === 'multi_agent') {
|
||||
if (model) {
|
||||
@@ -103,9 +104,12 @@ const ModelConfigModal = forwardRef<ModelConfigModalRef, ModelConfigModalProps>(
|
||||
const handleChange: SelectProps['onChange'] = (_value, option) => {
|
||||
if (source === 'chat') {
|
||||
form.setFieldValue('label', (option as Model).name)
|
||||
} else {
|
||||
form.setFieldValue('capability', (option as Model).capability)
|
||||
}
|
||||
|
||||
form.setFieldsValue({
|
||||
capability: (option as Model).capability,
|
||||
deep_thinking: false,
|
||||
})
|
||||
}
|
||||
|
||||
/** Expose methods to parent component */
|
||||
@@ -115,8 +119,12 @@ const ModelConfigModal = forwardRef<ModelConfigModalRef, ModelConfigModalProps>(
|
||||
}));
|
||||
|
||||
useEffect(() => {
|
||||
form.setFieldsValue({...(data?.model_parameters || {})})
|
||||
const { deep_thinking: _, ...rest } = data?.model_parameters || {}
|
||||
form.setFieldsValue(rest)
|
||||
}, [values?.default_model_config_id])
|
||||
|
||||
|
||||
console.log('handleChange values', values)
|
||||
return (
|
||||
<RbModal
|
||||
title={t('application.modelConfig')}
|
||||
@@ -145,9 +153,17 @@ const ModelConfigModal = forwardRef<ModelConfigModalRef, ModelConfigModalProps>(
|
||||
/>
|
||||
}
|
||||
</FormItem>
|
||||
{source === 'model' && <FormItem name="capability" hidden />}
|
||||
{['model', 'chat'].includes(source) && <>
|
||||
<FormItem name="capability" hidden />
|
||||
{(values?.deep_thinking || values?.capability?.includes('thinking')) && (
|
||||
<FormItem name="deep_thinking" valuePropName="checked">
|
||||
<Checkbox>{t('application.deep_thinking')}</Checkbox>
|
||||
</FormItem>
|
||||
)}
|
||||
</>}
|
||||
{source === 'chat' && <FormItem name="label" hidden />}
|
||||
|
||||
|
||||
<div className="rb:text-[14px] rb:font-medium rb:text-[#5B6167] rb:mb-4">{t('application.parameterConfig')}</div>
|
||||
|
||||
{configFields.map(item => (
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
* @Author: ZhaoYing
|
||||
* @Date: 2026-02-03 16:29:49
|
||||
* @Last Modified by: ZhaoYing
|
||||
* @Last Modified time: 2026-03-24 15:44:33
|
||||
* @Last Modified time: 2026-03-31 15:45:17
|
||||
*/
|
||||
import type { KnowledgeConfig } from './components/Knowledge/types'
|
||||
import type { Variable } from './components/VariableList/types'
|
||||
@@ -36,6 +36,7 @@ export interface ModelConfig {
|
||||
n: number;
|
||||
/** Stop sequences */
|
||||
stop?: string;
|
||||
deep_thinking?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user