openai-python
openai-python copied to clipboard
import openai openai.error.InvalidRequestError: Invalid URL (POST /v1/chat/completions)
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
If you're requesting your finetune model, try:
response = openai.Completion.create(
not finetune model ,i'm request gpt-3-turbo model
same problem
same problem. The example of official playground has this problem too. The api crashed maybe.
This seems to be account related. Some accounts are affected while others are not.
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
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
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
I've upgraded via pip and still get the same error.
I've upgraded via pip and still get the same error.
You should change from openai.Completion.create
to openai.ChatCompletion.create
.
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).
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? 问题相反啊!!!!
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? 问题相反啊!!!!
我也是一样问题。。你解决了吗。
我遇到了同样的问题?有人知道怎么解决吗?