From 9693d014ba42ea71a095e911fe4f42dac351a2c5 Mon Sep 17 00:00:00 2001 From: Joel Date: Thu, 7 Mar 2024 17:48:07 +0800 Subject: [PATCH] feat: add llm debug --- web/app/components/workflow/constants.ts | 20 +++ .../components/before-run-form/form-item.tsx | 137 ++++++++++++++++++ .../_base/components/before-run-form/form.tsx | 56 ++++++- .../components/before-run-form/index.tsx | 63 +++++--- .../nodes/_base/hooks/use-one-step-run.ts | 24 ++- web/app/components/workflow/nodes/llm/mock.ts | 8 + .../components/workflow/nodes/llm/panel.tsx | 55 ++++++- .../workflow/nodes/llm/use-config.ts | 15 ++ web/app/components/workflow/types.ts | 1 + web/i18n/en-US/workflow.ts | 4 + web/i18n/zh-Hans/workflow.ts | 4 + 11 files changed, 355 insertions(+), 32 deletions(-) create mode 100644 web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx diff --git a/web/app/components/workflow/constants.ts b/web/app/components/workflow/constants.ts index fc94c3003c..1091299628 100644 --- a/web/app/components/workflow/constants.ts +++ b/web/app/components/workflow/constants.ts @@ -117,3 +117,23 @@ export const NODE_WIDTH = 220 export const X_OFFSET = 64 export const Y_OFFSET = 39 export const TREE_DEEPTH = 20 + +export const RETRIEVAL_OUTPUT_STRUCT = `{ + "content": "", + "title": "", + "url": "", + "icon": "", + "metadata": { + "dataset_id": "", + "dataset_name": "", + "document_id": [], + "document_name": "", + "document_data_source_type": "", + "segment_id": "", + "segment_position": "", + "segment_word_count": "", + "segment_hit_count": "", + "segment_index_node_hash": "", + "score": "" + } +}` diff --git a/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx b/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx new file mode 100644 index 0000000000..5ade9dbe41 --- /dev/null +++ b/web/app/components/workflow/nodes/_base/components/before-run-form/form-item.tsx @@ -0,0 +1,137 @@ +'use client' +import type { FC } from 'react' +import React, { useCallback } from 'react' +import produce from 'immer' +import type { InputVar } from '../../../../types' +import { InputVarType } from '../../../../types' +import CodeEditor from '../editor/code-editor' +import { CodeLanguage } from '../../../code/types' +import Select from '@/app/components/base/select' +import TextGenerationImageUploader from '@/app/components/base/image-uploader/text-generation-image-uploader' +import { Resolution, TransferMethod } from '@/types/app' +import { Trash03 } from '@/app/components/base/icons/src/vender/line/general' + +type Props = { + payload: InputVar + value: any + onChange: (value: any) => void +} + +const FormItem: FC = ({ + payload, + value, + onChange, +}) => { + const { type } = payload + const handleContextItemChange = useCallback((index: number) => { + return (newValue: any) => { + const newValues = produce(value, (draft: any) => { + draft[index] = newValue + }) + onChange(newValues) + } + }, [value, onChange]) + + const handleContextItemRemove = useCallback((index: number) => { + return () => { + const newValues = produce(value, (draft: any) => { + draft.splice(index, 1) + }) + onChange(newValues) + } + }, [value, onChange]) + return ( +
+ {type !== InputVarType.contexts &&
{payload.label}
} +
+ { + type === InputVarType.textInput && ( + onChange(e.target.value)} + /> + ) + } + + { + type === InputVarType.number && ( + onChange(e.target.value)} + /> + ) + } + + { + type === InputVarType.paragraph && ( +