From f39eb78a1c3ac71d5192202972f46c5423204406 Mon Sep 17 00:00:00 2001 From: Arsenii Shatokhin Date: Wed, 14 Feb 2024 14:59:53 +0400 Subject: [PATCH] Set default timeout for openai client to 5 --- agency_swarm/agents/agent.py | 6 ++++++ agency_swarm/util/oai.py | 3 ++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/agency_swarm/agents/agent.py b/agency_swarm/agents/agent.py index d432fb4a..b9e73d44 100644 --- a/agency_swarm/agents/agent.py +++ b/agency_swarm/agents/agent.py @@ -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() diff --git a/agency_swarm/util/oai.py b/agency_swarm/util/oai.py index 88f9bf68..261bd225 100644 --- a/agency_swarm/util/oai.py +++ b/agency_swarm/util/oai.py @@ -20,6 +20,7 @@ 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 @@ -27,7 +28,7 @@ def get_openai_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):