Skip to content

Commit

Permalink
Set default timeout for openai client to 5
Browse files Browse the repository at this point in the history
  • Loading branch information
VRSEN committed Feb 14, 2024
1 parent ba34b79 commit f39eb78
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
6 changes: 6 additions & 0 deletions agency_swarm/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,13 @@ def __init__(
# init methods
self.client = get_openai_client()
self._read_instructions()

# upload files
prev_timeout = self.client.timeout
self.client.timeout = 120 if prev_timeout < 120 else prev_timeout # default timeout is too low for file large file uploads
self._upload_files()
self.client.timeout = prev_timeout

self._parse_schemas()
self._parse_tools_folder()

Expand Down
3 changes: 2 additions & 1 deletion agency_swarm/util/oai.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,15 @@ def get_openai_client():
if api_key is None:
raise ValueError("OpenAI API key is not set. Please set it using set_openai_key.")
client = instructor.patch(openai.OpenAI(api_key=api_key,
timeout=5,
max_retries=5))
return client


def set_openai_client(new_client):
global client
with client_lock:
client = new_client
client = instructor.patch(new_client)


def set_openai_key(key):
Expand Down

0 comments on commit f39eb78

Please sign in to comment.