Commit 25a11c5b authored by Joel's avatar Joel

feat: question classify output

parent 1f41521c
...@@ -185,69 +185,70 @@ export const SUPPORT_OUTPUT_VARS_NODE = [ ...@@ -185,69 +185,70 @@ export const SUPPORT_OUTPUT_VARS_NODE = [
BlockEnum.QuestionClassifier, BlockEnum.HttpRequest, BlockEnum.Tool, BlockEnum.VariableAssigner, BlockEnum.QuestionClassifier, BlockEnum.HttpRequest, BlockEnum.Tool, BlockEnum.VariableAssigner,
] ]
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',
type: VarType.string, type: VarType.string,
}, },
{
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 KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT: Var[] = [ export const KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT: Var[] = [
...@@ -255,6 +256,7 @@ export const KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT: Var[] = [ ...@@ -255,6 +256,7 @@ export const KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT: Var[] = [
variable: 'result', variable: 'result',
type: VarType.arrayObject, type: VarType.arrayObject,
}, },
USAGE,
] ]
export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [ export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [
...@@ -263,3 +265,35 @@ export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [ ...@@ -263,3 +265,35 @@ export const TEMPLATE_TRANSFORM_OUTPUT_STRUCT: Var[] = [
type: VarType.string, type: VarType.string,
}, },
] ]
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 = [
{
variable: 'model_mode',
type: VarType.string,
},
{
variable: 'text',
type: VarType.string,
},
...QUESTION_CLASSIFIER_OUTPUT_STRUCT_COMMON,
]
...@@ -2,7 +2,14 @@ import type { CodeNodeType } from '../../../code/types' ...@@ -2,7 +2,14 @@ import type { CodeNodeType } from '../../../code/types'
import { BlockEnum, InputVarType, VarType } from '@/app/components/workflow/types' import { BlockEnum, InputVarType, VarType } from '@/app/components/workflow/types'
import type { StartNodeType } from '@/app/components/workflow/nodes/start/types' import type { StartNodeType } from '@/app/components/workflow/nodes/start/types'
import type { NodeOutPutVar } from '@/app/components/workflow/types' import type { NodeOutPutVar } from '@/app/components/workflow/types'
import { KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT, LLM_OUTPUT_STRUCT, SUPPORT_OUTPUT_VARS_NODE, TEMPLATE_TRANSFORM_OUTPUT_STRUCT } from '@/app/components/workflow/constants' import {
CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT,
COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT,
KNOWLEDGE_RETRIEVAL_OUTPUT_STRUCT,
LLM_OUTPUT_STRUCT,
SUPPORT_OUTPUT_VARS_NODE,
TEMPLATE_TRANSFORM_OUTPUT_STRUCT,
} from '@/app/components/workflow/constants'
const inputVarTypeToVarType = (type: InputVarType): VarType => { const inputVarTypeToVarType = (type: InputVarType): VarType => {
if (type === InputVarType.number) if (type === InputVarType.number)
...@@ -11,7 +18,7 @@ const inputVarTypeToVarType = (type: InputVarType): VarType => { ...@@ -11,7 +18,7 @@ const inputVarTypeToVarType = (type: InputVarType): VarType => {
return VarType.string return VarType.string
} }
const formatItem = (item: any): NodeOutPutVar => { const formatItem = (item: any, isChatMode: boolean): NodeOutPutVar => {
const { id, data } = item const { id, data } = item
const res: NodeOutPutVar = { const res: NodeOutPutVar = {
nodeId: id, nodeId: id,
...@@ -59,10 +66,15 @@ const formatItem = (item: any): NodeOutPutVar => { ...@@ -59,10 +66,15 @@ const formatItem = (item: any): NodeOutPutVar => {
res.vars = TEMPLATE_TRANSFORM_OUTPUT_STRUCT res.vars = TEMPLATE_TRANSFORM_OUTPUT_STRUCT
break break
} }
case BlockEnum.QuestionClassifier: {
res.vars = isChatMode ? CHAT_QUESTION_CLASSIFIER_OUTPUT_STRUCT : COMPLETION_QUESTION_CLASSIFIER_OUTPUT_STRUCT
break
}
} }
return res return res
} }
export const toNodeOutputVars = (nodes: any[]): NodeOutPutVar[] => { export const toNodeOutputVars = (nodes: any[], isChatMode: boolean): NodeOutPutVar[] => {
return nodes.filter(node => SUPPORT_OUTPUT_VARS_NODE.includes(node.data.type)).map(formatItem) return nodes.filter(node => SUPPORT_OUTPUT_VARS_NODE.includes(node.data.type)).map(node => formatItem(node, isChatMode))
} }
...@@ -14,7 +14,10 @@ import { ...@@ -14,7 +14,10 @@ import {
PortalToFollowElemContent, PortalToFollowElemContent,
PortalToFollowElemTrigger, PortalToFollowElemTrigger,
} from '@/app/components/base/portal-to-follow-elem' } from '@/app/components/base/portal-to-follow-elem'
import { useWorkflow } from '@/app/components/workflow/hooks' import {
useIsChatMode,
useWorkflow,
} from '@/app/components/workflow/hooks'
type Props = { type Props = {
className?: string className?: string
...@@ -37,9 +40,11 @@ const VarReferencePicker: FC<Props> = ({ ...@@ -37,9 +40,11 @@ const VarReferencePicker: FC<Props> = ({
value, value,
onChange, onChange,
}) => { }) => {
const isChatMode = useIsChatMode()
const { getTreeLeafNodes, getBeforeNodesInSameBranch } = useWorkflow() const { getTreeLeafNodes, getBeforeNodesInSameBranch } = useWorkflow()
const availableNodes = getBeforeNodesInSameBranch(nodeId) const availableNodes = getBeforeNodesInSameBranch(nodeId)
const outputVars = toNodeOutputVars(availableNodes) const outputVars = toNodeOutputVars(availableNodes, isChatMode)
const [open, setOpen] = useState(false) const [open, setOpen] = useState(false)
const hasValue = value.length > 0 const hasValue = value.length > 0
const outputVarNodeId = hasValue ? value[0] : '' const outputVarNodeId = hasValue ? value[0] : ''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment