diff --git a/evals/utils/api_utils.py b/evals/utils/api_utils.py index 7479d5e9a2..8f8b7a732d 100644 --- a/evals/utils/api_utils.py +++ b/evals/utils/api_utils.py @@ -1,7 +1,6 @@ """ This file defines various helper functions for interacting with the OpenAI API. """ -import concurrent import logging import os @@ -38,16 +37,14 @@ def openai_completion_create_retrying(client: OpenAI, *args, **kwargs): def request_with_timeout(func, *args, timeout=EVALS_THREAD_TIMEOUT, **kwargs): """ - Worker thread for making a single request within allotted time. + Function for making a single request within allotted time. """ while True: - with concurrent.futures.ThreadPoolExecutor(max_workers=1) as executor: - future = executor.submit(func, *args, **kwargs) - try: - result = future.result(timeout=timeout) - return result - except concurrent.futures.TimeoutError: - continue + try: + result = func(*args, timeout=timeout, **kwargs) + return result + except openai.APITimeoutError as e: + continue @backoff.on_exception(