Skip to content

Commit 029a9f4

Browse files
feat: Configurable output of reason for Intent recognition
1 parent d186bac commit 029a9f4

File tree

7 files changed

+24
-6
lines changed

7 files changed

+24
-6
lines changed

apps/application/flow/step_node/intent_node/i_intent_node.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class IntentNodeSerializer(serializers.Serializer):
2323
model_params_setting = serializers.DictField(required=False,
2424
label=_("Model parameter settings"))
2525
branch = IntentBranchSerializer(many=True)
26+
output_reason = serializers.BooleanField(required=False, label=_("Output reason"), default=True)
2627

2728

2829
class IIntentNode(INode):

apps/application/flow/step_node/intent_node/impl/base_intent_node.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ def save_context(self, details, workflow_manage):
5252
self.context['branch_id'] = details.get('branch_id')
5353
self.context['category'] = details.get('category')
5454

55-
def execute(self, model_id, dialogue_number, history_chat_record, user_input, branch,
55+
def execute(self, model_id, dialogue_number, history_chat_record, user_input, branch, output_reason,
5656
model_params_setting=None, **kwargs) -> NodeResult:
5757

5858
# 设置默认模型参数
@@ -73,7 +73,7 @@ def execute(self, model_id, dialogue_number, history_chat_record, user_input, br
7373
self.context['user_input'] = user_input
7474

7575
# 构建分类提示词
76-
prompt = self.build_classification_prompt(user_input, branch)
76+
prompt = self.build_classification_prompt(user_input, branch, output_reason)
7777

7878
# 生成消息列表
7979
system = self.build_system_prompt()
@@ -129,7 +129,7 @@ def build_system_prompt(self) -> str:
129129
"""构建系统提示词"""
130130
return "你是一个专业的意图识别助手,请根据用户输入和意图选项,准确识别用户的真实意图。"
131131

132-
def build_classification_prompt(self, user_input: str, branch: List[Dict]) -> str:
132+
def build_classification_prompt(self, user_input: str, branch: List[Dict], output_reason: bool) -> str:
133133
"""构建分类提示词"""
134134

135135
classification_list = []
@@ -153,7 +153,8 @@ def build_classification_prompt(self, user_input: str, branch: List[Dict]) -> st
153153

154154
return PROMPT_TEMPLATE.format(
155155
classification_list=classification_list,
156-
user_input=user_input
156+
user_input=user_input,
157+
output_reason=',\n"reason": ""' if output_reason is True else ""
157158
)
158159

159160
def generate_message_list(self, system: str, prompt: str, history_message):

apps/application/flow/step_node/intent_node/impl/prompt_template.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121
- Do not add prefix ```json or suffix ```
2222
- The answer needs to include the following fields such as:
2323
{{
24-
"classificationId": 0,
25-
"reason": ""
24+
"classificationId": 0{output_reason}
2625
}}
2726
2827
## Limit

ui/src/locales/lang/en-US/workflow.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -447,6 +447,7 @@ You are a master of problem optimization, adept at accurately inferring user int
447447
classify: {
448448
label: 'Intent classify',
449449
},
450+
output_reason: 'Output Reason',
450451
input: {
451452
label: 'Input',
452453
},

ui/src/locales/lang/zh-CN/workflow.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ export default {
439439
classify: {
440440
label: '意图分类',
441441
},
442+
output_reason: '输出理由',
442443
input: {
443444
label: '输入',
444445
},

ui/src/locales/lang/zh-Hant/workflow.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,7 @@ export default {
439439
classify: {
440440
label: '意圖分類',
441441
},
442+
output_reason: '輸出理由',
442443
input: {
443444
label: '輸入',
444445
},

ui/src/workflow/nodes/intent-classify-node/index.vue

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,19 @@
138138
</div>
139139
</div>
140140
</el-form-item>
141+
<el-form-item>
142+
<div class="flex-between w-full">
143+
<div>
144+
<span>{{ $t('workflow.nodes.intentNode.output_reason') }}</span>
145+
</div>
146+
<div>
147+
<el-switch
148+
size="small"
149+
v-model="form_data.output_reason"
150+
/>
151+
</div>
152+
</div>
153+
</el-form-item>
141154
</el-form>
142155
</el-card>
143156

@@ -295,6 +308,7 @@ const form = {
295308
],
296309
dialogue_number: 1,
297310
content_list: [],
311+
output_reason: true,
298312
}
299313
300314
function refreshParam(data: any) {

0 commit comments

Comments
 (0)