feat(web): add question classifier node

This commit is contained in:
zhaoying
2026-01-04 13:51:56 +08:00
parent 351be8aaf3
commit 9dd3fc8d08
6 changed files with 117 additions and 3 deletions

View File

@@ -1553,6 +1553,7 @@ Memory Bear: After the rebellion, regional warlordism intensified for several re
'parameter-extractor': 'Parameter Extraction',
flowControl: 'Flow Control',
'if-else': 'Conditional Branch',
'question-classifier': 'Question Classifier',
iteration: 'Iteration',
loop: 'Loop',
parallel: 'Parallel Execution',
@@ -1664,7 +1665,18 @@ Memory Bear: After the rebellion, regional warlordism intensified for several re
"gt": '>',
"ge": '>=',
else_desc: 'Used to define the logic that should be executed when the if condition is not met.'
}
},
'question-classifier': {
model_id: 'Model',
input_variable: 'Input Variable',
categories: 'Categories',
user_supplement_prompt: 'Instruction',
class_name: 'Category',
addClassName: 'Add Category'
},
name: 'Key',
type: 'Type',
value: 'Value',
},
clear: 'Clear',

View File

@@ -1654,6 +1654,7 @@ export const zh = {
'parameter-extractor': '参数提取',
flowControl: '流程控制',
'if-else': '条件分支',
'question-classifier': '问题分类器',
iteration: '迭代 (Iteration)',
loop: '循环 (Loop)',
parallel: '并行执行',
@@ -1793,6 +1794,14 @@ export const zh = {
template: '代码',
mapping: '输入变量'
},
'question-classifier': {
model_id: '模型',
input_variable: '输入变量',
categories: '分类',
user_supplement_prompt: '指令',
class_name: '分类',
addClassName: '添加分类'
},
name: '键',
type: '类型',
value: '值',

View File

@@ -0,0 +1,64 @@
import { type FC } from 'react';
import { useTranslation } from 'react-i18next';
import { Input, Button, Form, Space } from 'antd';
import { PlusOutlined, CopyOutlined, DeleteOutlined, ExpandOutlined } from '@ant-design/icons';
interface CategoryListProps {
parentName: string;
}
const CategoryList: FC<CategoryListProps> = ({ parentName }) => {
const { t } = useTranslation();
const form = Form.useFormInstance();
const formValues = Form.useWatch([parentName], form);
console.log('formValues', formValues)
return (
<Form.List name={parentName}>
{(fields, { add, remove }) => (
<Space direction="vertical" size={12} className="rb:w-full">
{fields.map(({ key, name, ...restField }, index) => {
const currentItem = formValues?.[key] || {};
const contentLength = (currentItem.class_name || '').length;
return (
<div key={key} className="rb:border rb:border-[#DFE4ED] rb:rounded-md rb:p-3 rb:bg-[#F8F9FB]">
<div className="rb:flex rb:items-center rb:justify-between rb:mb-2">
<div>{t('workflow.config.question-classifier.class_name')} {index + 1}</div>
<div className="rb:flex rb:items-center rb:gap-1">
<span className="rb:text-xs rb:text-gray-500">{contentLength}</span>
<Button
type="text"
size="small"
icon={<DeleteOutlined />}
onClick={() => remove(name)}
/>
</div>
</div>
<Form.Item
{...restField}
name={[name, 'class_name']}
noStyle
>
<Input.TextArea
placeholder={t('common.pleaseEnter')}
rows={2}
/>
</Form.Item>
</div>
)})}
<Button
type="dashed"
onClick={() => add({})}
className="rb:w-full"
>
+ {t('workflow.config.question-classifier.addClassName')}
</Button>
</Space>
)}
</Form.List>
);
};
export default CategoryList;

View File

@@ -17,6 +17,7 @@ import GroupVariableList from './GroupVariableList'
import CaseList from './CaseList'
import HttpRequest from './HttpRequest';
import MappingList from './MappingList'
import CategoryList from './CategoryList'
interface PropertiesProps {
selectedNode?: Node | null;
@@ -472,10 +473,15 @@ const Properties: FC<PropertiesProps> = ({
: config.type === 'variableList'
? <VariableSelect
placeholder={t('common.pleaseSelect')}
options={variableList}
options={variableList.map(vo => ({
...vo,
value: `{{${vo.value}}}`
}))}
/>
: config.type === 'switch'
? <Switch />
: config.type === 'categoryList'
? <CategoryList parentName={key} />
: null
}
</Form.Item>

View File

@@ -37,6 +37,7 @@ import sensitiveDetectionIcon from '@/assets/images/workflow/sensitive_detection
import outputAuditIcon from '@/assets/images/workflow/output_audit.png';
import selfOptimizationIcon from '@/assets/images/workflow/self_optimization.png';
import processEvolutionIcon from '@/assets/images/workflow/process_evolution.png';
import questionClassifierIcon from '@/assets/images/workflow/question-classifier.png'
import { getModelListUrl } from '@/api/models'
import type { NodeLibrary } from './types'
@@ -201,6 +202,28 @@ export const nodeLibrary: NodeLibrary[] = [
}
}
},
{
type: "question-classifier", icon: questionClassifierIcon,
config: {
model_id: {
type: 'customSelect',
url: getModelListUrl,
params: { type: 'llm,chat' }, // llm/chat
valueKey: 'id',
labelKey: 'name',
},
input_variable: {
type: 'variableList',
},
categories: {
type: 'categoryList'
},
user_supplement_prompt: {
type: 'messageEditor',
isArray: false
}
}
},
// { type: "iteration", icon: iterationIcon },
// { type: "loop", icon: loopIcon },
// { type: "parallel", icon: parallelIcon },

View File

@@ -771,7 +771,7 @@ export const useWorkflowGraph = ({
itemConfig = {
...itemConfig,
...data.config[key].defaultValue,
knowledge_bases: knowledge_bases.map((vo: any) => ({ kb_id: vo.id, ...vo.config }))
knowledge_bases: knowledge_bases?.map((vo: any) => ({ kb_id: vo.id, ...vo.config }))
}
}
})