parse_chat_completion drops custom tool calls

オープン
#4,235 コメント 6 件 リアクション 0 件 担当者 0 名 GitHub で見る

メンテナーはふだん 1 日以内に返信

まだ誰も着手していません。

評価

難易度
3/5
見積もり時間
1〜2日
初心者へのやさしさ
45/100
issue の種類
バグ
明瞭さ
明確に書かれている
活発さ
活発
技術スタック
python
領域
api

調査の方向性

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
  1. build a chat completion whose message has one custom tool call (no network needed, snippet below)
  2. pass it through parse_chat_completion
  3. 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分
マージ済み PR(30日)
112

環境構築

Codespaces で開く

このプロジェクトの開発コンテナを、あなたの GitHub アカウントでブラウザ上に起動します。

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

openai/openai-python のほかの issue

openai/openai-python の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。