Skip to content

Commit

Permalink
add openai error logs
Browse files Browse the repository at this point in the history
  • Loading branch information
harry committed Apr 11, 2024
1 parent 56a6d5c commit 759c1ce
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion app/services/llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
from loguru import logger
from openai import OpenAI
from openai import AzureOpenAI
from openai.types.chat import ChatCompletion

from app.config import config


Expand Down Expand Up @@ -133,7 +135,15 @@ def _generate_response(prompt: str) -> str:
messages=[{"role": "user", "content": prompt}]
)
if response:
content = response.choices[0].message.content
if isinstance(response, ChatCompletion):
content = response.choices[0].message.content
else:
raise Exception(
f"[{llm_provider}] returned an invalid response: \"{response}\", please check your network "
f"connection and try again.")
else:
raise Exception(
f"[{llm_provider}] returned an empty response, please check your network connection and try again.")

return content.replace("\n", "")

Expand Down

0 comments on commit 759c1ce

Please sign in to comment.