From 4fa116bd450200ea302b3980cf7a28ad3222f141 Mon Sep 17 00:00:00 2001 From: Deepak K <89829542+Deepak-Kesavan@users.noreply.github.com> Date: Wed, 10 Apr 2024 12:09:59 +0530 Subject: [PATCH] Fix : Prompt service error handling improvement (#35) * Handle errors for json response * Version bump 0.18.1 -> 0.18.2 --- src/unstract/sdk/__init__.py | 2 +- src/unstract/sdk/prompt.py | 11 ++++++++++- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/unstract/sdk/__init__.py b/src/unstract/sdk/__init__.py index 6c8f4d35..e35b60ab 100644 --- a/src/unstract/sdk/__init__.py +++ b/src/unstract/sdk/__init__.py @@ -1,4 +1,4 @@ -__version__ = "0.18.1" +__version__ = "0.18.2" def get_sdk_version(): diff --git a/src/unstract/sdk/prompt.py b/src/unstract/sdk/prompt.py index b973b7a7..a03d8915 100644 --- a/src/unstract/sdk/prompt.py +++ b/src/unstract/sdk/prompt.py @@ -75,7 +75,16 @@ def _post_call( result["status"] = "OK" result["structure_output"] = response.text except RequestException as e: - result["error"] = f"Error occurred: {e}" + # Extract error information from the response if available + error_message = str(e) + content_type = response.headers.get("Content-Type", "").lower() + if "application/json" in content_type: + response_json = response.json() + if "error" in response_json: + error_message = response_json["error"] + elif response.text: + error_message = response.text + result["error"] = error_message self.tool.stream_log( f"Error while fetching response for prompt: {result['error']}", level=LogLevel.ERROR,