feat(web): agent support deep thinking
This commit is contained in:
@@ -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 => (
|
||||
|
||||
Reference in New Issue
Block a user