mirror of
https://git.mirrors.martin98.com/https://github.com/langgenius/dify.git
synced 2025-08-15 15:25:58 +08:00
feat: support question classifier node output (#4000)
This commit is contained in:
parent
1e6e8b446d
commit
da5a8b9a59
@ -79,7 +79,6 @@ class QuestionClassifierNode(LLMNode):
|
|||||||
prompt_messages=prompt_messages
|
prompt_messages=prompt_messages
|
||||||
),
|
),
|
||||||
'usage': jsonable_encoder(usage),
|
'usage': jsonable_encoder(usage),
|
||||||
'topics': categories[0] if categories else ''
|
|
||||||
}
|
}
|
||||||
outputs = {
|
outputs = {
|
||||||
'class_name': categories[0] if categories else ''
|
'class_name': categories[0] if categories else ''
|
||||||
|
@ -259,67 +259,9 @@ export const RETRIEVAL_OUTPUT_STRUCT = `{
|
|||||||
|
|
||||||
export const SUPPORT_OUTPUT_VARS_NODE = [
|
export const SUPPORT_OUTPUT_VARS_NODE = [
|
||||||
BlockEnum.Start, BlockEnum.LLM, BlockEnum.KnowledgeRetrieval, BlockEnum.Code, BlockEnum.TemplateTransform,
|
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[] = [
|
export const LLM_OUTPUT_STRUCT: Var[] = [
|
||||||
{
|
{
|
||||||
variable: 'text',
|
variable: 'text',
|
||||||
@ -341,38 +283,13 @@ export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [
|
|||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
|
||||||
const QUESTION_CLASSIFIER_OUTPUT_STRUCT_COMMON: Var[] = [
|
export const QUESTION_CLASSIFIER_OUTPUT_STRUCT = [
|
||||||
USAGE,
|
|
||||||
{
|
{
|
||||||
variable: 'topic',
|
variable: 'class_name',
|
||||||
type: VarType.string,
|
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[] = [
|
export const HTTP_REQUEST_OUTPUT_STRUCT: Var[] = [
|
||||||
{
|
{
|
||||||
variable: 'body',
|
variable: 'body',
|
||||||
|
@ -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 { Node, NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
|
||||||
import type { VariableAssignerNodeType } from '@/app/components/workflow/nodes/variable-assigner/types'
|
import type { VariableAssignerNodeType } from '@/app/components/workflow/nodes/variable-assigner/types'
|
||||||
import {
|
import {
|
||||||
CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT,
|
|
||||||
COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT,
|
|
||||||
HTTP_REQUEST_OUTPUT_STRUCT,
|
HTTP_REQUEST_OUTPUT_STRUCT,
|
||||||
KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT,
|
KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT,
|
||||||
LLM_OUTPUT_STRUCT,
|
LLM_OUTPUT_STRUCT,
|
||||||
|
QUESTION_CLASSIFIER_OUTPUT_STRUCT,
|
||||||
SUPPORT_OUTPUT_VARS_NODE,
|
SUPPORT_OUTPUT_VARS_NODE,
|
||||||
TEMPLATE_TRANSFORM_OUTPUT_STRUCT,
|
TEMPLATE_TRANSFORM_OUTPUT_STRUCT,
|
||||||
TOOL_OUTPUT_STRUCT,
|
TOOL_OUTPUT_STRUCT,
|
||||||
@ -125,7 +124,7 @@ const formatItem = (item: any, isChatMode: boolean, filterVar: (payload: Var, se
|
|||||||
}
|
}
|
||||||
|
|
||||||
case BlockEnum.QuestionClassifier: {
|
case BlockEnum.QuestionClassifier: {
|
||||||
res.vars = isChatMode ? CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT : COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT
|
res.vars = QUESTION_CLASSIFIER_OUTPUT_STRUCT
|
||||||
break
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -554,7 +553,7 @@ export const getNodeOutputVars = (node: Node, isChatMode: boolean): ValueSelecto
|
|||||||
}
|
}
|
||||||
|
|
||||||
case BlockEnum.QuestionClassifier: {
|
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
|
break
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -11,6 +11,8 @@ import ModelParameterModal from '@/app/components/header/account-setting/model-p
|
|||||||
import { InputVarType, type NodePanelProps } from '@/app/components/workflow/types'
|
import { InputVarType, type NodePanelProps } from '@/app/components/workflow/types'
|
||||||
import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
|
import BeforeRunForm from '@/app/components/workflow/nodes/_base/components/before-run-form'
|
||||||
import ResultPanel from '@/app/components/workflow/run/result-panel'
|
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'
|
const i18nPrefix = 'workflow.nodes.questionClassifiers'
|
||||||
|
|
||||||
@ -44,8 +46,8 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
|
|||||||
const model = inputs.model
|
const model = inputs.model
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<div>
|
<div className='mt-2'>
|
||||||
<div className='mt-2 px-4 space-y-4'>
|
<div className='px-4 pb-4 space-y-4'>
|
||||||
<Field
|
<Field
|
||||||
title={t(`${i18nPrefix}.inputVars`)}
|
title={t(`${i18nPrefix}.inputVars`)}
|
||||||
>
|
>
|
||||||
@ -100,6 +102,18 @@ const Panel: FC<NodePanelProps<QuestionClassifierNodeType>> = ({
|
|||||||
/>
|
/>
|
||||||
</Field>
|
</Field>
|
||||||
</div>
|
</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 && (
|
{isShowSingleRun && (
|
||||||
<BeforeRunForm
|
<BeforeRunForm
|
||||||
nodeName={inputs.title}
|
nodeName={inputs.title}
|
||||||
|
@ -324,6 +324,9 @@ const translation = {
|
|||||||
questionClassifiers: {
|
questionClassifiers: {
|
||||||
model: 'Modell',
|
model: 'Modell',
|
||||||
inputVars: 'Eingabevariablen',
|
inputVars: 'Eingabevariablen',
|
||||||
|
outputVars: {
|
||||||
|
className: 'Klassenname',
|
||||||
|
},
|
||||||
class: 'Klasse',
|
class: 'Klasse',
|
||||||
classNamePlaceholder: 'Schreiben Sie Ihren Klassennamen',
|
classNamePlaceholder: 'Schreiben Sie Ihren Klassennamen',
|
||||||
advancedSetting: 'Erweiterte Einstellung',
|
advancedSetting: 'Erweiterte Einstellung',
|
||||||
|
@ -331,6 +331,9 @@ const translation = {
|
|||||||
questionClassifiers: {
|
questionClassifiers: {
|
||||||
model: 'model',
|
model: 'model',
|
||||||
inputVars: 'Input Variables',
|
inputVars: 'Input Variables',
|
||||||
|
outputVars: {
|
||||||
|
className: 'Class Name',
|
||||||
|
},
|
||||||
class: 'Class',
|
class: 'Class',
|
||||||
classNamePlaceholder: 'Write your class name',
|
classNamePlaceholder: 'Write your class name',
|
||||||
advancedSetting: 'Advanced Setting',
|
advancedSetting: 'Advanced Setting',
|
||||||
|
@ -327,6 +327,9 @@ const translation = {
|
|||||||
questionClassifiers: {
|
questionClassifiers: {
|
||||||
model: 'modèle',
|
model: 'modèle',
|
||||||
inputVars: 'Variables d\'entrée',
|
inputVars: 'Variables d\'entrée',
|
||||||
|
outputVars: {
|
||||||
|
className: 'Nom de la classe',
|
||||||
|
},
|
||||||
class: 'Classe',
|
class: 'Classe',
|
||||||
classNamePlaceholder: 'Écrivez votre nom de classe',
|
classNamePlaceholder: 'Écrivez votre nom de classe',
|
||||||
advancedSetting: 'Paramètre avancé',
|
advancedSetting: 'Paramètre avancé',
|
||||||
|
@ -327,6 +327,9 @@ const translation = {
|
|||||||
questionClassifiers: {
|
questionClassifiers: {
|
||||||
model: 'モデル',
|
model: 'モデル',
|
||||||
inputVars: '入力変数',
|
inputVars: '入力変数',
|
||||||
|
outputVars: {
|
||||||
|
className: 'クラス名',
|
||||||
|
},
|
||||||
class: 'クラス',
|
class: 'クラス',
|
||||||
classNamePlaceholder: 'クラス名を入力してください',
|
classNamePlaceholder: 'クラス名を入力してください',
|
||||||
advancedSetting: '高度な設定',
|
advancedSetting: '高度な設定',
|
||||||
|
@ -327,6 +327,9 @@ const translation = {
|
|||||||
questionClassifiers: {
|
questionClassifiers: {
|
||||||
model: 'modelo',
|
model: 'modelo',
|
||||||
inputVars: 'Variáveis de entrada',
|
inputVars: 'Variáveis de entrada',
|
||||||
|
outputVars: {
|
||||||
|
className: 'Nome da classe',
|
||||||
|
},
|
||||||
class: 'Classe',
|
class: 'Classe',
|
||||||
classNamePlaceholder: 'Escreva o nome da classe',
|
classNamePlaceholder: 'Escreva o nome da classe',
|
||||||
advancedSetting: 'Configuração avançada',
|
advancedSetting: 'Configuração avançada',
|
||||||
|
@ -327,6 +327,9 @@ const translation = {
|
|||||||
questionClassifiers: {
|
questionClassifiers: {
|
||||||
model: 'модель',
|
model: 'модель',
|
||||||
inputVars: 'Вхідні змінні',
|
inputVars: 'Вхідні змінні',
|
||||||
|
outputVars: {
|
||||||
|
className: 'Назва класу',
|
||||||
|
},
|
||||||
class: 'Клас',
|
class: 'Клас',
|
||||||
classNamePlaceholder: 'Напишіть назву вашого класу',
|
classNamePlaceholder: 'Напишіть назву вашого класу',
|
||||||
advancedSetting: 'Розширена настройка',
|
advancedSetting: 'Розширена настройка',
|
||||||
|
@ -327,6 +327,9 @@ const translation = {
|
|||||||
questionClassifiers: {
|
questionClassifiers: {
|
||||||
model: 'mô hình',
|
model: 'mô hình',
|
||||||
inputVars: 'Biến đầu vào',
|
inputVars: 'Biến đầu vào',
|
||||||
|
outputVars: {
|
||||||
|
className: 'Tên phân loại',
|
||||||
|
},
|
||||||
class: 'Lớp',
|
class: 'Lớp',
|
||||||
classNamePlaceholder: 'Viết tên lớp của bạn',
|
classNamePlaceholder: 'Viết tên lớp của bạn',
|
||||||
advancedSetting: 'Cài đặt Nâng cao',
|
advancedSetting: 'Cài đặt Nâng cao',
|
||||||
|
@ -331,6 +331,9 @@ const translation = {
|
|||||||
questionClassifiers: {
|
questionClassifiers: {
|
||||||
model: '模型',
|
model: '模型',
|
||||||
inputVars: '输入变量',
|
inputVars: '输入变量',
|
||||||
|
outputVars: {
|
||||||
|
className: '分类名称',
|
||||||
|
},
|
||||||
class: '分类',
|
class: '分类',
|
||||||
classNamePlaceholder: '输入你的分类名称',
|
classNamePlaceholder: '输入你的分类名称',
|
||||||
advancedSetting: '高级设置',
|
advancedSetting: '高级设置',
|
||||||
|
@ -319,6 +319,9 @@ const translation = {
|
|||||||
questionClassifiers: {
|
questionClassifiers: {
|
||||||
model: '模型',
|
model: '模型',
|
||||||
inputVars: '輸入變數',
|
inputVars: '輸入變數',
|
||||||
|
outputVars: {
|
||||||
|
className: '分類名稱',
|
||||||
|
},
|
||||||
class: '分類',
|
class: '分類',
|
||||||
classNamePlaceholder: '輸入你的分類名稱',
|
classNamePlaceholder: '輸入你的分類名稱',
|
||||||
advancedSetting: '高階設定',
|
advancedSetting: '高階設定',
|
||||||
|
Loading…
x
Reference in New Issue
Block a user