feat: support question classifier node output (#4000)

This commit is contained in:
sino
2024-04-30 17:07:29 +08:00
committed by GitHub
parent 1e6e8b446d
commit da5a8b9a59
13 changed files with 49 additions and 93 deletions

View File

@@ -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',

View File

@@ -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
}

View File

@@ -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}