openai-python icon indicating copy to clipboard operation
openai-python copied to clipboard

import openai openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)

Open Eric0101 opened this issue 1 year ago • 10 comments

Describe the bug

[ERROR][2023-03-04 18:25:20][chat_gpt_bot.py:68] - Invalid URL (POST /v1/chat/completions) Traceback (most recent call last): File "/opt/chatgpt-on-wechat/bot/chatgpt/chat_gpt_bot.py", line 44, in reply_text response = openai.ChatCompletion.create( File "/usr/local/lib/python3.9/site-packages/openai/api_resources/chat_completion.py", line 25, in create return super().create(*args, **kwargs) File "/usr/local/lib/python3.9/site-packages/openai/api_resources/abstract/engine_api_resource.py", line 153, in create response, _, api_key = requestor.request( File "/usr/local/lib/python3.9/site-packages/openai/api_requestor.py", line 226, in request resp, got_stream = self._interpret_response(result, stream) File "/usr/local/lib/python3.9/site-packages/openai/api_requestor.py", line 619, in _interpret_response self._interpret_response_line( File "/usr/local/lib/python3.9/site-packages/openai/api_requestor.py", line 679, in _interpret_response_line raise self.handle_error_response( openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)

To Reproduce

response = openai.ChatCompletion.create(

openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)

Code snippets

response = openai.ChatCompletion.create(

openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)


[root@vps87388579 chatgpt-on-wechat]# pip3 show openai
Name: openai
Version: 0.27.0
Summary: Python client library for the OpenAI API
Home-page: https://github.com/openai/openai-python
Author: OpenAI
Author-email: [email protected]
License: None
Location: /usr/local/lib/python3.9/site-packages
Requires: requests, aiohttp, tqdm
Required-by:

OS

centos 8.6

Python version

3.9

Library version

0.27

Eric0101 avatar Mar 04 '23 10:03 Eric0101

If you're requesting your finetune model, try:

response = openai.Completion.create(

mymusise avatar Mar 04 '23 14:03 mymusise

not finetune model ,i'm request gpt-3-turbo model

Eric0101 avatar Mar 06 '23 06:03 Eric0101

same problem

IvoryF avatar Mar 06 '23 07:03 IvoryF

same problem. The example of official playground has this problem too. The api crashed maybe.

bell99431 avatar Mar 06 '23 10:03 bell99431

This seems to be account related. Some accounts are affected while others are not.

lucifer1004 avatar Mar 06 '23 10:03 lucifer1004

same issue in my case I have a loop that calls the api multiple times, bit backoff retry exception handling, and It only does it a few times, in the loop, but not on every one and it seems very unpredictable

adeolaemmanuelmorren avatar Mar 06 '23 18:03 adeolaemmanuelmorren

I think they moved the endpoint for the new models. They also seemed to have updated the error...

openai.error.InvalidRequestError: This is a chat model and not supported in the v1/completions endpoint. Did you mean to use v1/chat/completions?

So the maybe the API needs to add '/chat' for gpt-3.5-turbo and gpt-3.5-turbo-0301 models? The documentation looks like only those two are supported for 'chat completion' but doesn't state that they are losing the normal endpoint. So 🤷🏻‍♀️

https://platform.openai.com/docs/api-reference/chat/create

jriskin avatar Mar 06 '23 19:03 jriskin

I was able to fix it by updating the openai lib.

pip install --upgrade openai.

Then you can try this:

import openai

completion = openai.ChatCompletion.create(
  model="gpt-3.5-turbo",
  messages=[{"role": "user", "content": "Tell the world about the ChatGPT API in the style of a pirate."}]
)

I got the answer in the official documentation:

https://openai.com/blog/introducing-chatgpt-and-whisper-apis

javff avatar Mar 09 '23 09:03 javff

I've upgraded via pip and still get the same error.

calebtote avatar Mar 14 '23 18:03 calebtote

I've upgraded via pip and still get the same error.

You should change from openai.Completion.create to openai.ChatCompletion.create.

fengerzh avatar Mar 16 '23 05:03 fengerzh

This error is expected if using openai.Completion.create with a chat model. Please use openai.ChatCompletion.create instead. This includes gpt-3.5-turbo and gpt-4 (for those with access).

athyuttamre avatar Mar 17 '23 20:03 athyuttamre

openai.error.InvalidRequestError: This is not a chat model and thus not supported in the v1/chat/completions endpoint. Did you mean to use v1/completions? 问题相反啊!!!!

youning-xx avatar Apr 16 '23 05:04 youning-xx

openai.error.InvalidRequestError: This is not a chat model and thus not supported in the v1/chat/completions endpoint. Did you mean to use v1/completions? 问题相反啊!!!!

我也是一样问题。。你解决了吗。

GayITHub avatar Apr 16 '23 13:04 GayITHub

image

peefau avatar May 14 '23 06:05 peefau

我遇到了同样的问题?有人知道怎么解决吗?

peefau avatar May 14 '23 06:05 peefau