anmar
1
Currently working on a project with GPT completions and it worked perfectly fine with the model set as “text-davinci-003” but when I changed it to “gpt-4” it stopped working and I’m getting the error I set in my code. BTW I have the beta invite to gpt 4 api.
Here’s a snippet from my code:
response = requests.post("https://api.openai.com/v1/completions", json={
"model": "gpt-4",
"prompt": prompt,
"max_tokens": 8000,
"n": 1,
"stop": None,
"temperature": 0.3,
}, headers={
"Content-Type": "application/json",
"Authorization": f"Bearer {API_KEY}"
})
response_data = response.json()
if 'choices' in response_data:
definition = response_data['choices'][0]['text'].strip()
else:
definition = "Error: Could not get a translation."
I believe GPT 4 isn’t available yet for regular completions, only chat completions.
If you reformat your request to have the format of the Chat endpoint, then it should work!
There are a few notes in the documentation about this.
Hope that helps!
1 Like
anmar
3
I followed ur advice and im still getting the same error.
response = requests.post("https://api.openai.com/v1/chat/completions", json={
"model": "gpt-4",
"prompt": prompt,
Is there anything else I’m doing wrong? I’ve been looking through documentation and I’m pretty sure I’m doing everything right.
sps
4
Welcome to the community @anmar
GPT-4 works with the ChatCompletions endpoint instead of the completions endpoint.
These docs on chat completions will be helpful in migrating to the GPT-4 model.
2 Likes
Hi
If you are getting the same error you may not have access to gpt-4. I don’t have access and I get that error too via the same chat/completions end point.
The model: gpt-4 does not exist
anmar
6
thank you this fixed my problem! keep a lookout for a post in the next few days of my project!
1 Like
srolly
7
I am getting same error , I have chatgpt plus too, still this api is not working
getting error in translating text