This commit is contained in:
jiangbo721 2025-03-21 12:48:36 +08:00 committed by GitHub
commit 139e4870b1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
23 changed files with 50 additions and 3 deletions

View File

@ -191,8 +191,18 @@ class LLMNode(BaseNode[LLMNodeData]):
# deduct quota # deduct quota
self.deduct_llm_quota(tenant_id=self.tenant_id, model_instance=model_instance, usage=usage) self.deduct_llm_quota(tenant_id=self.tenant_id, model_instance=model_instance, usage=usage)
break 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( yield RunCompletedEvent(
run_result=NodeRunResult( run_result=NodeRunResult(
status=WorkflowNodeExecutionStatus.SUCCEEDED, status=WorkflowNodeExecutionStatus.SUCCEEDED,

View File

@ -139,7 +139,16 @@ const formatItem = (
} }
case BlockEnum.LLM: { 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 break
} }

View File

@ -289,6 +289,14 @@ const Panel: FC<NodePanelProps<LLMNodeType>> = ({
type='string' type='string'
description={t(`${i18nPrefix}.outputVars.output`)} description={t(`${i18nPrefix}.outputVars.output`)}
/> />
{['json_object', 'JSON'].includes(model?.completion_params?.response_format)
&& (
<VarItem
name="json"
type="object"
description={t(`${i18nPrefix}.outputVars.json`)}
/>
)}
</> </>
</OutputVars> </OutputVars>
{isShowSingleRun && ( {isShowSingleRun && (

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Generierter Inhalt', output: 'Generierter Inhalt',
usage: 'Nutzungsinformationen des Modells', usage: 'Nutzungsinformationen des Modells',
json: 'Generierter Inhalt JSON',
}, },
singleRun: { singleRun: {
variable: 'Variable', variable: 'Variable',

View File

@ -412,6 +412,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Generate content', output: 'Generate content',
usage: 'Model Usage Information', usage: 'Model Usage Information',
json: 'Generate content JSON',
}, },
singleRun: { singleRun: {
variable: 'Variable', variable: 'Variable',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Generar contenido', output: 'Generar contenido',
usage: 'Información de uso del modelo', usage: 'Información de uso del modelo',
json: 'Generar contenido JSON',
}, },
singleRun: { singleRun: {
variable: 'Variable', variable: 'Variable',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'تولید محتوا', output: 'تولید محتوا',
usage: 'اطلاعات استفاده از مدل', usage: 'اطلاعات استفاده از مدل',
json: 'تولید محتوا JSON',
}, },
singleRun: { singleRun: {
variable: 'متغیر', variable: 'متغیر',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Contenu généré', output: 'Contenu généré',
usage: 'Informations sur l\'utilisation du modèle', usage: 'Informations sur l\'utilisation du modèle',
json: 'Contenu généré JSON',
}, },
singleRun: { singleRun: {
variable: 'Variable', variable: 'Variable',

View File

@ -412,6 +412,7 @@ const translation = {
outputVars: { outputVars: {
output: 'सामग्री उत्पन्न करें', output: 'सामग्री उत्पन्न करें',
usage: 'मॉडल उपयोग जानकारी', usage: 'मॉडल उपयोग जानकारी',
json: 'सामग्री उत्पन्न करें JSON',
}, },
singleRun: { singleRun: {
variable: 'वेरिएबल', variable: 'वेरिएबल',

View File

@ -416,6 +416,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Genera contenuto', output: 'Genera contenuto',
usage: 'Informazioni sull\'utilizzo del modello', usage: 'Informazioni sull\'utilizzo del modello',
json: 'Genera contenuto JSON',
}, },
singleRun: { singleRun: {
variable: 'Variabile', variable: 'Variabile',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'コンテンツを生成', output: 'コンテンツを生成',
usage: 'モデルの使用情報', usage: 'モデルの使用情報',
json: 'コンテンツを生成 JSON',
}, },
singleRun: { singleRun: {
variable: '変数', variable: '変数',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: '생성된 내용', output: '생성된 내용',
usage: '모델 사용 정보', usage: '모델 사용 정보',
json: '생성된 내용 JSON',
}, },
singleRun: { singleRun: {
variable: '변수', variable: '변수',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Generowana treść', output: 'Generowana treść',
usage: 'Informacje o użyciu modelu', usage: 'Informacje o użyciu modelu',
json: 'Generowana treść JSON',
}, },
singleRun: { singleRun: {
variable: 'Zmienna', variable: 'Zmienna',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Conteúdo gerado', output: 'Conteúdo gerado',
usage: 'Informações de uso do modelo', usage: 'Informações de uso do modelo',
json: 'Conteúdo gerado JSON',
}, },
singleRun: { singleRun: {
variable: 'Variável', variable: 'Variável',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Conținut generat', output: 'Conținut generat',
usage: 'Informații de utilizare a modelului', usage: 'Informații de utilizare a modelului',
json: 'Conținut generat JSON',
}, },
singleRun: { singleRun: {
variable: 'Variabilă', variable: 'Variabilă',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Создать контент', output: 'Создать контент',
usage: 'Информация об использовании модели', usage: 'Информация об использовании модели',
json: 'Создать контент JSON',
}, },
singleRun: { singleRun: {
variable: 'Переменная', variable: 'Переменная',

View File

@ -348,6 +348,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Generirana vsebina', output: 'Generirana vsebina',
usage: 'Podatki o uporabi modela', usage: 'Podatki o uporabi modela',
json: 'Generirana vsebina JSON',
}, },
singleRun: { singleRun: {
variable: 'Spremenljivka', variable: 'Spremenljivka',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'สร้างเนื้อหา', output: 'สร้างเนื้อหา',
usage: 'ข้อมูลการใช้งานรุ่น', usage: 'ข้อมูลการใช้งานรุ่น',
json: 'สร้างเนื้อหา JSON',
}, },
singleRun: { singleRun: {
variable: 'ตัวแปร', variable: 'ตัวแปร',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'İçerik Üret', output: 'İçerik Üret',
usage: 'Model Kullanım Bilgileri', usage: 'Model Kullanım Bilgileri',
json: 'İçerik Üret JSON',
}, },
singleRun: { singleRun: {
variable: 'Değişken', variable: 'Değişken',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Генерований вміст', output: 'Генерований вміст',
usage: 'Інформація про використання моделі', usage: 'Інформація про використання моделі',
json: 'Генерований вміст JSON',
}, },
singleRun: { singleRun: {
variable: 'Змінна', variable: 'Змінна',

View File

@ -399,6 +399,7 @@ const translation = {
outputVars: { outputVars: {
output: 'Nội dung được tạo', output: 'Nội dung được tạo',
usage: 'Thông tin sử dụng mô hình', usage: 'Thông tin sử dụng mô hình',
json: 'Nội dung được tạo JSON',
}, },
singleRun: { singleRun: {
variable: 'Biến', variable: 'Biến',

View File

@ -413,6 +413,7 @@ const translation = {
outputVars: { outputVars: {
output: '生成内容', output: '生成内容',
usage: '模型用量信息', usage: '模型用量信息',
json: '生成内容 JSON',
}, },
singleRun: { singleRun: {
variable: '变量', variable: '变量',

View File

@ -401,6 +401,7 @@ const translation = {
outputVars: { outputVars: {
output: '生成內容', output: '生成內容',
usage: '模型用量信息', usage: '模型用量信息',
json: '生成內容 JSON',
}, },
singleRun: { singleRun: {
variable: '變量', variable: '變量',