diff --git a/api/core/workflow/nodes/llm/node.py b/api/core/workflow/nodes/llm/node.py index fe0ed3e564..3e246c2658 100644 --- a/api/core/workflow/nodes/llm/node.py +++ b/api/core/workflow/nodes/llm/node.py @@ -191,8 +191,18 @@ class LLMNode(BaseNode[LLMNodeData]): # deduct quota self.deduct_llm_quota(tenant_id=self.tenant_id, model_instance=model_instance, usage=usage) break - outputs = {"text": result_text, "usage": jsonable_encoder(usage), "finish_reason": finish_reason} - + outputs = { + "text": result_text, + "usage": jsonable_encoder(usage), + "finish_reason": finish_reason, + "json": {}, + } + if model_config.parameters.get("response_format") in ["json_object", "JSON"]: + try: + result_dict = json.loads(result_text) + except: + result_dict = {} + outputs.update({"json": result_dict}) yield RunCompletedEvent( run_result=NodeRunResult( status=WorkflowNodeExecutionStatus.SUCCEEDED, diff --git a/web/app/components/workflow/nodes/_base/components/variable/utils.ts b/web/app/components/workflow/nodes/_base/components/variable/utils.ts index 969bdf2dd5..234d9e3c5d 100644 --- a/web/app/components/workflow/nodes/_base/components/variable/utils.ts +++ b/web/app/components/workflow/nodes/_base/components/variable/utils.ts @@ -139,7 +139,16 @@ const formatItem = ( } case BlockEnum.LLM: { - res.vars = LLM_OUTPUT_STRUCT + res.vars = [ + ...LLM_OUTPUT_STRUCT, + ...(['json_object', 'JSON'].includes(data.model?.completion_params?.response_format) + ? [{ + variable: 'json', + type: VarType.object, + }] + : []), + ] + break } diff --git a/web/app/components/workflow/nodes/llm/panel.tsx b/web/app/components/workflow/nodes/llm/panel.tsx index e1264ad89e..5e1c5f1e1d 100644 --- a/web/app/components/workflow/nodes/llm/panel.tsx +++ b/web/app/components/workflow/nodes/llm/panel.tsx @@ -289,6 +289,14 @@ const Panel: FC> = ({ type='string' description={t(`${i18nPrefix}.outputVars.output`)} /> + {['json_object', 'JSON'].includes(model?.completion_params?.response_format) + && ( + + )} {isShowSingleRun && ( diff --git a/web/i18n/de-DE/workflow.ts b/web/i18n/de-DE/workflow.ts index 74bea2b85e..31b8a80c45 100644 --- a/web/i18n/de-DE/workflow.ts +++ b/web/i18n/de-DE/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'Generierter Inhalt', usage: 'Nutzungsinformationen des Modells', + json: 'Generierter Inhalt JSON', }, singleRun: { variable: 'Variable', diff --git a/web/i18n/en-US/workflow.ts b/web/i18n/en-US/workflow.ts index c81d9f8e94..87660c48f9 100644 --- a/web/i18n/en-US/workflow.ts +++ b/web/i18n/en-US/workflow.ts @@ -412,6 +412,7 @@ const translation = { outputVars: { output: 'Generate content', usage: 'Model Usage Information', + json: 'Generate content JSON', }, singleRun: { variable: 'Variable', diff --git a/web/i18n/es-ES/workflow.ts b/web/i18n/es-ES/workflow.ts index 0ee1b0a223..fa24389de5 100644 --- a/web/i18n/es-ES/workflow.ts +++ b/web/i18n/es-ES/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'Generar contenido', usage: 'Información de uso del modelo', + json: 'Generar contenido JSON', }, singleRun: { variable: 'Variable', diff --git a/web/i18n/fa-IR/workflow.ts b/web/i18n/fa-IR/workflow.ts index 71fd48d5c2..e5e88537c3 100644 --- a/web/i18n/fa-IR/workflow.ts +++ b/web/i18n/fa-IR/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'تولید محتوا', usage: 'اطلاعات استفاده از مدل', + json: 'تولید محتوا JSON', }, singleRun: { variable: 'متغیر', diff --git a/web/i18n/fr-FR/workflow.ts b/web/i18n/fr-FR/workflow.ts index c345eb32b9..d9ad3fba81 100644 --- a/web/i18n/fr-FR/workflow.ts +++ b/web/i18n/fr-FR/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'Contenu généré', usage: 'Informations sur l\'utilisation du modèle', + json: 'Contenu généré JSON', }, singleRun: { variable: 'Variable', diff --git a/web/i18n/hi-IN/workflow.ts b/web/i18n/hi-IN/workflow.ts index c0e679ab8c..8603ac1afa 100644 --- a/web/i18n/hi-IN/workflow.ts +++ b/web/i18n/hi-IN/workflow.ts @@ -412,6 +412,7 @@ const translation = { outputVars: { output: 'सामग्री उत्पन्न करें', usage: 'मॉडल उपयोग जानकारी', + json: 'सामग्री उत्पन्न करें JSON', }, singleRun: { variable: 'वेरिएबल', diff --git a/web/i18n/it-IT/workflow.ts b/web/i18n/it-IT/workflow.ts index 58d3455cd0..fde538d29b 100644 --- a/web/i18n/it-IT/workflow.ts +++ b/web/i18n/it-IT/workflow.ts @@ -416,6 +416,7 @@ const translation = { outputVars: { output: 'Genera contenuto', usage: 'Informazioni sull\'utilizzo del modello', + json: 'Genera contenuto JSON', }, singleRun: { variable: 'Variabile', diff --git a/web/i18n/ja-JP/workflow.ts b/web/i18n/ja-JP/workflow.ts index cb577f97c3..fecfc88347 100644 --- a/web/i18n/ja-JP/workflow.ts +++ b/web/i18n/ja-JP/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'コンテンツを生成', usage: 'モデルの使用情報', + json: 'コンテンツを生成 JSON', }, singleRun: { variable: '変数', diff --git a/web/i18n/ko-KR/workflow.ts b/web/i18n/ko-KR/workflow.ts index 17297f1273..9f579b244c 100644 --- a/web/i18n/ko-KR/workflow.ts +++ b/web/i18n/ko-KR/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: '생성된 내용', usage: '모델 사용 정보', + json: '생성된 내용 JSON', }, singleRun: { variable: '변수', diff --git a/web/i18n/pl-PL/workflow.ts b/web/i18n/pl-PL/workflow.ts index c47f4ea7d0..352afdf763 100644 --- a/web/i18n/pl-PL/workflow.ts +++ b/web/i18n/pl-PL/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'Generowana treść', usage: 'Informacje o użyciu modelu', + json: 'Generowana treść JSON', }, singleRun: { variable: 'Zmienna', diff --git a/web/i18n/pt-BR/workflow.ts b/web/i18n/pt-BR/workflow.ts index 3d2b3fe8f0..5b54a7af1f 100644 --- a/web/i18n/pt-BR/workflow.ts +++ b/web/i18n/pt-BR/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'Conteúdo gerado', usage: 'Informações de uso do modelo', + json: 'Conteúdo gerado JSON', }, singleRun: { variable: 'Variável', diff --git a/web/i18n/ro-RO/workflow.ts b/web/i18n/ro-RO/workflow.ts index b4aa035274..9666cd3b0b 100644 --- a/web/i18n/ro-RO/workflow.ts +++ b/web/i18n/ro-RO/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'Conținut generat', usage: 'Informații de utilizare a modelului', + json: 'Conținut generat JSON', }, singleRun: { variable: 'Variabilă', diff --git a/web/i18n/ru-RU/workflow.ts b/web/i18n/ru-RU/workflow.ts index d22ae7bf4f..c9444a15c4 100644 --- a/web/i18n/ru-RU/workflow.ts +++ b/web/i18n/ru-RU/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'Создать контент', usage: 'Информация об использовании модели', + json: 'Создать контент JSON', }, singleRun: { variable: 'Переменная', diff --git a/web/i18n/sl-SI/workflow.ts b/web/i18n/sl-SI/workflow.ts index e4a71ddac3..b17e91573b 100644 --- a/web/i18n/sl-SI/workflow.ts +++ b/web/i18n/sl-SI/workflow.ts @@ -348,6 +348,7 @@ const translation = { outputVars: { output: 'Generirana vsebina', usage: 'Podatki o uporabi modela', + json: 'Generirana vsebina JSON', }, singleRun: { variable: 'Spremenljivka', diff --git a/web/i18n/th-TH/workflow.ts b/web/i18n/th-TH/workflow.ts index 5cf4ad9e16..fc3506724f 100644 --- a/web/i18n/th-TH/workflow.ts +++ b/web/i18n/th-TH/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'สร้างเนื้อหา', usage: 'ข้อมูลการใช้งานรุ่น', + json: 'สร้างเนื้อหา JSON', }, singleRun: { variable: 'ตัวแปร', diff --git a/web/i18n/tr-TR/workflow.ts b/web/i18n/tr-TR/workflow.ts index 0ba1206b86..5661f73155 100644 --- a/web/i18n/tr-TR/workflow.ts +++ b/web/i18n/tr-TR/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'İçerik Üret', usage: 'Model Kullanım Bilgileri', + json: 'İçerik Üret JSON', }, singleRun: { variable: 'Değişken', diff --git a/web/i18n/uk-UA/workflow.ts b/web/i18n/uk-UA/workflow.ts index a4b832660d..d220dbb651 100644 --- a/web/i18n/uk-UA/workflow.ts +++ b/web/i18n/uk-UA/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'Генерований вміст', usage: 'Інформація про використання моделі', + json: 'Генерований вміст JSON', }, singleRun: { variable: 'Змінна', diff --git a/web/i18n/vi-VN/workflow.ts b/web/i18n/vi-VN/workflow.ts index db56350daf..21986cc5ad 100644 --- a/web/i18n/vi-VN/workflow.ts +++ b/web/i18n/vi-VN/workflow.ts @@ -399,6 +399,7 @@ const translation = { outputVars: { output: 'Nội dung được tạo', usage: 'Thông tin sử dụng mô hình', + json: 'Nội dung được tạo JSON', }, singleRun: { variable: 'Biến', diff --git a/web/i18n/zh-Hans/workflow.ts b/web/i18n/zh-Hans/workflow.ts index c9bccebcea..7cab75d150 100644 --- a/web/i18n/zh-Hans/workflow.ts +++ b/web/i18n/zh-Hans/workflow.ts @@ -413,6 +413,7 @@ const translation = { outputVars: { output: '生成内容', usage: '模型用量信息', + json: '生成内容 JSON', }, singleRun: { variable: '变量', diff --git a/web/i18n/zh-Hant/workflow.ts b/web/i18n/zh-Hant/workflow.ts index 1e4fd2ef21..b5ec10cfa0 100644 --- a/web/i18n/zh-Hant/workflow.ts +++ b/web/i18n/zh-Hant/workflow.ts @@ -401,6 +401,7 @@ const translation = { outputVars: { output: '生成內容', usage: '模型用量信息', + json: '生成內容 JSON', }, singleRun: { variable: '變量',