Skip to content

Conversation

@v-49
Copy link

@v-49 v-49 commented Nov 10, 2025

代码在尝试访问 chunk.choices[0] 之前,没有检查 chunk.choices 列表是否为空。

当你使用 client.chat.completions.create 并且设置 stream=True 时,API会返回一个数据流(generator)。这个流会产生多个 chunk(数据块)。

大多数 chunk 会包含 choices 列表,列表中的 delta.content 包含了模型新生成的词。

但是,并非所有 chunk 都保证 choices 列表里有内容。例如,流的最后一个 chunk(或者某些中间的元数据 chunk)可能是一个 choices 为空列表 [] 的对象。

代码在尝试访问 chunk.choices[0] 之前,没有检查 chunk.choices 列表是否为空。

当你使用 client.chat.completions.create 并且设置 stream=True 时,API会返回一个数据流(generator)。这个流会产生多个 chunk(数据块)。

大多数 chunk 会包含 choices 列表,列表中的 delta.content 包含了模型新生成的词。

但是,并非所有 chunk 都保证 choices 列表里有内容。例如,流的最后一个 chunk(或者某些中间的元数据 chunk)可能是一个 choices 为空列表 [] 的对象。
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant