From 9ff6770a0473e8e7e0ccc87e74eb197710e282d7 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Wed, 8 May 2024 08:05:15 -0700 Subject: [PATCH] refactored litellm to avoid duplicating workarounds --- aider/coders/base_coder.py | 4 +--- aider/commands.py | 4 +--- aider/main.py | 6 +----- aider/models.py | 4 +--- aider/sendchat.py | 4 +--- aider/voice.py | 5 ++--- 6 files changed, 7 insertions(+), 20 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 28acb65ad..3279e1e3d 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -11,7 +11,6 @@ from json.decoder import JSONDecodeError from pathlib import Path import git -import litellm import openai from jsonschema import Draft7Validator from rich.console import Console, Text @@ -21,6 +20,7 @@ from aider import __version__, models, prompts, utils from aider.commands import Commands from aider.history import ChatSummary from aider.io import InputOutput +from aider.litellm import litellm from aider.mdstream import MarkdownStream from aider.repo import GitRepo from aider.repomap import RepoMap @@ -29,8 +29,6 @@ from aider.utils import is_image_file from ..dump import dump # noqa: F401 -litellm.suppress_debug_info = True - class MissingAPIKeyError(ValueError): pass diff --git a/aider/commands.py b/aider/commands.py index 3cbf7967c..c592a5d7f 100644 --- a/aider/commands.py +++ b/aider/commands.py @@ -5,18 +5,16 @@ import sys from pathlib import Path import git -import litellm import openai from prompt_toolkit.completion import Completion from aider import models, prompts, voice +from aider.litellm import litellm from aider.scrape import Scraper from aider.utils import is_image_file from .dump import dump # noqa: F401 -litellm.suppress_debug_info = True - class SwitchModel(Exception): def __init__(self, model): diff --git a/aider/main.py b/aider/main.py index 1bba9cdd0..57f0f530b 100644 --- a/aider/main.py +++ b/aider/main.py @@ -4,7 +4,6 @@ import sys from pathlib import Path import git -import litellm from dotenv import load_dotenv from streamlit.web import cli @@ -13,15 +12,12 @@ 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.repo import GitRepo from aider.versioncheck import check_version from .dump import dump # noqa: F401 -litellm.suppress_debug_info = True -os.environ["OR_SITE_URL"] = "http://aider.chat" -os.environ["OR_APP_NAME"] = "Aider" - def get_git_root(): """Try and guess the git repo, since the conf.yml can be at the repo root""" diff --git a/aider/models.py b/aider/models.py index d6903bc8c..6d3e99b79 100644 --- a/aider/models.py +++ b/aider/models.py @@ -6,12 +6,10 @@ import sys from dataclasses import dataclass, fields from typing import Optional -import litellm from PIL import Image from aider.dump import dump # noqa: F401 - -litellm.suppress_debug_info = True +from aider.litellm import litellm DEFAULT_MODEL_NAME = "gpt-4-1106-preview" diff --git a/aider/sendchat.py b/aider/sendchat.py index bd2ab9df6..0dc27e63b 100644 --- a/aider/sendchat.py +++ b/aider/sendchat.py @@ -3,20 +3,18 @@ import json import backoff import httpx -import litellm import openai # from diskcache import Cache from openai import APIConnectionError, InternalServerError, RateLimitError from aider.dump import dump # noqa: F401 +from aider.litellm import litellm CACHE_PATH = "~/.aider.send.cache.v1" CACHE = None # CACHE = Cache(CACHE_PATH) -litellm.suppress_debug_info = True - def should_giveup(e): if not hasattr(e, "status_code"): diff --git a/aider/voice.py b/aider/voice.py index c383fc208..3b2199eed 100644 --- a/aider/voice.py +++ b/aider/voice.py @@ -3,9 +3,10 @@ import queue import tempfile import time -import litellm import numpy as np +from aider.litellm import litellm + try: import soundfile as sf except (OSError, ModuleNotFoundError): @@ -15,8 +16,6 @@ from prompt_toolkit.shortcuts import prompt from .dump import dump # noqa: F401 -litellm.suppress_debug_info = True - class SoundDeviceError(Exception): pass