From 4c261d9c5e1c943d43ec4d06f0e39e1c134f0a5f Mon Sep 17 00:00:00 2001 From: Giulio Starace Date: Wed, 13 Mar 2024 10:25:12 +0100 Subject: [PATCH] avoid nested threading --- evals/utils/api_utils.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) 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(