Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
feat: Add response format support to GLM-4 (#12252)
丹枫染秋色7c1961e618b7
diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-0520.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-0520.yamlindex 035d9881ebc..bf1dad81fee 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-0520.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-0520.yaml@@ -47,6 +47,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0.1'output: '0.1'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-air.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-air.yamlindex c3ee76141d9..a88779ed138 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-air.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-air.yaml@@ -47,6 +47,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0.001'output: '0.001'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-airx.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-airx.yamlindex 1926db7ac38..868dab92421 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-airx.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-airx.yaml@@ -47,6 +47,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0.01'output: '0.01'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-flash.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-flash.yamlindex e54b5de4a12..5ee67aadef8 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-flash.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-flash.yaml@@ -47,6 +47,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0'output: '0'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-flashx.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-flashx.yamlindex 724fe48909b..abd95a3a9a5 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-flashx.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm-4-flashx.yaml@@ -47,6 +47,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0'output: '0'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4.yamlindex e1eb13df3db..127f81c5ad7 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4.yaml@@ -47,6 +47,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0.1'output: '0.1'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4_long.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4_long.yamlindex c0c4e04d378..ebcb7b4f78d 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4_long.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4_long.yaml@@ -49,6 +49,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0.001'output: '0.001'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4_plus.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4_plus.yamlindex c4f26f8ba93..7dd113c06f4 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4_plus.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4_plus.yaml@@ -47,6 +47,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0.05'output: '0.05'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v.yamlindex 0d99f89cb80..ceeeacced24 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v.yaml@@ -45,6 +45,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0.05'output: '0.05'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v_flash.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v_flash.yamlindex c2047b2cd32..9e3a7f203d9 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v_flash.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v_flash.yaml@@ -45,6 +45,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0.00'output: '0.00'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v_plus.yaml b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v_plus.yamlindex 5cd0e16b0ee..3aa981deff6 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v_plus.yaml+++ b/api/core/model_runtime/model_providers/zhipuai/llm/glm_4v_plus.yaml@@ -46,6 +46,18 @@ parameter_rules:help:zh_Hans: 模型内置了互联网搜索服务,该参数控制模型在生成文本时是否参考使用互联网搜索结果。启用互联网搜索,模型会将搜索结果作为文本生成过程中的参考信息,但模型会基于其内部逻辑“自行判断”是否使用互联网搜索结果。en_US: The model has a built-in Internet search service. This parameter controls whether the model refers to Internet search results when generating text. When Internet search is enabled, the model will use the search results as reference information in the text generation process, but the model will "judge" whether to use Internet search results based on its internal logic.+ - name: response_format+ label:+ zh_Hans: 回复格式+ en_US: Response Format+ type: string+ help:+ zh_Hans: 指定模型必须输出的格式+ en_US: specifying the format that the model must output+ required: false+ options:+ - text+ - json_objectpricing:input: '0.01'output: '0.01'diff --git a/api/core/model_runtime/model_providers/zhipuai/llm/llm.py b/api/core/model_runtime/model_providers/zhipuai/llm/llm.pyindex eef86cc52c3..6199fbb45e6 100644--- a/api/core/model_runtime/model_providers/zhipuai/llm/llm.py+++ b/api/core/model_runtime/model_providers/zhipuai/llm/llm.py@@ -1,3 +1,4 @@+import jsonfrom collections.abc import Generatorfrom typing import Optional, Union@@ -188,6 +189,23 @@ class ZhipuAILargeLanguageModel(_CommonZhipuaiAI, LargeLanguageModel):else:model_parameters["tools"] = [web_search_params]+ response_format = model_parameters.get("response_format")+ if response_format:+ if response_format == "json_schema":+ json_schema = model_parameters.get("json_schema")+ if not json_schema:+ raise ValueError("Must define JSON Schema when the response format is json_schema")+ try:+ schema = json.loads(json_schema)+ except:+ raise ValueError(f"not correct json_schema format: {json_schema}")+ model_parameters.pop("json_schema")+ model_parameters["response_format"] = {"type": "json_schema", "json_schema": schema}+ else:+ model_parameters["response_format"] = {"type": response_format}+ elif "json_schema" in model_parameters:+ del model_parameters["json_schema"]+if model.startswith("glm-4v"):params = self._construct_glm_4v_parameter(model, new_prompt_messages, model_parameters)else: