From a5f2398b5b56d669a9d59e779dd6b1cd7604d159 Mon Sep 17 00:00:00 2001 From: Juan Pablo Vega Date: Mon, 8 Jul 2024 15:22:35 +0200 Subject: [PATCH 1/2] fix(backend): AGE-391 Fix different error info in playground and evals An existing try-except mechanism why hiding valuable information only in evaluation mode, and not in playground mode --- .../services/llm_apps_service.py | 21 +++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/agenta-backend/agenta_backend/services/llm_apps_service.py b/agenta-backend/agenta_backend/services/llm_apps_service.py index 322f262de..66fbf7b6b 100644 --- a/agenta-backend/agenta_backend/services/llm_apps_service.py +++ b/agenta-backend/agenta_backend/services/llm_apps_service.py @@ -83,11 +83,13 @@ async def invoke_app( payload = await make_payload(datapoint, parameters, openapi_parameters) async with aiohttp.ClientSession() as client: + app_response = {} + try: logger.debug(f"Invoking app {uri} with payload {payload}") response = await client.post(url, json=payload, timeout=900) - response.raise_for_status() app_response = await response.json() + response.raise_for_status() return InvokationResult( result=Result( type="text", @@ -99,8 +101,12 @@ async def invoke_app( ) except aiohttp.ClientResponseError as e: - error_message = f"HTTP error {e.status}: {e.message}" - stacktrace = "".join(traceback.format_exception_only(type(e), e)) + error_message = app_response.get("detail", {}).get( + "error", f"HTTP error {e.status}: {e.message}" + ) + stacktrace = app_response.get("detail", {}).get( + "traceback", "".join(traceback.format_exception_only(type(e), e)) + ) logger.error(f"HTTP error occurred during request: {error_message}") common.capture_exception_in_sentry(e) except aiohttp.ServerTimeoutError as e: @@ -184,6 +190,7 @@ async def run_with_retry( if retries == max_retry_count else f"Error processing {input_data} datapoint" ) + return InvokationResult( result=Result( type="error", @@ -221,9 +228,9 @@ async def batch_invoke( "delay_between_batches" ] # Delay between batches (in seconds) - list_of_app_outputs: List[ - InvokationResult - ] = [] # Outputs after running all batches + list_of_app_outputs: List[InvokationResult] = ( + [] + ) # Outputs after running all batches openapi_parameters = await get_parameters_from_openapi(uri + "/openapi.json") async def run_batch(start_idx: int): @@ -245,6 +252,7 @@ async def run_batch(start_idx: int): # Gather results of all tasks results = await asyncio.gather(*tasks) + for result in results: list_of_app_outputs.append(result) print(f"Adding outputs to batch {start_idx}") @@ -257,6 +265,7 @@ async def run_batch(start_idx: int): # Start the first batch await run_batch(0) + return list_of_app_outputs From 511586accd78289b658170f3dd4ea13004c6c809 Mon Sep 17 00:00:00 2001 From: Kaosiso Ezealigo Date: Mon, 8 Jul 2024 15:21:34 +0100 Subject: [PATCH 2/2] fix(backend): ran black formatter --- agenta-backend/agenta_backend/services/llm_apps_service.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/agenta-backend/agenta_backend/services/llm_apps_service.py b/agenta-backend/agenta_backend/services/llm_apps_service.py index 66fbf7b6b..66d7b2143 100644 --- a/agenta-backend/agenta_backend/services/llm_apps_service.py +++ b/agenta-backend/agenta_backend/services/llm_apps_service.py @@ -228,9 +228,9 @@ async def batch_invoke( "delay_between_batches" ] # Delay between batches (in seconds) - list_of_app_outputs: List[InvokationResult] = ( - [] - ) # Outputs after running all batches + list_of_app_outputs: List[ + InvokationResult + ] = [] # Outputs after running all batches openapi_parameters = await get_parameters_from_openapi(uri + "/openapi.json") async def run_batch(start_idx: int):