OpenAI Completions API 响应内容不完整

问题描述 投票:0回答:1

我有一个使用官方 OpenAI 库的 python 脚本,我用它来根据我告诉它的特定配方生成一些脚本。

我认为问题是我没有流式传输响应,所以现在它也使用了stream=True选项。

现在,如果响应很大(超过约 515 个字符),则响应会被削减一半。

有什么想法吗?

这是一个片段(不是真正的代码)

    response = client.chat.completions.create(
    model="gpt-4",
    messages=[
        {
            "role": "system",
            "content": "You will be provided with some instructions for logic to implement in windows Batch"
                       "Please make it machine readable without explanations"
        },
        {
            "role": "user",
            "content": f'instructions: {instructions}'
        }
    ],
    temperature=0,
    max_tokens=512,
    top_p=1,
    stream=True
)
command = ''
try:
    for chunk in response:
        command += chunk.choices[0].delta.content
except:
    pass
print(command)
openai-api chatgpt-api
1个回答
0
投票

更新 - 看起来像是 GPT 4 的问题, 对我来说,解决方案就是切换到 model="gpt-3.5-turbo-1106"

© www.soinside.com 2019 - 2024. All rights reserved.