From f8d26e46ac10527a8bdac5df7f7be6d7509e888c Mon Sep 17 00:00:00 2001 From: JzoNg Date: Wed, 25 Sep 2024 15:01:56 +0800 Subject: [PATCH] text-generation support file type --- .../share/text-generation/index.tsx | 1 + .../share/text-generation/run-once/index.tsx | 15 ++++++-- web/utils/model-config.ts | 34 +++++++++++++++++++ 3 files changed, 47 insertions(+), 3 deletions(-) diff --git a/web/app/components/share/text-generation/index.tsx b/web/app/components/share/text-generation/index.tsx index a2f6864242..79572ab83f 100644 --- a/web/app/components/share/text-generation/index.tsx +++ b/web/app/components/share/text-generation/index.tsx @@ -392,6 +392,7 @@ const TextGeneration: FC = ({ image_file_size_limit: appParams?.system_parameters?.image_file_size_limit, }) const prompt_variables = userInputsFormToPromptVariables(user_input_form) + console.log(prompt_variables) setPromptConfig({ prompt_template: '', // placeholder for future prompt_variables, diff --git a/web/app/components/share/text-generation/run-once/index.tsx b/web/app/components/share/text-generation/run-once/index.tsx index 99aaf57a9f..d804deadab 100644 --- a/web/app/components/share/text-generation/run-once/index.tsx +++ b/web/app/components/share/text-generation/run-once/index.tsx @@ -94,6 +94,18 @@ const RunOnce: FC = ({ onChange={(e) => { onInputsChange({ ...inputs, [item.key]: e.target.value }) }} /> )} + {item.type === 'file' && ( + { onInputsChange({ ...inputs, [item.key]: getProcessedFiles(files)[0] }) }} + fileConfig={item.config as any} + /> + )} + {item.type === 'file-list' && ( + { onInputsChange({ ...inputs, [item.key]: getProcessedFiles(files) }) }} + fileConfig={item.config as any} + /> + )} ))} @@ -115,9 +127,6 @@ const RunOnce: FC = ({ ) } - onVisionFilesChange(getProcessedFiles(files))} - /> {promptConfig.prompt_variables.length > 0 && (
)} diff --git a/web/utils/model-config.ts b/web/utils/model-config.ts index d83757aaaa..a00bcfbb51 100644 --- a/web/utils/model-config.ts +++ b/web/utils/model-config.ts @@ -18,6 +18,12 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] | if (item.number) return ['number', item.number] + if (item.file) + return ['file', item.file] + + if (item['file-list']) + return ['file-list', item['file-list']] + if (item.external_data_tool) return [item.external_data_tool.type, item.external_data_tool] @@ -55,6 +61,34 @@ export const userInputsFormToPromptVariables = (useInputs: UserInputFormItem[] | is_context_var, }) } + else if (type === 'file') { + promptVariables.push({ + key: content.variable, + name: content.label, + required: content.required, + type, + config: { + allowed_file_types: content.allowed_file_types, + allowed_file_extensions: content.allowed_file_extensions, + allowed_file_upload_methods: content.allowed_file_upload_methods, + number_limits: 1, + }, + }) + } + else if (type === 'file-list') { + promptVariables.push({ + key: content.variable, + name: content.label, + required: content.required, + type, + config: { + allowed_file_types: content.allowed_file_types, + allowed_file_extensions: content.allowed_file_extensions, + allowed_file_upload_methods: content.allowed_file_upload_methods, + number_limits: content.max_length, + }, + }) + } else { promptVariables.push({ key: content.variable,