Skip to content

Commit e9cc82b

Browse files
committed
修改问题分类组件
1 parent c7b4081 commit e9cc82b

File tree

9 files changed

+216
-16
lines changed

9 files changed

+216
-16
lines changed
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
import PropTypes from 'prop-types';
8+
import React from 'react';
9+
import {Collapse, Popover} from 'antd';
10+
import {useDispatch, useShapeContext} from '@/components/DefaultRoot.jsx';
11+
import {Trans, useTranslation} from 'react-i18next';
12+
import {QuestionCircleOutlined} from '@ant-design/icons';
13+
import TextArea from 'antd/es/input/TextArea.js';
14+
import {JadeCollapse} from '@/components/common/JadeCollapse.jsx';
15+
16+
const {Panel} = Collapse;
17+
18+
/**
19+
* 问题分类高级设置组件 - 用于显示高级设置的显示用户指令
20+
*
21+
* @param disabled 是否禁用
22+
* @param description 提示词描述
23+
* @param promptPopover 提示词气泡提示的国际化key
24+
* @param promptTitle 提示词标题的国际化key
25+
* @return {JSX.Element} 高级设置组件
26+
* @private
27+
*/
28+
const _QuestionClassificationAdvancedSettings = ({
29+
disabled,
30+
description,
31+
promptPopover,
32+
promptTitle,
33+
}) => {
34+
const shape = useShapeContext();
35+
const shapeId = shape.id;
36+
const {t} = useTranslation();
37+
const dispatch = useDispatch();
38+
39+
/**
40+
* 获取提示词的提示信息
41+
*
42+
* @return {JSX.Element} 国际化后的提示信息
43+
*/
44+
const getPromptContent = () => {
45+
return (<div className={'jade-font-size'} style={{lineHeight: '1.2'}}>
46+
<Trans i18nKey={promptPopover} components={{p: <p/>}}/>
47+
</div>);
48+
};
49+
50+
/**
51+
* 失焦时才设置值,对于必填项.若为空,则不设置
52+
*
53+
* @param e event
54+
* @param actionType 事件类型
55+
* @param id config的id
56+
*/
57+
const onChange = (e, actionType, id) => {
58+
dispatch({actionType: actionType, id: id, value: e.target.value});
59+
};
60+
61+
return (<>
62+
<JadeCollapse defaultActiveKey={[]}>
63+
{<Panel
64+
key={`questionClassificationAdvancedSettingsPanel${shapeId}`}
65+
header={<div className='panel-header'>
66+
<span className='jade-panel-header-font'>{t('advancedSettings')}</span>
67+
</div>}
68+
className='jade-panel'
69+
>
70+
<div className={'jade-custom-panel-content'}>
71+
<span>
72+
<span className='jade-panel-header-font'>{t(promptTitle)}</span>
73+
</span>
74+
<Popover
75+
content={getPromptContent()}
76+
align={{offset: [0, 3]}}
77+
overlayClassName={'jade-custom-popover'}
78+
>
79+
<QuestionCircleOutlined className='jade-panel-header-popover-content'/>
80+
</Popover>
81+
<TextArea
82+
value={description.value}
83+
disabled={disabled}
84+
maxLength={10000}
85+
className='jade-textarea-input jade-font-size'
86+
onChange={(e) => onChange(e, 'changePromptValue', description.id)}
87+
/>
88+
</div>
89+
</Panel>}
90+
</JadeCollapse>
91+
</>);
92+
};
93+
94+
_QuestionClassificationAdvancedSettings.propTypes = {
95+
disabled: PropTypes.bool,
96+
description: PropTypes.object.isRequired,
97+
promptPopover: PropTypes.string.isRequired,
98+
promptTitle: PropTypes.string.isRequired,
99+
};
100+
101+
const areEqual = (prevProps, nextProps) => {
102+
return prevProps.disabled === nextProps.disabled &&
103+
prevProps.description === nextProps.description &&
104+
prevProps.promptPopover === nextProps.promptPopover &&
105+
prevProps.promptTitle === nextProps.promptTitle;
106+
};
107+
108+
export const QuestionClassificationAdvancedSettings = React.memo(_QuestionClassificationAdvancedSettings, areEqual);
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
/*---------------------------------------------------------------------------------------------
2+
* Copyright (c) 2025 Huawei Technologies Co., Ltd. All rights reserved.
3+
* This file is a part of the ModelEngine Project.
4+
* Licensed under the MIT License. See License.txt in the project root for license information.
5+
*--------------------------------------------------------------------------------------------*/
6+
7+
import PropTypes from 'prop-types';
8+
import React from 'react';
9+
import {Collapse} from 'antd';
10+
import {Model} from '@/components/llm/Model.jsx';
11+
import {useShapeContext} from '@/components/DefaultRoot.jsx';
12+
import {useTranslation} from 'react-i18next';
13+
import {JadeCollapse} from '@/components/common/JadeCollapse.jsx';
14+
15+
const {Panel} = Collapse;
16+
17+
/**
18+
* 问题分类模型配置组件 - 只包含模型配置,不包含提示词模板
19+
*
20+
* @param disabled 是否禁用
21+
* @param modelOptions 模板选项
22+
* @param temperature 温度对象
23+
* @param serviceName 模型对象
24+
* @param tag 模型对象标签
25+
* @return {JSX.Element} 模型配置组件
26+
* @private
27+
*/
28+
const _QuestionClassificationModelConfig = ({
29+
disabled,
30+
modelOptions,
31+
temperature,
32+
serviceName,
33+
tag,
34+
}) => {
35+
const shape = useShapeContext();
36+
const shapeId = shape.id;
37+
const {t} = useTranslation();
38+
39+
return (<>
40+
<JadeCollapse defaultActiveKey={[`questionClassificationModelPanel${shapeId}`]}>
41+
{<Panel
42+
key={`questionClassificationModelPanel${shapeId}`}
43+
header={<div className='panel-header'>
44+
<span className='jade-panel-header-font'>{t('llm')}</span>
45+
</div>}
46+
className='jade-panel'
47+
>
48+
<div className={'jade-custom-panel-content'}>
49+
<Model
50+
disabled={disabled} shapeId={shapeId} modelOptions={modelOptions} temperature={temperature}
51+
serviceName={serviceName} tag={tag}/>
52+
</div>
53+
</Panel>}
54+
</JadeCollapse>
55+
</>);
56+
};
57+
58+
_QuestionClassificationModelConfig.propTypes = {
59+
disabled: PropTypes.bool,
60+
modelOptions: PropTypes.array.isRequired,
61+
temperature: PropTypes.object.isRequired,
62+
serviceName: PropTypes.object.isRequired,
63+
tag: PropTypes.object.isRequired,
64+
};
65+
66+
const areEqual = (prevProps, nextProps) => {
67+
return prevProps.disabled === nextProps.disabled &&
68+
prevProps.modelOptions === nextProps.modelOptions &&
69+
prevProps.temperature === nextProps.temperature &&
70+
prevProps.serviceName === nextProps.serviceName &&
71+
prevProps.tag === nextProps.tag;
72+
};
73+
74+
export const QuestionClassificationModelConfig = React.memo(_QuestionClassificationModelConfig, areEqual);

agent-flow/src/components/questionClassification/QuestionClassificationWrapper.jsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,9 @@ import {getConfigValue} from '@/components/util/JadeConfigUtils.js';
1313
import httpUtil from '@/components/util/httpUtil.jsx';
1414
import {HistoryConfig} from '@/components/textExtraction/HistoryConfig.jsx';
1515
import {JadeInputForm} from '@/components/common/JadeInputForm.jsx';
16-
import {ModelConfig} from '@/components/common/ModelConfig.jsx';
1716
import {QuestionClassificationPanel} from '@/components/questionClassification/QuestionClassificationPanel.jsx';
17+
import {QuestionClassificationModelConfig} from '@/components/questionClassification/QuestionClassificationModelConfig.jsx';
18+
import {QuestionClassificationAdvancedSettings} from '@/components/questionClassification/QuestionClassificationAdvancedSettings.jsx';
1819

1920
const EMPTY_STRING = '';
2021

@@ -120,16 +121,23 @@ const _QuestionClassificationWrapper = ({data, shapeStatus}) => {
120121
deleteItem={deleteItem}
121122
content={inputDescription}
122123
maxInputLength={1000}/>
123-
<ModelConfig
124-
modelOptions={modelOptions} temperature={temperature} serviceName={serviceName} tag={tag}
125-
description={template} disabled={shapeStatus.disabled} promptTitle={'userPromptTemplate'}
126-
promptPopover={'questionClassificationPromptPopover'}/>
124+
<QuestionClassificationModelConfig
125+
modelOptions={modelOptions}
126+
temperature={temperature}
127+
serviceName={serviceName}
128+
tag={tag}
129+
disabled={shapeStatus.disabled}/>
130+
<QuestionClassificationPanel disabled={shapeStatus.disabled} questionTypeList={questionTypeList}/>
127131
<HistoryConfig
128132
disabled={shapeStatus.disabled}
129133
dispatch={dispatch}
130134
memoryConfig={memoryConfig}
131135
memorySwitch={memorySwitch}/>
132-
<QuestionClassificationPanel disabled={shapeStatus.disabled} questionTypeList={questionTypeList}/>
136+
<QuestionClassificationAdvancedSettings
137+
description={template}
138+
disabled={shapeStatus.disabled}
139+
promptTitle={'additionalInstruction'}
140+
promptPopover={'questionClassificationPromptPopover'}/>
133141
</>);
134142
};
135143

agent-flow/src/components/questionClassification/style.css

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@
5454
height: 21px !important;
5555
display: inline-block;
5656
align-items: center;
57-
margin-top: 16px;
58-
margin-bottom: 12px;
57+
margin-top: 0;
58+
margin-bottom: 20px;
5959
padding: 0 12px 0 12px;
6060
}
6161

agent-flow/src/i18n/en_US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@
364364
"classificationPopover": "待翻译",
365365
"otherQuestionClassification": "待翻译",
366366
"questionClassificationReportPrefix": "待翻译",
367-
"questionClassificationPromptPopover": "待翻译",
367+
"additionalInstruction": "Additional Instruction",
368+
"questionClassificationPromptPopover": "<p>Additional instructions for the problem classification model</p>\n<p>These instructions can help the model perform classification tasks better.</p>",
369+
"advancedSettings": "Advanced Settings",
368370
"skill": "待翻译",
369371
"requestConfig": "待翻译",
370372
"authentication": "待翻译",

agent-flow/src/i18n/zh_CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,7 +620,9 @@
620620
"addQuestionClassification": "添加问题分类",
621621
"otherQuestionClassification": "其他问题分类",
622622
"questionClassificationReportPrefix": "问题归类为",
623-
"questionClassificationPromptPopover": "<p>可以添加一些特定内容的介绍,从而更好的识别用户的</p>\n<p>问题类型。这个内容通常是给模型介绍一个它不知道的</p>\n<p>内容。可以使用{{变量名}}从输入参数中引入变量。</p>",
623+
"additionalInstruction": "额外指令",
624+
"questionClassificationPromptPopover": "<p>问题分类模型的额外指令</p>\n<p>可以帮助模型更好的执行分类任务。</p>",
625+
"advancedSettings": "高级设置",
624626
"httpInputPopover": "输入可被请求param或者body引用的变量",
625627
"requestConfig": "请求配置",
626628
"authentication": "鉴权",

app-builder/plugins/aipp-classify-question/src/main/java/modelengine/fit/jade/aipp/classify/question/command/impl/ClassifyQuestionCommandHandlerImpl.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,8 @@ public class ClassifyQuestionCommandHandlerImpl implements ClassifyQuestionComma
4848
private final String builtinPrompt;
4949
private final ChatModel modelService;
5050

51-
private static final String TYPE_REGEX = "[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
51+
private static final String TYPE_REGEX =
52+
"[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}";
5253

5354
/**
5455
* 创建 {@link ClassifyQuestionCommandHandlerImpl} 的实例。
@@ -74,8 +75,8 @@ public String handle(ClassifyQuestionCommand command) {
7475
HashMap<String, String> variables = new HashMap<>(args);
7576
variables.put(Constant.HISTORY_KEY, memory.text());
7677
variables.put(Constant.TYPE_LIST_KEY, command.getTypeList());
77-
ModelAccessInfo modelAccessInfo = this.aippModelCenter.getModelAccessInfo(command.getModelTag(),
78-
command.getModel(), null);
78+
ModelAccessInfo modelAccessInfo =
79+
this.aippModelCenter.getModelAccessInfo(command.getModelTag(), command.getModel(), null);
7980
ChatOption chatOption = ChatOption.custom()
8081
.model(command.getModel())
8182
.baseUrl(modelAccessInfo.getBaseUrl())
@@ -102,6 +103,7 @@ public String handle(ClassifyQuestionCommand command) {
102103
}
103104

104105
private String getTemplate(ClassifyQuestionCommand command) {
105-
return StringUtils.isNotBlank(command.getTemplate()) ? command.getTemplate() : this.builtinPrompt;
106+
return StringUtils.isNotBlank(command.getTemplate()) ? this.builtinPrompt + "\n\n## 辅助描述\n\n"
107+
+ command.getTemplate() : this.builtinPrompt;
106108
}
107109
}

frontend/src/locale/en_US.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -429,7 +429,9 @@
429429
"addQuestionClassification": "Add question category",
430430
"otherQuestionClassification": "Other problem categories",
431431
"questionClassificationReportPrefix": "Problems are categorized as",
432-
"questionClassificationPromptPopover": "You can add some specific content to better identify the user's question type. This content usually introduces something that the model does not know. You can use {{variable name}} to introduce variables from the input parameters.",
432+
"additionalInstruction": "Additional Instruction",
433+
"questionClassificationPromptPopover": "<p>Additional instructions for the problem classification model</p>\n<p>These instructions can help the model perform classification tasks better.</p>",
434+
"advancedSettings": "Advanced Settings",
433435
"skill": "Skill",
434436
"generate": "Generate",
435437
"confirmUse": "Apply",

frontend/src/locale/zh_CN.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -677,7 +677,9 @@
677677
"addQuestionClassification": "添加问题分类",
678678
"otherQuestionClassification": "其他问题分类",
679679
"questionClassificationReportPrefix": "问题归类为",
680-
"questionClassificationPromptPopover": "<p>可以添加一些特定内容的介绍,从而更好的识别用户的</p>\n<p>问题类型。这个内容通常是给模型介绍一个它不知道的</p>\n<p>内容。可以使用{{变量名}}从输入参数中引入变量。</p>",
680+
"additionalInstruction": "额外指令",
681+
"questionClassificationPromptPopover": "<p>问题分类模型的额外指令</p>\n<p>可以帮助模型更好的执行分类任务。</p>",
682+
"advancedSettings": "高级设置",
681683
"skill": "技能",
682684
"iconHttp": "图标",
683685
"generate": "生成",

0 commit comments

Comments
 (0)