Skip to content

Commit

Permalink
refactor: Handle errors and refusals in chat responses
Browse files Browse the repository at this point in the history
  • Loading branch information
provos committed Oct 24, 2024
1 parent f892a53 commit 5c34bd3
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/planai/llm_interface.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,11 @@ def _cached_chat(
# Cache the response with hashed prompt as key
self.disk_cache.set(prompt_hash, response)

if "error" in response:
self.logger.error("Error in chat response: %s", response["error"])
elif "refusal" in response:
self.logger.error("Model refused the request: %s", response["refusal"])

return response["message"]["content"]

def chat(
Expand Down

0 comments on commit 5c34bd3

Please sign in to comment.