Skip to content

Commit

Permalink
feat: forward openai error details (#5) (#6)
Browse files Browse the repository at this point in the history
* Handle OpenAI errors.

(cherry picked from commit 7f766340d77a31ba9670580e5e4d1205c8a326fd)

* Fixes OpenAI error handling.

(cherry picked from commit 1c5d212c092cb234c9072d7edd9032e4b4178e2e)
  • Loading branch information
Oleksii-Klimov authored Oct 19, 2023
1 parent a3191eb commit 238ed39
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 23 deletions.
3 changes: 3 additions & 0 deletions aidial_assistant/application/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import logging

logger = logging.getLogger(__name__)
15 changes: 13 additions & 2 deletions aidial_assistant/application/assistant_application.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
from pathlib import Path

from aidial_sdk import HTTPException
from aidial_sdk.chat_completion.base import ChatCompletion
from aidial_sdk.chat_completion.request import Addon, Request
from aidial_sdk.chat_completion.response import Response
from aiohttp import hdrs
from openai import InvalidRequestError
from openai import InvalidRequestError, OpenAIError

from aidial_assistant.application import logger
from aidial_assistant.application.args import parse_args
from aidial_assistant.application.prompts import (
MAIN_SYSTEM_DIALOG_MESSAGE,
Expand Down Expand Up @@ -112,7 +114,16 @@ async def chat_completion(
)
with response.create_single_choice() as choice:
callback = ServerChainCallback(choice)
await chain.run_chat(history, callback, usage_publisher)
try:
await chain.run_chat(history, callback, usage_publisher)
except OpenAIError as e:
logger.exception("Request processing has failed.")
raise HTTPException(
str(e),
status_code=e.http_status or 500,
code=e.code,
)

choice.set_state(callback.state)

response.set_usage(
Expand Down
21 changes: 0 additions & 21 deletions aidial_assistant/json_stream/parsing_context.py

This file was deleted.

0 comments on commit 238ed39

Please sign in to comment.