Skip to content

Added helpful error message telling user to use ChatCompletion #258

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions openai/api_requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,6 +340,10 @@ def handle_error_response(self, rbody, rcode, resp, rheaders, stream_error=False

if "internal_message" in error_data:
error_data["message"] += "\n\n" + error_data["internal_message"]
if "Did you mean to use v1/chat/completions?" in error_data["message"]:
error_data["message"] = "Please use ChatCompletion instead of Completion when using the"\
"'gpt-3.5-turbo' models. For more information see "\
"https://platform.openai.com/docs/guides/chat/introduction."

util.log_info(
"OpenAI API error received",
Expand Down
7 changes: 7 additions & 0 deletions openai/tests/test_endpoints.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,13 @@ def test_timeout_raises_error():
request_timeout=0.01,
)

def test_calling_chat_completion_incorrectly_raises_helpful_error():
with pytest.raises(error.InvalidRequestError) as excinfo:
openai.Completion.create(
prompt="test",
model="gpt-3.5-turbo",
)
assert "ChatCompletion" in str(excinfo.value)

def test_timeout_does_not_error():
# A query that should be fast
Expand Down