Open
Conversation
代码在尝试访问 chunk.choices[0] 之前,没有检查 chunk.choices 列表是否为空。 当你使用 client.chat.completions.create 并且设置 stream=True 时,API会返回一个数据流(generator)。这个流会产生多个 chunk(数据块)。 大多数 chunk 会包含 choices 列表,列表中的 delta.content 包含了模型新生成的词。 但是,并非所有 chunk 都保证 choices 列表里有内容。例如,流的最后一个 chunk(或者某些中间的元数据 chunk)可能是一个 choices 为空列表 [] 的对象。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
代码在尝试访问 chunk.choices[0] 之前,没有检查 chunk.choices 列表是否为空。
当你使用 client.chat.completions.create 并且设置 stream=True 时,API会返回一个数据流(generator)。这个流会产生多个 chunk(数据块)。
大多数 chunk 会包含 choices 列表,列表中的 delta.content 包含了模型新生成的词。
但是,并非所有 chunk 都保证 choices 列表里有内容。例如,流的最后一个 chunk(或者某些中间的元数据 chunk)可能是一个 choices 为空列表 [] 的对象。