From 39855f4d2bf6f656109de3c2a2d8b1778b47aeb4 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 6 Feb 2025 11:36:15 -0800 Subject: [PATCH] refactor: Change timeout handling to use float type and global request_timeout --- aider/args.py | 2 +- aider/main.py | 3 +-- aider/models.py | 4 +++- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/aider/args.py b/aider/args.py index 88fd68536..e20d99db4 100644 --- a/aider/args.py +++ b/aider/args.py @@ -216,7 +216,7 @@ def get_parser(default_config_files, git_root): ) group.add_argument( "--timeout", - type=int, + type=float, default=None, help="Timeout in seconds for API calls (default: None)", ) diff --git a/aider/main.py b/aider/main.py index ead3c127f..f88b8268b 100644 --- a/aider/main.py +++ b/aider/main.py @@ -509,8 +509,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F litellm._lazy_module.aclient_session = httpx.AsyncClient(verify=False) if args.timeout: - litellm._load_litellm() - litellm._lazy_module.request_timeout = args.timeout + models.request_timeout = args.timeout if args.dark_mode: args.user_input_color = "#32FF32" diff --git a/aider/models.py b/aider/models.py index 2160547f7..de3a91b0a 100644 --- a/aider/models.py +++ b/aider/models.py @@ -22,6 +22,8 @@ from aider.sendchat import ensure_alternating_roles, sanity_check_messages RETRY_TIMEOUT = 60 +request_timeout = 600 + DEFAULT_MODEL_NAME = "gpt-4o" ANTHROPIC_BETA_HEADER = "prompt-caching-2024-07-31,pdfs-2024-09-25" @@ -599,7 +601,7 @@ class Model(ModelSettings): # dump(kwargs) hash_object = hashlib.sha1(key) - res = litellm.completion(**kwargs) + res = litellm.completion(timeout=request_timeout, **kwargs) return hash_object, res def remove_reasoning_content(self, res):