From 2dc6735ab42c129d12edf9eff63abfac89a8dbba Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 3 Jul 2024 13:25:10 -0300 Subject: [PATCH] defer import of httpx --- aider/main.py | 3 ++- aider/scrape.py | 3 ++- aider/sendchat.py | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/aider/main.py b/aider/main.py index 6a099f0b4..a7bdf4932 100644 --- a/aider/main.py +++ b/aider/main.py @@ -5,7 +5,6 @@ import sys from pathlib import Path import git -import httpx from dotenv import load_dotenv from prompt_toolkit.enums import EditingMode @@ -293,6 +292,8 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F args = parser.parse_args(argv) if not args.verify_ssl: + import httpx + litellm.client_session = httpx.Client(verify=False) if args.gui and not return_coder: diff --git a/aider/scrape.py b/aider/scrape.py index 2ac29b6a2..c705755ae 100755 --- a/aider/scrape.py +++ b/aider/scrape.py @@ -3,7 +3,6 @@ import re import sys -import httpx import playwright import pypandoc from bs4 import BeautifulSoup @@ -111,6 +110,8 @@ class Scraper: return PLAYWRIGHT_INFO def scrape_with_httpx(self, url): + import httpx + headers = {"User-Agent": f"Mozilla./5.0 ({aider_user_agent})"} try: with httpx.Client(headers=headers) as client: diff --git a/aider/sendchat.py b/aider/sendchat.py index 43153d2ec..bb0030c3a 100644 --- a/aider/sendchat.py +++ b/aider/sendchat.py @@ -2,7 +2,6 @@ import hashlib import json import backoff -import httpx from aider.dump import dump # noqa: F401 from aider.litellm import litellm @@ -17,6 +16,8 @@ CACHE = None def lazy_litellm_retry_decorator(func): def wrapper(*args, **kwargs): + import httpx + def should_giveup(e): if not hasattr(e, "status_code"): return False