Skip to content

Commit

Permalink
ai: Properly forward non-successful responses from non-streaming chat (
Browse files Browse the repository at this point in the history
  • Loading branch information
elprans authored Jun 24, 2024
1 parent 16193df commit d142189
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions edb/server/protocol/ai_ext.py
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,13 @@ async def _start_openai_like_chat(
}
)

if result.status_code >= 400:
await result.aread()
raise AIProviderError(
f"API call to generate chat completions failed with status "
f"{result.status_code}: {result.text}"
)

response.status = http.HTTPStatus.OK
response_text = result.json()["choices"][0]["message"]["content"]
response.content_type = b'application/json'
Expand Down Expand Up @@ -795,6 +802,13 @@ async def _start_anthropic_chat(
}
)

if result.status_code >= 400:
await result.aread()
raise AIProviderError(
f"API call to generate chat completions failed with status "
f"{result.status_code}: {result.text}"
)

response.status = http.HTTPStatus.OK
response.content_type = b'application/json'
response_text = result.json()["content"][0]["text"]
Expand Down

0 comments on commit d142189

Please sign in to comment.