From 9d02628cf87c8d52e0ab5616fa7d6cefc725da35 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 3 Jul 2024 21:32:50 -0300 Subject: [PATCH] streamlit borks sys.path, causes import("litellm") to load our litellm.py; fix --- aider/coders/base_coder.py | 2 +- aider/commands.py | 2 +- aider/{litellm.py => llm.py} | 3 ++- aider/main.py | 4 ++-- aider/models.py | 2 +- aider/sendchat.py | 4 ++-- aider/tests/test_sendchat.py | 2 +- aider/voice.py | 2 +- 8 files changed, 11 insertions(+), 10 deletions(-) rename aider/{litellm.py => llm.py} (87%) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 67df194f9..662bd7912 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -22,7 +22,7 @@ from aider.commands import Commands from aider.history import ChatSummary from aider.io import InputOutput from aider.linter import Linter -from aider.litellm import litellm +from aider.llm import litellm from aider.mdstream import MarkdownStream from aider.repo import GitRepo from aider.repomap import RepoMap diff --git a/aider/commands.py b/aider/commands.py index ac1f07bf4..fd129dc3c 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -7,7 +7,7 @@ from pathlib import Path import git from aider import models, prompts, voice -from aider.litellm import litellm +from aider.llm import litellm from aider.scrape import Scraper from aider.utils import is_image_file diff --git a/aider/litellm.py b/aider/llm.py similarity index 87% rename from aider/litellm.py rename to aider/llm.py index 4c97c0a94..73f7a25a5 100644 --- a/aider/litellm.py +++ b/aider/llm.py @@ -1,3 +1,4 @@ +import importlib import os import warnings @@ -15,7 +16,7 @@ class LazyLiteLLM: def __getattr__(self, name): if self._lazy_module is None: - self._lazy_module = __import__("litellm") + self._lazy_module = importlib.import_module("litellm") self._lazy_module.suppress_debug_info = True self._lazy_module.set_verbose = False diff --git a/aider/main.py b/aider/main.py index 88ea47f98..078fa0540 100644 --- a/aider/main.py +++ b/aider/main.py @@ -14,7 +14,7 @@ from aider.args import get_parser from aider.coders import Coder from aider.commands import SwitchModel from aider.io import InputOutput -from aider.litellm import litellm # noqa: F401; properly init litellm on launch +from aider.llm import litellm # noqa: F401; properly init litellm on launch from aider.repo import GitRepo from aider.versioncheck import check_version @@ -249,7 +249,7 @@ def register_models(git_root, model_settings_fname, io): def register_litellm_models(git_root, model_metadata_fname, io): model_metatdata_files = generate_search_path_list( - ".aider.litellm.models.json", git_root, model_metadata_fname + ".aider.llm.models.json", git_root, model_metadata_fname ) try: diff --git a/aider/models.py b/aider/models.py index 44acdb95f..0667f8183 100644 --- a/aider/models.py +++ b/aider/models.py @@ -13,7 +13,7 @@ from PIL import Image from aider import urls from aider.dump import dump # noqa: F401 -from aider.litellm import litellm +from aider.llm import litellm DEFAULT_MODEL_NAME = "gpt-4o" diff --git a/aider/sendchat.py b/aider/sendchat.py index bb0030c3a..1123fe78c 100644 --- a/aider/sendchat.py +++ b/aider/sendchat.py @@ -4,7 +4,7 @@ import json import backoff from aider.dump import dump # noqa: F401 -from aider.litellm import litellm +from aider.llm import litellm # from diskcache import Cache @@ -57,7 +57,7 @@ def lazy_litellm_retry_decorator(func): @lazy_litellm_retry_decorator def send_with_retries(model_name, messages, functions, stream, temperature=0): - from aider.litellm import litellm + from aider.llm import litellm kwargs = dict( model=model_name, diff --git a/aider/tests/test_sendchat.py b/aider/tests/test_sendchat.py index 7f9ce274d..6ac02a47b 100644 --- a/aider/tests/test_sendchat.py +++ b/aider/tests/test_sendchat.py @@ -3,7 +3,7 @@ from unittest.mock import MagicMock, patch import httpx -from aider.litellm import litellm +from aider.llm import litellm from aider.sendchat import send_with_retries diff --git a/aider/voice.py b/aider/voice.py index 416917dee..46568e8e8 100644 --- a/aider/voice.py +++ b/aider/voice.py @@ -4,7 +4,7 @@ import queue import tempfile import time -from aider.litellm import litellm +from aider.llm import litellm try: import soundfile as sf