From c0a27a124e10d7be81ee06daf3e9e92383a49e16 Mon Sep 17 00:00:00 2001 From: Simon Kurtz Date: Fri, 24 May 2024 12:28:58 -0400 Subject: [PATCH] Fix APIError exception import and format statistics --- aoai.py | 23 +++++++++++------------ 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/aoai.py b/aoai.py index 33aa1f0..5f1d355 100644 --- a/aoai.py +++ b/aoai.py @@ -11,7 +11,7 @@ # https://github.com/openai/openai-python/releases/tag/v1.17.0 import httpx from azure.identity import DefaultAzureCredential, get_bearer_token_provider -from openai import AzureOpenAI, AsyncAzureOpenAI, NotFoundError +from openai import AzureOpenAI, AsyncAzureOpenAI, NotFoundError, APIError from src.openai_priority_loadbalancer.openai_priority_loadbalancer import AsyncLoadBalancer, LoadBalancer, Backend ########################################################################################################################################################## @@ -391,28 +391,27 @@ async def send_async_stream_loadbalancer_request(num_of_requests: int): async_stream_lb_end_time = time.time() # Statistics -WIDTH = 7 +WIDTH = 16 +SECONDS_WIDTH = WIDTH - 8 print(f"\n{'*' * 100}\n") -print(f"Number of requests per approach : {str(NUM_OF_REQUESTS).rjust(WIDTH)}\n") +print(f"Requests per approach : {str(NUM_OF_REQUESTS).rjust(WIDTH)}") print(f"Total requests : {str(counter).rjust(WIDTH)}") -print(f"Successful requests : {str(success_counter).rjust(WIDTH)}") -print(f"Failed requests : {str(failure_counter).rjust(WIDTH)}\n") - +print(f"Total successful requests : {str(success_counter).rjust(WIDTH)}") +print(f"Total failed requests : {str(failure_counter).rjust(WIDTH)}") print(f"Successful requests percentage : {('{:.2%}'.format(success_counter / counter)).rjust(WIDTH)}") print(f"Failed requests percentage : {('{:.2%}'.format(failure_counter / counter)).rjust(WIDTH)}\n") - if test_executions.standard: - print(f"Single instance operation duration : {end_time - start_time:.2f} seconds") + print(f"Single instance operation duration : {end_time - start_time:>{SECONDS_WIDTH}.2f} seconds") if test_executions.load_balanced: - print(f"Load-balancer operation duration : {lb_end_time - lb_start_time:.2f} seconds") + print(f"Load-balancer operation duration : {lb_end_time - lb_start_time:>{SECONDS_WIDTH}.2f} seconds") if test_executions.async_load_balanced: - print(f"Async Load-balancer operation duration : {async_lb_end_time - async_lb_start_time:.2f} seconds") + print(f"Async Load-balancer operation duration : {async_lb_end_time - async_lb_start_time:>{SECONDS_WIDTH}.2f} seconds") if test_executions.stream_load_balanced: - print(f"Stream Load-balancer operation duration : {stream_lb_end_time - stream_lb_start_time:.2f} seconds") + print(f"Stream Load-balancer operation duration : {stream_lb_end_time - stream_lb_start_time:>{SECONDS_WIDTH}.2f} seconds") if test_executions.async_stream_load_balanced: - print(f"Stream Async Load-balancer operation duration : {async_stream_lb_end_time - async_stream_lb_start_time:.2f} seconds") + print(f"Stream Async Load-balancer operation duration : {async_stream_lb_end_time - async_stream_lb_start_time:>{SECONDS_WIDTH}.2f} seconds") print("\n\n")