mirror of
https://github.com/langgenius/dify.git
synced 2026-05-06 02:18:08 +08:00
feat: llm output and var type
This commit is contained in:
@ -1,6 +1,14 @@
|
||||
import { BlockEnum } 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 { NodeOutPutVar } from '@/app/components/workflow/types'
|
||||
import { LLM_OUTPUT_STRUCT, SUPPORT_OUTPUT_VARS_NODE } from '@/app/components/workflow/constants'
|
||||
|
||||
const inputVarTypeToVarType = (type: InputVarType): VarType => {
|
||||
if (type === InputVarType.number)
|
||||
return VarType.number
|
||||
|
||||
return VarType.string
|
||||
}
|
||||
|
||||
const formatItem = (item: any): NodeOutPutVar => {
|
||||
const { id, data } = item
|
||||
@ -17,19 +25,20 @@ const formatItem = (item: any): NodeOutPutVar => {
|
||||
res.vars = variables.map((v) => {
|
||||
return {
|
||||
variable: v.variable,
|
||||
type: v.type,
|
||||
type: inputVarTypeToVarType(v.type),
|
||||
}
|
||||
})
|
||||
break
|
||||
}
|
||||
|
||||
// default:
|
||||
// // throw new Error('unknown type')
|
||||
// break
|
||||
case BlockEnum.LLM: {
|
||||
res.vars = LLM_OUTPUT_STRUCT
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
return res
|
||||
}
|
||||
export const toNodeOutputVars = (nodes: any[]): NodeOutPutVar[] => {
|
||||
return nodes.map(formatItem)
|
||||
return nodes.filter(node => SUPPORT_OUTPUT_VARS_NODE.includes(node.data.type)).map(formatItem)
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import cn from 'classnames'
|
||||
import VarReferencePopup from './var-reference-popup'
|
||||
import { toNodeOutputVars } from './utils'
|
||||
import type { ValueSelector } from '@/app/components/workflow/types'
|
||||
import { VarType } from '@/app/components/workflow/types'
|
||||
import { VarBlockIcon } from '@/app/components/workflow/block-icon'
|
||||
import { Line3 } from '@/app/components/base/icons/src/public/common'
|
||||
import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
|
||||
@ -54,9 +55,26 @@ const VarReferencePicker: FC<Props> = ({
|
||||
const outputVarNode = hasValue ? getNodeInfoById(availableNodes, outputVarNodeId)?.data : null
|
||||
// console.log(hasValue, value, outputVarNode)
|
||||
const varName = hasValue ? value[value.length - 1] : ''
|
||||
// TODO: get var type through node and value
|
||||
|
||||
const getVarType = () => {
|
||||
return 'string'
|
||||
const targetVar = outputVars.find(v => v.nodeId === outputVarNodeId)
|
||||
if (!targetVar)
|
||||
return 'undefined'
|
||||
|
||||
let type: VarType = VarType.string
|
||||
let curr: any = targetVar.vars
|
||||
value.slice(1).forEach((key, i) => {
|
||||
const isLast = i === value.length - 2
|
||||
curr = curr.find((v: any) => v.variable === key)
|
||||
if (isLast) {
|
||||
type = curr.type
|
||||
}
|
||||
else {
|
||||
if (curr.type === VarType.object)
|
||||
curr = curr.children
|
||||
}
|
||||
})
|
||||
return type
|
||||
}
|
||||
|
||||
return (
|
||||
|
||||
@ -3,7 +3,7 @@ import type { FC } from 'react'
|
||||
import React, { useRef } from 'react'
|
||||
import { useHover } from 'ahooks'
|
||||
import cn from 'classnames'
|
||||
import type { NodeOutPutVar, ValueSelector, Var } from '@/app/components/workflow/types'
|
||||
import { type NodeOutPutVar, type ValueSelector, type Var, VarType } from '@/app/components/workflow/types'
|
||||
import { Variable02 } from '@/app/components/base/icons/src/vender/solid/development'
|
||||
import { ChevronRight } from '@/app/components/base/icons/src/vender/line/arrows'
|
||||
|
||||
@ -30,7 +30,7 @@ const Item: FC<ItemProps> = ({
|
||||
itemData,
|
||||
onChange,
|
||||
}) => {
|
||||
const isObj = itemData.type === 'object'
|
||||
const isObj = itemData.type === VarType.object
|
||||
const itemRef = useRef(null)
|
||||
const isItemHovering = useHover(itemRef)
|
||||
const handleChosen = (e: React.MouseEvent) => {
|
||||
|
||||
Reference in New Issue
Block a user