From 7ec29bbee7a36f6b33f28032044d0c2d6ddd562e Mon Sep 17 00:00:00 2001 From: Joel Date: Tue, 5 Mar 2024 14:23:47 +0800 Subject: [PATCH] feat: node add default value --- web/app/components/workflow/constants.ts | 13 +------------ .../components/workflow/nodes/code/default.ts | 9 +++++++-- .../components/workflow/nodes/end/default.ts | 10 ++++++++-- .../components/workflow/nodes/http/default.ts | 18 ++++++++++++++++-- .../components/workflow/nodes/http/types.ts | 2 +- .../workflow/nodes/if-else/default.ts | 17 +++++++++++++++-- .../nodes/knowledge-retrieval/default.ts | 7 ++++++- .../components/workflow/nodes/llm/default.ts | 18 +++++++++++++++++- web/app/components/workflow/nodes/llm/types.ts | 2 +- .../nodes/question-classifier/default.ts | 13 ++++++++++++- .../workflow/nodes/question-classifier/mock.ts | 2 +- .../nodes/question-classifier/node.tsx | 2 +- .../nodes/question-classifier/panel.tsx | 2 +- .../nodes/question-classifier/types.ts | 2 +- .../nodes/template-transform/default.ts | 4 +++- .../components/workflow/nodes/tool/default.ts | 5 ++++- .../nodes/variable-assigner/default.ts | 5 ++++- 17 files changed, 99 insertions(+), 32 deletions(-) diff --git a/web/app/components/workflow/constants.ts b/web/app/components/workflow/constants.ts index 02fb682cde..69e618ca9c 100644 --- a/web/app/components/workflow/constants.ts +++ b/web/app/components/workflow/constants.ts @@ -48,21 +48,10 @@ export const NODES_INITIAL_DATA = { ...KnowledgeRetrievalDefault.defaultValue, }, [BlockEnum.IfElse]: { - _targetBranches: [ - { - id: 'if-true', - name: 'IS TRUE', - }, - { - id: 'if-false', - name: 'IS FALSE', - }, - ], type: BlockEnum.IfElse, title: '', desc: '', - logical_operator: 'and', - conditions: [], + ...IfElseDefault.defaultValue, }, [BlockEnum.Code]: { diff --git a/web/app/components/workflow/nodes/code/default.ts b/web/app/components/workflow/nodes/code/default.ts index 1abac168a7..7a255188ba 100644 --- a/web/app/components/workflow/nodes/code/default.ts +++ b/web/app/components/workflow/nodes/code/default.ts @@ -1,8 +1,13 @@ import type { NodeDefault } from '../../types' -import type { CodeNodeType } from './types' +import { CodeLanguage, type CodeNodeType } from './types' const nodeDefault: NodeDefault = { - defaultValue: {}, + defaultValue: { + code: '', + code_language: CodeLanguage.python3, + variables: [], + outputs: [], + }, getAvailablePrevNodes() { return [] }, diff --git a/web/app/components/workflow/nodes/end/default.ts b/web/app/components/workflow/nodes/end/default.ts index 05a462d15f..1c1701d7c6 100644 --- a/web/app/components/workflow/nodes/end/default.ts +++ b/web/app/components/workflow/nodes/end/default.ts @@ -1,8 +1,14 @@ import type { NodeDefault } from '../../types' -import type { EndNodeType } from './types' +import { type EndNodeType, EndVarType } from './types' const nodeDefault: NodeDefault = { - defaultValue: {}, + defaultValue: { + outputs: { + type: EndVarType.none, + plain_text_selector: [], + structured_variables: [], + }, + }, getAvailablePrevNodes() { return [] }, diff --git a/web/app/components/workflow/nodes/http/default.ts b/web/app/components/workflow/nodes/http/default.ts index e795b39dd4..aade82383a 100644 --- a/web/app/components/workflow/nodes/http/default.ts +++ b/web/app/components/workflow/nodes/http/default.ts @@ -1,8 +1,22 @@ import type { NodeDefault } from '../../types' -import type { HttpNodeType } from './types' +import { AuthorizationType, BodyType, type HttpNodeType, Method } from './types' const nodeDefault: NodeDefault = { - defaultValue: {}, + defaultValue: { + variables: [], + method: Method.get, + url: '', + authorization: { + type: AuthorizationType.none, + config: null, + }, + headers: '', + params: '', + body: { + type: BodyType.none, + data: '', + }, + }, getAvailablePrevNodes() { return [] }, diff --git a/web/app/components/workflow/nodes/http/types.ts b/web/app/components/workflow/nodes/http/types.ts index c8b0251320..ca3c98c6fc 100644 --- a/web/app/components/workflow/nodes/http/types.ts +++ b/web/app/components/workflow/nodes/http/types.ts @@ -44,7 +44,7 @@ export type Authorization = { type: APIType api_key: string header?: string - } + } | null } export type HttpNodeType = CommonNodeType & { diff --git a/web/app/components/workflow/nodes/if-else/default.ts b/web/app/components/workflow/nodes/if-else/default.ts index 180de711aa..c738bfd54c 100644 --- a/web/app/components/workflow/nodes/if-else/default.ts +++ b/web/app/components/workflow/nodes/if-else/default.ts @@ -1,8 +1,21 @@ import type { NodeDefault } from '../../types' -import type { IfElseNodeType } from './types' +import { type IfElseNodeType, LogicalOperator } from './types' const nodeDefault: NodeDefault = { - defaultValue: {}, + defaultValue: { + _targetBranches: [ + { + id: 'if-true', + name: 'IS TRUE', + }, + { + id: 'if-false', + name: 'IS FALSE', + }, + ], + logical_operator: LogicalOperator.and, + conditions: [], + }, getAvailablePrevNodes() { return [] }, diff --git a/web/app/components/workflow/nodes/knowledge-retrieval/default.ts b/web/app/components/workflow/nodes/knowledge-retrieval/default.ts index d684e81e9a..ba396e18b4 100644 --- a/web/app/components/workflow/nodes/knowledge-retrieval/default.ts +++ b/web/app/components/workflow/nodes/knowledge-retrieval/default.ts @@ -1,8 +1,13 @@ import type { NodeDefault } from '../../types' import type { KnowledgeRetrievalNodeType } from './types' +import { RETRIEVE_TYPE } from '@/types/app' const nodeDefault: NodeDefault = { - defaultValue: {}, + defaultValue: { + query_variable_selector: [], + dataset_ids: [], + retrieval_mode: RETRIEVE_TYPE.oneWay, + }, getAvailablePrevNodes() { return [] }, diff --git a/web/app/components/workflow/nodes/llm/default.ts b/web/app/components/workflow/nodes/llm/default.ts index 115dcc56a3..15a1b6c632 100644 --- a/web/app/components/workflow/nodes/llm/default.ts +++ b/web/app/components/workflow/nodes/llm/default.ts @@ -3,7 +3,23 @@ import type { LLMNodeType } from './types' const nodeDefault: NodeDefault = { defaultValue: { - + model: { + provider: '', + name: '', + mode: 'chat', + completion_params: { + temperature: 0.7, + }, + }, + variables: [], + prompt: [], + context: { + enabled: false, + variable_selector: [], + }, + vision: { + enabled: false, + }, }, getAvailablePrevNodes() { return [] diff --git a/web/app/components/workflow/nodes/llm/types.ts b/web/app/components/workflow/nodes/llm/types.ts index c0fa3938ed..b24fc7b48b 100644 --- a/web/app/components/workflow/nodes/llm/types.ts +++ b/web/app/components/workflow/nodes/llm/types.ts @@ -12,7 +12,7 @@ export type LLMNodeType = CommonNodeType & { } vision: { enabled: boolean - configs: { + configs?: { detail: Resolution } } diff --git a/web/app/components/workflow/nodes/question-classifier/default.ts b/web/app/components/workflow/nodes/question-classifier/default.ts index ed0423654f..599ef2c594 100644 --- a/web/app/components/workflow/nodes/question-classifier/default.ts +++ b/web/app/components/workflow/nodes/question-classifier/default.ts @@ -2,7 +2,18 @@ import type { NodeDefault } from '../../types' import type { QuestionClassifierNodeType } from './types' const nodeDefault: NodeDefault = { - defaultValue: {}, + defaultValue: { + query_variable_selector: [], + model: { + provider: '', + name: '', + mode: 'chat', + completion_params: { + temperature: 0.7, + }, + }, + classes: [], + }, getAvailablePrevNodes() { return [] }, diff --git a/web/app/components/workflow/nodes/question-classifier/mock.ts b/web/app/components/workflow/nodes/question-classifier/mock.ts index 7c2b18eefd..daada0fa1a 100644 --- a/web/app/components/workflow/nodes/question-classifier/mock.ts +++ b/web/app/components/workflow/nodes/question-classifier/mock.ts @@ -14,7 +14,7 @@ export const mockData: QuestionClassifierNodeType = { temperature: 0.7, }, }, - topics: [ + classes: [ { id: '1', name: 'topic 1', diff --git a/web/app/components/workflow/nodes/question-classifier/node.tsx b/web/app/components/workflow/nodes/question-classifier/node.tsx index 834490811b..bffbef8c65 100644 --- a/web/app/components/workflow/nodes/question-classifier/node.tsx +++ b/web/app/components/workflow/nodes/question-classifier/node.tsx @@ -13,7 +13,7 @@ const Node: FC> = (props) => { const { data } = props const { provider, name: modelId } = data.model // const tempTopics = data.topics - const topics = data.topics + const topics = data.classes const { textGenerationModelList, } = useTextGenerationCurrentProviderAndModelAndModelList() diff --git a/web/app/components/workflow/nodes/question-classifier/panel.tsx b/web/app/components/workflow/nodes/question-classifier/panel.tsx index 3b21f5701b..fc68480733 100644 --- a/web/app/components/workflow/nodes/question-classifier/panel.tsx +++ b/web/app/components/workflow/nodes/question-classifier/panel.tsx @@ -62,7 +62,7 @@ const Panel: FC> = ({ title={t(`${i18nPrefix}.class`)} > = { - defaultValue: {}, + defaultValue: { + variables: [], + }, getAvailablePrevNodes() { return [] }, diff --git a/web/app/components/workflow/nodes/tool/default.ts b/web/app/components/workflow/nodes/tool/default.ts index b4b93b71b2..090918e9ba 100644 --- a/web/app/components/workflow/nodes/tool/default.ts +++ b/web/app/components/workflow/nodes/tool/default.ts @@ -2,7 +2,10 @@ import type { NodeDefault } from '../../types' import type { ToolNodeType } from './types' const nodeDefault: NodeDefault = { - defaultValue: {}, + defaultValue: { + tool_inputs: [], + tool_parameters: {}, + }, getAvailablePrevNodes() { return [] }, diff --git a/web/app/components/workflow/nodes/variable-assigner/default.ts b/web/app/components/workflow/nodes/variable-assigner/default.ts index 1439774ac5..ce7785fc3f 100644 --- a/web/app/components/workflow/nodes/variable-assigner/default.ts +++ b/web/app/components/workflow/nodes/variable-assigner/default.ts @@ -2,7 +2,10 @@ import type { NodeDefault } from '../../types' import type { VariableAssignerNodeType } from './types' const nodeDefault: NodeDefault = { - defaultValue: {}, + defaultValue: { + output_type: 'string', + variables: [], + }, getAvailablePrevNodes() { return [] },