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'"
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?"
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()