Skip to content

Commit

Permalink
Fix APIError exception import and format statistics
Browse files Browse the repository at this point in the history
  • Loading branch information
simonkurtz-MSFT committed May 24, 2024
1 parent 6bc8e91 commit c0a27a1
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions aoai.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

##########################################################################################################################################################
Expand Down Expand Up @@ -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")

0 comments on commit c0a27a1

Please sign in to comment.