Skip to content

Commit

Permalink
avoid nested threading
Browse files Browse the repository at this point in the history
  • Loading branch information
thesofakillers committed Mar 13, 2024
1 parent 82ec660 commit 4c261d9
Showing 1 changed file with 6 additions and 9 deletions.
15 changes: 6 additions & 9 deletions evals/utils/api_utils.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
"""
This file defines various helper functions for interacting with the OpenAI API.
"""
import concurrent
import logging
import os

Expand Down Expand Up @@ -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(
Expand Down

0 comments on commit 4c261d9

Please sign in to comment.