From d8095e2c40a1e9262af2d428f2b66c85b9d70b7d Mon Sep 17 00:00:00 2001 From: Nick Bobrowski <39348559+bonk1t@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:02:09 +0000 Subject: [PATCH 1/2] Make Timeouts Configurable --- agency_swarm/tools/ToolFactory.py | 6 ++---- agency_swarm/util/oai.py | 4 ++-- 2 files changed, 4 insertions(+), 6 deletions(-) diff --git a/agency_swarm/tools/ToolFactory.py b/agency_swarm/tools/ToolFactory.py index d36cd7ce..a7bf9521 100644 --- a/agency_swarm/tools/ToolFactory.py +++ b/agency_swarm/tools/ToolFactory.py @@ -2,7 +2,6 @@ import json import os import sys -from importlib import import_module from typing import Any, Dict, List, Type, Union import httpx @@ -129,6 +128,7 @@ def from_openapi_schema( headers: Dict[str, str] = None, params: Dict[str, Any] = None, strict: bool = False, + timeout: float = 600.0, ) -> List[Type[BaseTool]]: """ Converts an OpenAPI schema into a list of BaseTools. @@ -163,9 +163,7 @@ async def callback(self): url = url.rstrip("/") parameters = {k: v for k, v in parameters.items() if v is not None} parameters = {**parameters, **params} if params else parameters - async with httpx.AsyncClient( - timeout=90 - ) as client: # Set custom read timeout to 10 seconds + async with httpx.AsyncClient(timeout=timeout) as client: if method == "get": response = await client.get( url, params=parameters, headers=headers diff --git a/agency_swarm/util/oai.py b/agency_swarm/util/oai.py index cb502ce1..4e62f0cc 100644 --- a/agency_swarm/util/oai.py +++ b/agency_swarm/util/oai.py @@ -11,7 +11,7 @@ client = None -def get_openai_client(): +def get_openai_client(timeout: float = 600.0): global client with client_lock: if client is None: @@ -23,7 +23,7 @@ def get_openai_client(): ) client = openai.OpenAI( api_key=api_key, - timeout=httpx.Timeout(60.0, read=40, connect=5.0), + timeout=httpx.Timeout(timeout, read=timeout - 20, connect=5.0), max_retries=10, default_headers={"OpenAI-Beta": "assistants=v2"}, ) From 6d9f141ee4413e883e389c23caf9f67e8d38b7cd Mon Sep 17 00:00:00 2001 From: Nick Bobrowski <39348559+bonk1t@users.noreply.github.com> Date: Thu, 19 Dec 2024 21:12:09 +0000 Subject: [PATCH 2/2] Use 60 seconds as default --- agency_swarm/tools/ToolFactory.py | 2 +- agency_swarm/util/oai.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/agency_swarm/tools/ToolFactory.py b/agency_swarm/tools/ToolFactory.py index a7bf9521..b3ab26b9 100644 --- a/agency_swarm/tools/ToolFactory.py +++ b/agency_swarm/tools/ToolFactory.py @@ -128,7 +128,7 @@ def from_openapi_schema( headers: Dict[str, str] = None, params: Dict[str, Any] = None, strict: bool = False, - timeout: float = 600.0, + timeout: float = 60.0, ) -> List[Type[BaseTool]]: """ Converts an OpenAPI schema into a list of BaseTools. diff --git a/agency_swarm/util/oai.py b/agency_swarm/util/oai.py index 4e62f0cc..5884ccfc 100644 --- a/agency_swarm/util/oai.py +++ b/agency_swarm/util/oai.py @@ -11,7 +11,7 @@ client = None -def get_openai_client(timeout: float = 600.0): +def get_openai_client(timeout: float = 60.0): global client with client_lock: if client is None: