chatbot - 使用 gpt 3.5 时出现 Few-shot 提示错误

标签 chatbot openai-api gpt-3 chatgpt-api

我正在尝试使用 messages 参数而不是 prompt 参数来训练带有少量提示的 GPT 3.5 模型。尽管 OpenAI 文档中明确提到我们可以通过这种方式训练模型,但它还是会抛出错误。

import openai

conversation=[
        {"role": "system", "content": "You are a helpful assistant."},
        {"role": "user", "content": "Who won the world series in 2020?"},
        {"role": "assistant", "content": "The Los Angeles Dodgers won the World Series in 2020."},
    ]

def askGPT(question):
    conversation.append({"role": "user", "content": question})
    openai.api_key = "openai key"
    response = openai.Completion.create(
        model = "gpt-3.5-turbo",
        messages = conversation,
        temperature = 0.6
        #max_tokens = 150,
    )
    #conversation.append({"role": "assistant","content":response})
    #print(response)
    #print(response["choices"][0]["message"]["content"])

    
    conversation.append({"role": "assistant", "content": response.choices[0].message.content})
    print(response.choices[0].message.content)

def main():
    while True:
        print('GPT: Ask me a question\n')
        myQn = input()
        askGPT(myQn)
        print('\n')


main()

错误:

openai.error.InvalidRequestError: Unrecognized request argument supplied: messages

我尝试在“响应”内向模型提供“对话”,但它似乎不起作用。

最佳答案

您在聊天完成完成之间犯了一个错误。请参阅文档。

完成:https://platform.openai.com/docs/api-reference/completions/create

聊天完成:https://platform.openai.com/docs/api-reference/chat/create

关于chatbot - 使用 gpt 3.5 时出现 Few-shot 提示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76502113/

相关文章:

json - 为什么 OpenAI 图像生成 Api 在 Unity 中返回 400 错误请求?

r - 如何避免 R 中 OpenAI API 的字数限制?

artificial-intelligence - 重铸.ai : TypeError: Cannot read property 'attachment' of undefined

javascript - 我可以在 Firebase 上托管 Facebook 聊天机器人吗?

openai-api - 如何提示 chatGPT API 给出完全机器可读的响应,而没有多余的注释?

python - 使用 GPT API 创建多消息对话

python - 属性错误: module transformers has no attribute TFGPTNeoForCausalLM

node.js - Facebook 开发者问题 - 'URL couldn' 待验证。响应与预期挑战不符'

artificial-intelligence - 最新的(开源)聊天机器人/假人工智能?

openai-api - OpenAI API错误: Why do I still get the "module ' openai' has no attribute 'ChatCompletion' "error after I upgraded the OpenAI package and Python?