diff --git a/litellm/proxy/llm.py b/litellm/proxy/llm.py index 85d34d06c..816ea3e85 100644 --- a/litellm/proxy/llm.py +++ b/litellm/proxy/llm.py @@ -10,7 +10,7 @@ import openai.error import litellm from litellm.utils import trim_messages -import litellm.exceptions +from litellm.exceptions import ServiceUnavailableError, InvalidRequestError cost_dict: Dict[str, Dict[str, float]] = defaultdict(dict) cost_dict_lock = threading.Lock() @@ -50,16 +50,16 @@ class UnknownLLMError(Exception): def handle_llm_exception(e: Exception, user_api_base: Optional[str]=None): print(f"\033[1;31mLiteLLM.Exception: {str(e)}\033[0m") - if isinstance(e, openai.error.ServiceUnavailableError) and e.llm_provider == "ollama": + if isinstance(e, ServiceUnavailableError) and e.llm_provider == "ollama": # type: ignore run_ollama_serve() - if isinstance(e, openai.error.InvalidRequestError) and e.llm_provider == "ollama": + if isinstance(e, InvalidRequestError) and e.llm_provider == "ollama": # type: ignore completion_call_details = {} - completion_call_details["model"] = e.model + completion_call_details["model"] = e.model # type: ignore if user_api_base: completion_call_details["api_base"] = user_api_base else: completion_call_details["api_base"] = None - print(f"\033[1;31mLiteLLM.Exception: Invalid API Call. Call details: Model: \033[1;37m{e.model}\033[1;31m; LLM Provider: \033[1;37m{e.llm_provider}\033[1;31m; Custom API Base - \033[1;37m{completion_call_details['api_base']}\033[1;31m\033[0m") + print(f"\033[1;31mLiteLLM.Exception: Invalid API Call. Call details: Model: \033[1;37m{e.model}\033[1;31m; LLM Provider: \033[1;37m{e.llm_provider}\033[1;31m; Custom API Base - \033[1;37m{completion_call_details['api_base']}\033[1;31m\033[0m") # type: ignore if completion_call_details["api_base"] == "http://localhost:11434": print() print("Trying to call ollama? Try `litellm --model ollama/llama2 --api_base http://localhost:11434`") @@ -113,7 +113,7 @@ def litellm_completion(data: Dict, user_max_tokens: Optional[int], user_api_base: Optional[str], user_headers: Optional[dict], - user_debug: bool) -> litellm.ModelResponse: + user_debug: bool): try: global debug debug = user_debug diff --git a/litellm/proxy/proxy_server.py b/litellm/proxy/proxy_server.py index 8a89f90e3..6dbdc8f65 100644 --- a/litellm/proxy/proxy_server.py +++ b/litellm/proxy/proxy_server.py @@ -2,7 +2,7 @@ import sys, os, platform, time, copy import threading import shutil, random, traceback -messages = [] +messages: list = [] sys.path.insert( 0, os.path.abspath("../..") ) # Adds the parent directory to the system path - for litellm local dev @@ -25,9 +25,9 @@ except ImportError: import tomli_w try: - from .llm import litellm_completion + from .llm import litellm_completion except ImportError as e: - from llm import litellm_completion + from llm import litellm_completion # type: ignore import random