parse_chat_completion drops custom tool calls
维护者通常 1 天内回复
还没有人认领这个 Issue。
评估
调研方向
Start in src/openai/lib/_parsing/_completions.py, at the custom branch that only logs a warning and the tool-call list typed as ParsedFunctionToolCall. Run the snippet in the issue to confirm the parsed message has tool_calls=None. Done means a custom call appears in the parsed tool_calls and survives model_dump(), with a regression test covering it. The streaming gap is separate and out of scope.
由索引模型根据 Issue 内容生成。
描述
Confirm this is an issue with the Python library and not an underlying OpenAI API
- This is an issue with the Python library
Describe the bug
parse_chat_completion(), which backs client.chat.completions.parse(), drops custom tool calls. when the model calls only a custom tool, the parsed message has tool_calls=None even though the raw completion contains the call. on a turn with both kinds, the function calls are kept and the custom ones are dropped.
root cause, on main @ f6e8480: the custom branch in src/openai/lib/_parsing/_completions.py only logs a warning and never appends the call (L136-L143), and the list it would append to is typed list[ParsedFunctionToolCall] (L117), so no parsed type can hold one.
To Reproduce
- build a chat completion whose message has one custom tool call (no network needed, snippet below)
- pass it through
parse_chat_completion - the raw completion has the call; the parsed message has
tool_calls=None
Code snippets
from openai.types.chat import ChatCompletion
from openai.lib._parsing._completions import parse_chat_completion
completion = ChatCompletion.model_validate({
"id": "chatcmpl-1", "object": "chat.completion", "created": 0, "model": "gpt-5",
"choices": [{
"index": 0, "finish_reason": "tool_calls", "logprobs": None,
"message": {
"role": "assistant", "content": None,
"tool_calls": [{
"id": "call_1", "type": "custom",
"custom": {"name": "code_exec", "input": "print('hi')"},
}],
},
}],
})
print("raw: ", [c.type for c in completion.choices[0].message.tool_calls])
parsed = parse_chat_completion(
response_format=None, input_tools=[{"type": "custom", "custom": {"name": "code_exec"}}],
chat_completion=completion,
)
print("parsed:", parsed.choices[0].message.tool_calls)
output on 3.42.1:
Custom tool calls are not callable. Ignoring tool call: call_1 - code_exec
raw: ['custom']
parsed: None
suggested fix
the diff in #3505 appends the call in that branch. review on that pr found that appending alone is not enough: ParsedChatCompletionMessage.tool_calls is declared as list[ParsedFunctionToolCall], so an appended custom call is dumped as {id, type} and custom.name / custom.input are lost from model_dump(). the complete fix is to widen the parsed tool-call type to a discriminated union of ParsedFunctionToolCall and ChatCompletionMessageCustomToolCall in the generated source of truth, append in this branch, and add a regression test that dumps the whole parsed completion.
streaming is a separate gap: ChoiceDeltaToolCall.type is Optional[Literal["function"]] in 3.42.1, so a streamed custom call fails validation before it reaches this parser.
pr diff: https://github.com/openai/openai-python/pull/3505/files
OS
macOS 26.6.2 (arm64)
Python version
3.13.13
Library version
3.42.1
- 主要语言
- Python
- 星标
- 32.2k
- 派生
- 5.8k
- 平均合并
- 12 小时 29 分钟
- 30 天内合并 PR
- 112
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openai/openai-python 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 76/100
openai/openai-python#4338 ·
维护者通常 1 天内回复
-
bug
难度 2/5 1-3 小时 新手友好度 65/100
openai/openai-python#4337 ·
维护者通常 1 天内回复
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parameters可能已有人在做 @Rewaskc02-lang 于 1 天前认领。 未关闭
难度 2/5 1-3 小时 新手友好度 78/100
openai/openai-python#4311 · 4 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 78/100
openai/openai-python#4310 · 1 条评论 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 82/100
openai/openai-python#4309 · 1 条评论 ·
维护者通常 1 天内回复
查看 openai/openai-python 的全部 Issue
相似的 Issue
-
triage
难度 1/5 1-3 小时 新手友好度 88/100
kornia/kornia-rs#1416 · 1 条评论 ·
维护者通常 2 天内回复
-
ui
难度 2/5 1-3 小时 新手友好度 78/100
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
PolicyEngine/ai-inequality#64 ·
维护者通常 1 天内回复
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over time可能已有人在做 @PabloRoque 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 88/100
pymc-devs/pymc-extras#839 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 76/100
维护者通常 1 天内回复