From da5a8b9a59337270425e7c8b604ef8ed4200765e Mon Sep 17 00:00:00 2001 From: sino Date: Tue, 30 Apr 2024 17:07:29 +0800 Subject: [PATCH] feat: support question classifier node output (#4000) --- .../question_classifier_node.py | 1 - web/app/components/workflow/constants.ts | 89 +------------------ .../nodes/_base/components/variable/utils.ts | 7 +- .../nodes/question-classifier/panel.tsx | 18 +++- web/i18n/de-DE/workflow.ts | 3 + web/i18n/en-US/workflow.ts | 3 + web/i18n/fr-FR/workflow.ts | 3 + web/i18n/ja-JP/workflow.ts | 3 + web/i18n/pt-BR/workflow.ts | 3 + web/i18n/uk-UA/workflow.ts | 3 + web/i18n/vi-VN/workflow.ts | 3 + web/i18n/zh-Hans/workflow.ts | 3 + web/i18n/zh-Hant/workflow.ts | 3 + 13 files changed, 49 insertions(+), 93 deletions(-) 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 c8f458de87..9ec0df721c 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 e9818ea19c..2b163008ad 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,38 +283,13 @@ export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [ }, ] -const QUESTION_CLASSIFIER_OUTPUT_STRUCT_COMMON: Var[] = [ - USAGE, +export const QUESTION_CLASSIFIER_OUTPUT_STRUCT = [ { - variable: 'topic', + variable: 'class_name', 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 = [ - { - variable: 'model_mode', - type: VarType.string, - }, - { - variable: 'text', - type: VarType.string, - }, - ...QUESTION_CLASSIFIER_OUTPUT_STRUCT_COMMON, -] - export const HTTP_REQUEST_OUTPUT_STRUCT: Var[] = [ { variable: 'body', 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 1c396be536..d5d2c3ef60 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 e953fbd2d8..9103412e48 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> = ({ const model = inputs.model return ( -
-
+
+
@@ -100,6 +102,18 @@ const Panel: FC> = ({ />
+ +
+ + <> + + + +
{isShowSingleRun && (