Skip to content

armgit / dify

Public Imported from GitHub
0

Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.

feat: support question classifier node output (#4000)

sinoda5a8b9a5933
diff --git a/api/core/workflow/nodes/question_classifier/question_classifier_node.py b/api/core/workflow/nodes/question_classifier/question_classifier_node.py
index c8f458de87c..9ec0df721c1 100644
--- a/api/core/workflow/nodes/question_classifier/question_classifier_node.py
+++ b/api/core/workflow/nodes/question_classifier/question_classifier_node.py
@@ -79,7 +79,6 @@ class QuestionClassifierNode(LLMNode):
prompt_messages=prompt_messages
),
'usage': jsonable_encoder(usage),
- 'topics': categories[0] if categories else ''
}
outputs = {
'class_name': categories[0] if categories else ''
diff --git a/web/app/components/workflow/constants.ts b/web/app/components/workflow/constants.ts
index e9818ea19ca..2b163008ad9 100644
--- a/web/app/components/workflow/constants.ts
+++ b/web/app/components/workflow/constants.ts
@@ -259,67 +259,9 @@ export const RETRIEVAL_OUTPUT_STRUCT = `{
export const SUPPORT_OUTPUT_VARS_NODE = [
BlockEnum.Start, BlockEnum.LLM, BlockEnum.KnowledgeRetrieval, BlockEnum.Code, BlockEnum.TemplateTransform,
- BlockEnum.HttpRequest, BlockEnum.Tool, BlockEnum.VariableAssigner,
+ BlockEnum.HttpRequest, BlockEnum.Tool, BlockEnum.VariableAssigner, BlockEnum.QuestionClassifier,
]
-const USAGE = {
- variable: 'usage',
- type: VarType.object,
- children: [
- {
- variable: 'prompt_tokens',
- type: VarType.number,
- },
- {
- variable: 'prompt_unit_price',
- type: VarType.number,
- },
- {
- variable: 'prompt_price_unit',
- type: VarType.number,
- },
- {
- variable: 'prompt_price',
- type: VarType.number,
- },
- {
- variable: 'completion_tokens',
- type: VarType.number,
- },
- {
- variable: 'completion_unit_price',
- type: VarType.number,
- },
- {
- variable: 'completion_price_unit',
- type: VarType.number,
- },
- {
- variable: 'completion_unit_price',
- type: VarType.number,
- },
- {
- variable: 'completion_price',
- type: VarType.number,
- },
- {
- variable: 'total_tokens',
- type: VarType.number,
- },
- {
- variable: 'total_price',
- type: VarType.number,
- },
- {
- variable: 'currency',
- type: VarType.string,
- },
- {
- variable: 'latency',
- type: VarType.number,
- },
- ],
-}
export const LLM_OUTPUT_STRUCT: Var[] = [
{
variable: 'text',
@@ -341,36 +283,11 @@ export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [
},
]
-const QUESTION_CLASSIFIER_OUTPUT_STRUCT_COMMON: Var[] = [
- USAGE,
- {
- variable: 'topic',
- type: VarType.string,
- },
-]
-
-export const CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT = [
- {
- variable: 'model_mode',
- type: VarType.string,
- },
- {
- variable: 'messages',
- type: VarType.arrayObject,
- },
- ...QUESTION_CLASSIFIER_OUTPUT_STRUCT_COMMON,
-]
-
-export const COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT = [
+export const QUESTION_CLASSIFIER_OUTPUT_STRUCT = [
{
- variable: 'model_mode',
- type: VarType.string,
- },
- {
- variable: 'text',
+ variable: 'class_name',
type: VarType.string,
},
- ...QUESTION_CLASSIFIER_OUTPUT_STRUCT_COMMON,
]
export const HTTP_REQUEST_OUTPUT_STRUCT: Var[] = [
diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts
index 1c396be536f..d5d2c3ef60f 100644
--- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts
+++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts
@@ -16,11 +16,10 @@ import type { StartNodeType } from '@/app/components/workflow/nodes/start/types'
import type { Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
import type { VariableAssignerNodeType } from '@/app/components/workflow/nodes/variable-assigner/types'
import {
- CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT,
- COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT,
HTTP_REQUEST_OUTPUT_STRUCT,
KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT,
LLM_OUTPUT_STRUCT,
+ QUESTION_CLASSIFIER_OUTPUT_STRUCT,
SUPPORT_OUTPUT_VARS_NODE,
TEMPLATE_TRANSFORM_OUTPUT_STRUCT,
TOOL_OUTPUT_STRUCT,
@@ -125,7 +124,7 @@ const formatItem = (item: any, isChatMode: boolean, filterVar: (payload: Var, se
}
case BlockEnum.QuestionClassifier: {
- res.vars = isChatMode ? CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT : COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT
+ res.vars = QUESTION_CLASSIFIER_OUTPUT_STRUCT
break
}
@@ -554,7 +553,7 @@ export const getNodeOutputVars = (node: Node, isChatMode: boolean): ValueSelecto
}
case BlockEnum.QuestionClassifier: {
- varsToValueSelectorList(isChatMode ? CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT : COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT, [id], res)
+ varsToValueSelectorList(QUESTION_CLASSIFIER_OUTPUT_STRUCT, [id], res)
break
}
diff --git a/web/app/components/workflow/nodes/question-classifier/panel.tsx b/web/app/components/workflow/nodes/question-classifier/panel.tsx
index e953fbd2d89..9103412e488 100644
--- a/web/app/components/workflow/nodes/question-classifier/panel.tsx
+++ b/web/app/components/workflow/nodes/question-classifier/panel.tsx
@@ -11,6 +11,8 @@ import ModelParameterModal from '@/app/components/header/account-setting/model-p
import { InputVarType, type NodePanelProps } from '@/app/components/workflow/types'
import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
import ResultPanel from '@/app/components/workflow/run/result-panel'
+import Split from '@/app/components/workflow/nodes/_base/components/split'
+import OutputVars, { VarItem } from '@/app/components/workflow/nodes/_base/components/output-vars'
const i18nPrefix = 'workflow.nodes.questionClassifiers'
@@ -44,8 +46,8 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
const model = inputs.model
return (
- <div>
- <div className='mt-2 px-4 space-y-4'>
+ <div className='mt-2'>
+ <div className='px-4 pb-4 space-y-4'>
<Field
title={t(`${i18nPrefix}.inputVars`)}
>
@@ -100,6 +102,18 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
/>
</Field>
</div>
+ <Split />
+ <div className='px-4 pt-4 pb-2'>
+ <OutputVars>
+ <>
+ <VarItem
+ name='class_name'
+ type='string'
+ description={t(`${i18nPrefix}.outputVars.className`)}
+ />
+ </>
+ </OutputVars>
+ </div>
{isShowSingleRun && (
<BeforeRunForm
nodeName={inputs.title}
diff --git a/web/i18n/de-DE/workflow.ts b/web/i18n/de-DE/workflow.ts
index e0a8d2531fc..e044d1fd6f7 100644
--- a/web/i18n/de-DE/workflow.ts
+++ b/web/i18n/de-DE/workflow.ts
@@ -324,6 +324,9 @@ const translation = {
questionClassifiers: {
model: 'Modell',
inputVars: 'Eingabevariablen',
+ outputVars: {
+ className: 'Klassenname',
+ },
class: 'Klasse',
classNamePlaceholder: 'Schreiben Sie Ihren Klassennamen',
advancedSetting: 'Erweiterte Einstellung',
diff --git a/web/i18n/en-US/workflow.ts b/web/i18n/en-US/workflow.ts
index 6453c5b5c67..42a073d093b 100644
--- a/web/i18n/en-US/workflow.ts
+++ b/web/i18n/en-US/workflow.ts
@@ -331,6 +331,9 @@ const translation = {
questionClassifiers: {
model: 'model',
inputVars: 'Input Variables',
+ outputVars: {
+ className: 'Class Name',
+ },
class: 'Class',
classNamePlaceholder: 'Write your class name',
advancedSetting: 'Advanced Setting',
diff --git a/web/i18n/fr-FR/workflow.ts b/web/i18n/fr-FR/workflow.ts
index 44b070fc4a6..ad7b64bfff7 100644
--- a/web/i18n/fr-FR/workflow.ts
+++ b/web/i18n/fr-FR/workflow.ts
@@ -327,6 +327,9 @@ const translation = {
questionClassifiers: {
model: 'modèle',
inputVars: 'Variables d\'entrée',
+ outputVars: {
+ className: 'Nom de la classe',
+ },
class: 'Classe',
classNamePlaceholder: 'Écrivez votre nom de classe',
advancedSetting: 'Paramètre avancé',
diff --git a/web/i18n/ja-JP/workflow.ts b/web/i18n/ja-JP/workflow.ts
index b42ea563871..1d61a266426 100644
--- a/web/i18n/ja-JP/workflow.ts
+++ b/web/i18n/ja-JP/workflow.ts
@@ -327,6 +327,9 @@ const translation = {
questionClassifiers: {
model: 'モデル',
inputVars: '入力変数',
+ outputVars: {
+ className: 'クラス名',
+ },
class: 'クラス',
classNamePlaceholder: 'クラス名を入力してください',
advancedSetting: '高度な設定',
diff --git a/web/i18n/pt-BR/workflow.ts b/web/i18n/pt-BR/workflow.ts
index 09c608f73b4..57da67fd012 100644
--- a/web/i18n/pt-BR/workflow.ts
+++ b/web/i18n/pt-BR/workflow.ts
@@ -327,6 +327,9 @@ const translation = {
questionClassifiers: {
model: 'modelo',
inputVars: 'Variáveis de entrada',
+ outputVars: {
+ className: 'Nome da classe',
+ },
class: 'Classe',
classNamePlaceholder: 'Escreva o nome da classe',
advancedSetting: 'Configuração avançada',
diff --git a/web/i18n/uk-UA/workflow.ts b/web/i18n/uk-UA/workflow.ts
index 9362b348fd3..0d7bd8dcbb0 100644
--- a/web/i18n/uk-UA/workflow.ts
+++ b/web/i18n/uk-UA/workflow.ts
@@ -327,6 +327,9 @@ const translation = {
questionClassifiers: {
model: 'модель',
inputVars: 'Вхідні змінні',
+ outputVars: {
+ className: 'Назва класу',
+ },
class: 'Клас',
classNamePlaceholder: 'Напишіть назву вашого класу',
advancedSetting: 'Розширена настройка',
diff --git a/web/i18n/vi-VN/workflow.ts b/web/i18n/vi-VN/workflow.ts
index 609c09e0e4a..e9e031164ee 100644
--- a/web/i18n/vi-VN/workflow.ts
+++ b/web/i18n/vi-VN/workflow.ts
@@ -327,6 +327,9 @@ const translation = {
questionClassifiers: {
model: 'mô hình',
inputVars: 'Biến đầu vào',
+ outputVars: {
+ className: 'Tên phân loại',
+ },
class: 'Lớp',
classNamePlaceholder: 'Viết tên lớp của bạn',
advancedSetting: 'Cài đặt Nâng cao',
diff --git a/web/i18n/zh-Hans/workflow.ts b/web/i18n/zh-Hans/workflow.ts
index 8746f1060d7..4c994998088 100644
--- a/web/i18n/zh-Hans/workflow.ts
+++ b/web/i18n/zh-Hans/workflow.ts
@@ -331,6 +331,9 @@ const translation = {
questionClassifiers: {
model: '模型',
inputVars: '输入变量',
+ outputVars: {
+ className: '分类名称',
+ },
class: '分类',
classNamePlaceholder: '输入你的分类名称',
advancedSetting: '高级设置',
diff --git a/web/i18n/zh-Hant/workflow.ts b/web/i18n/zh-Hant/workflow.ts
index f5132a3df7c..91d4f8b5639 100644
--- a/web/i18n/zh-Hant/workflow.ts
+++ b/web/i18n/zh-Hant/workflow.ts
@@ -319,6 +319,9 @@ const translation = {
questionClassifiers: {
model: '模型',
inputVars: '輸入變數',
+ outputVars: {
+ className: '分類名稱',
+ },
class: '分類',
classNamePlaceholder: '輸入你的分類名稱',
advancedSetting: '高階設定',