Skip to content

Commit

Permalink
Merge pull request #1380 from Agenta-AI/feature/improve-error-message
Browse files Browse the repository at this point in the history
Improved the error messages when invoking llm applications
  • Loading branch information
mmabrouk authored Feb 16, 2024
2 parents 7d7e324 + ecc6426 commit 5c88ab5
Showing 1 changed file with 43 additions and 3 deletions.
46 changes: 43 additions & 3 deletions agenta-backend/agenta_backend/services/llm_apps_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,13 +91,53 @@ async def invoke_app(
result=Result(type="text", value=app_output["message"], error=None)
)

except httpx.HTTPError as e:
logger.error(f"Error occurred during request: {e}")
except httpx.HTTPStatusError as e:
# Parse error details from the API response
error_message = "Error in invoking the LLM App:"
try:
error_body = e.response.json()
if "message" in error_body:
error_message = error_body["message"]
elif (
"error" in error_body
): # Some APIs return error information under an 'error' key
error_message = error_body["error"]
except ValueError:
# Fallback if the error response is not JSON or doesn't have the expected structure
logger.error(f"Failed to parse error response: {e}")

logger.error(f"Error occurred during request: {error_message}")
return InvokationResult(
result=Result(
type="error",
error=Error(
message=error_message,
stacktrace=str(e),
),
)
)

except httpx.RequestError as e:
# Handle other request errors (e.g., network issues)
logger.error(f"Request error: {e}")
return InvokationResult(
result=Result(
type="error",
error=Error(
message="Network error while invoking the LLM App",
stacktrace=str(e),
),
)
)

except Exception as e:
# Catch-all for any other unexpected errors
logger.error(f"Unexpected error: {e}")
return InvokationResult(
result=Result(
type="error",
error=Error(
message="An error occurred while invoking the LLM App",
message="Unexpected error while invoking the LLM App",
stacktrace=str(e),
),
)
Expand Down

0 comments on commit 5c88ab5

Please sign in to comment.