Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Timeous Configurable #205

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 2 additions & 4 deletions agency_swarm/tools/ToolFactory.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,6 +128,7 @@ def from_openapi_schema(
headers: Dict[str, str] = None,
params: Dict[str, Any] = None,
strict: bool = False,
timeout: float = 60.0,
) -> List[Type[BaseTool]]:
"""
Converts an OpenAPI schema into a list of BaseTools.
Expand Down Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions agency_swarm/util/oai.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
client = None


def get_openai_client():
def get_openai_client(timeout: float = 60.0):
global client
with client_lock:
if client is None:
Expand All @@ -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"},
)
Expand Down
Loading