parse_chat_completion drops custom tool calls
Maintainer thường phản hồi trong vòng 1 ngày
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 3/5
- Thời gian dự kiến
- 1-2 ngày
- Mức phù hợp với người mới
- 45/100
Hướng nghiên cứu
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.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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
- Ngôn ngữ chính
- Python
- Star
- 32.2k
- Fork
- 5.8k
- Merge trung bình
- 12 giờ 29 phút
- Pull request đã merge (30 ngày)
- 112
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của openai/openai-python
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
openai/openai-python#4338 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
openai/openai-python#4337 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
`BaseClient._prepare_url()` corrupts relative endpoint URLs when `base_url` contains query parametersCó thể đã có người làm @Rewaskc02-lang đã nhận 1 ngày trước. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openai/openai-python#4311 · 4 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
openai/openai-python#4310 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
openai/openai-python#4309 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của openai/openai-python
Issue tương tự
-
triage
Độ khó 1/5 1-3 giờ Mức phù hợp với người mới 88/100
kornia/kornia-rs#1416 · 1 bình luận ·
Maintainer thường phản hồi trong vòng 2 ngày
-
ui
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
PolicyEngine/ai-inequality#64 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
LinearGaussianStateSpace.dist splits states and observations wrongly when the transition varies over timeCó thể đã có người làm @PabloRoque đã nhận hôm nay. Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
pymc-devs/pymc-extras#839 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
Maintainer thường phản hồi trong vòng 1 ngày