An error occurred: module ‘openai‘ has no attribute ‘ChatCompletion‘

题意:发生错误:模块 'openai' 没有属性 'ChatCompletion'

问题背景:

I'm trying to build a discord bot that uses the GPT-4 API to function as a chatbot on discord. I have the most recent version of the OpenAI library but when I run my code it tells me "An error occurred: module 'openai' has no attribute 'ChatCompletion'"

我正在尝试构建一个使用 GPT-4 API 的 Discord 机器人,使其在 Discord 上作为聊天机器人运行。我已经安装了最新版的 OpenAI 库,但当我运行代码时,它提示我“发生错误:模块 'openai' 没有属性 'ChatCompletion'”

I tried uninstalling and reinstalling the OpenAI library, I tried using the completions endpoint and got the error "This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?"

我尝试卸载并重新安装 OpenAI 库,也尝试使用 completions 端点,但收到错误提示:“这是一个聊天模型,不支持 v1/completions 端点。你是否打算使用 v1/chat/completions?”

This is the snippet of code that's giving me issues:

这是导致我问题的代码片段:

async def get_gpt_response(prompt, history):
    history_strings = [f"{message['role']}: {message['content']}" for message in history] # update history format
    chat_prompt = '\n'.join(history_strings + [f"user: {prompt}"])
    
    completions = openai.ChatCompletion.create(
        engine=config["model"],
        prompt=chat_prompt,
        max_tokens=config["max_tokens"],
        n=1,
        temperature=config["temperature"],
    )
    return completions.choices[0].text.strip().split('assistant:', 1)[-1].strip()

问题解决:

Make sure you don’t have a file called “openai.py”

确保你没有一个名为 “openai.py” 的文件

  • 6
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

营赢盈英

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值