Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

Typing: when stream is completed, delta in ChatCompletionChunk from azure openai is None; should be ChoiceDelta

未关闭
#1,677 8 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

@LuminaX-alt 已经在做这个了。

开始于 2025年8月2日。

  • #28 来自 @LuminaX-alt —— 未关闭

评估

难度
3/5
预计耗时
1-2 天
新手友好度
40/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
azure, python
领域
api

调研方向

首先复现 issue 中所示的异步流式调用,并检查针对 Azure OpenAI 最后一个 chunk 的 ChatCompletionChunk、Choice 和 ChoiceDelta 处理。验证已完成的 stream 产生的是 ChoiceDelta,而不是 delta=None,同时保持预期的 completion response 行为。

由索引模型根据 Issue 内容生成。

描述

api bug
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

When streaming from azure open ai API the delta of the choice is None. In the python open ai client v1.42.0 delta is type ChoiceDelta i.e. not None.

To Reproduce

Run this code in line with

    completion = await self._client.chat.completions.create(
            model=self.deployment.name,
            messages=cast(list[ChatCompletionMessageParam], messages),
            stream=True,
            temperature=temperature,
        )

    async for response_chunk in completion:
        ...

The types are:
response_chunk: ChatCompletionChunk
response_chunk.choices: list[Choice]
response_chunk.choices[0].delta: ChoiceDelta

The response from azure open ai API returns delta=Nonewhen stream ends

Response example:

Choice(delta=None, finish_reason=None ...........)
Code snippets

No response

OS

linux, ubuntu 20.04

Python version

3.12.1

Library version

openai v 1.42.0

主要语言
Python
星标
31.8k
派生
8k
平均合并
14 小时 16 分钟
30 天内合并 PR
151

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

openai/openai-python 的其他 Issue

查看 openai/openai-python 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。