fix(converter): 清洗 schema 中的 enum 以适配 Gemini OpenAPI TYPE_STRING 校验限制 - #419
Open
FloatingDream528 wants to merge 1 commit into
Open
FloatingDream528 wants to merge 1 commit into
FloatingDream528 wants to merge 1 commit into
Conversation
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
修复问题 / Problem
在通过 OpenAI 格式调用 Gemini 模型并传递工具定义(Tool Definitions)或结构化输出 Schema 时,部分客户端(如 Codex、LangChain、以及自定义 Schema)可能会传入:
{"type": "boolean", "enum": [true, false]}{"type": "integer", "enum": [1, 2, 3]}根据 Google Gemini OpenAPI 的规范,
enum字段中的元素必须严格为字符串(TYPE_STRING)。当传入布尔字面量
true时,Google API 会直接返回 400 校验错误:解决方案 / Solution
在
_clean_schema_for_parameters_json_schema和_clean_schema_for_gemini中增加对enum的规范化清洗:boolean或枚举列表中包含布尔值,移除enum限制(布尔值本身即只有 true/false,避免触发 Gemini 的 TYPE_STRING 校验)。[str(x) for x in enum_val],完全满足 Gemini 的TYPE_STRING规范。测试验证 / Testing
test_clean_schema_removes_boolean_enum_and_stringifies_enum覆盖_clean_schema_for_parameters_json_schema与_clean_schema_for_gemini。