jvink
1
Hi all,
I’m trying to setup the chatGPT API, however I’m getting the following error:
InvalidRequestError : Invalid URL (POST /v1/chat/completions/engines/gpt-3.5-turbo/chat/completions
I’m using the following code:
messages = [
{"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."},
{"role": "user", "content": "Where was it played?"}
]
response = openai.ChatCompletion.create(
engine="gpt-3.5-turbo",
messages=messages)
Any ideas what I could be doing wrong
UPDATE
engine was supposed to be model
1 Like
/v1/chat/completions/engines/gpt-3.5-turbo/chat/completions
Is completely wrong. Maybe try updating the openai module?
1 Like
jvink
3
I’m on openai version 0.27.0, I believe this is the latest one right? I’ll try reinstalling it
UPDATE:
Tried reinstalling it with no avail… Anyone has suggestions?
You need to use …
‘https://api.openai.com/v1/chat/completions’
… and send a model parameter.
I’m thinking the latest OpenAI module likely has it… I think 0.27 is old?
jvink
5
Thanks for the reply, but how do I use the link you provided? Should I change openai.api_base? I’m fairly new to this. To add, the error now is: InvalidRequestError : Invalid URL (POST /v1/engines/gpt-3.5-turbo/chat/completions), which is slightly different from before
PS. I checked on the openai github and 0.27.0 is the latest version
1 Like
How big is your file? Could you show all of your code, including the imports?
1 Like
As per PaulBellow’s suggestion, try changing the key engine to model.
messages = [
{"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."},
{"role": "user", "content": "Where was it played?"}
]
response = openai.ChatCompletion.create(
model="gpt-3.5-turbo",
messages=messages)
Slightly confusing interface change, if you ask me.
2 Likes
jvink
8
Hi,
Changing the engine to model worked. Thank you all!
1 Like
5km
9
I got the same error when request the API “/v1/chat/completions”,have you solve the error?
Hi,
This code resolved the issue for me.
import requests
import openai
messages = [
{“role”: “user”, “content”: “What is you name?”}
]
url = ‘https://api.openai.com/v1/chat/completions’
headers = {“Authorization”: f"Bearer {api_key}"}
data = {‘model’: ‘gpt-3.5-turbo’, ‘messages’: messages}
requests.post(url, headers=headers, json=data).json()