forked from phoenix/litellm-mirror
refactor(llm.py): fixes linting issues
This commit is contained in:
parent
0f26458fcf
commit
e34e6429a7
2 changed files with 9 additions and 9 deletions
|
@ -10,7 +10,7 @@ import openai.error
|
||||||
|
|
||||||
import litellm
|
import litellm
|
||||||
from litellm.utils import trim_messages
|
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: Dict[str, Dict[str, float]] = defaultdict(dict)
|
||||||
cost_dict_lock = threading.Lock()
|
cost_dict_lock = threading.Lock()
|
||||||
|
@ -50,16 +50,16 @@ class UnknownLLMError(Exception):
|
||||||
|
|
||||||
def handle_llm_exception(e: Exception, user_api_base: Optional[str]=None):
|
def handle_llm_exception(e: Exception, user_api_base: Optional[str]=None):
|
||||||
print(f"\033[1;31mLiteLLM.Exception: {str(e)}\033[0m")
|
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()
|
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 = {}
|
||||||
completion_call_details["model"] = e.model
|
completion_call_details["model"] = e.model # type: ignore
|
||||||
if user_api_base:
|
if user_api_base:
|
||||||
completion_call_details["api_base"] = user_api_base
|
completion_call_details["api_base"] = user_api_base
|
||||||
else:
|
else:
|
||||||
completion_call_details["api_base"] = None
|
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":
|
if completion_call_details["api_base"] == "http://localhost:11434":
|
||||||
print()
|
print()
|
||||||
print("Trying to call ollama? Try `litellm --model ollama/llama2 --api_base http://localhost:11434`")
|
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_max_tokens: Optional[int],
|
||||||
user_api_base: Optional[str],
|
user_api_base: Optional[str],
|
||||||
user_headers: Optional[dict],
|
user_headers: Optional[dict],
|
||||||
user_debug: bool) -> litellm.ModelResponse:
|
user_debug: bool):
|
||||||
try:
|
try:
|
||||||
global debug
|
global debug
|
||||||
debug = user_debug
|
debug = user_debug
|
||||||
|
|
|
@ -2,7 +2,7 @@ import sys, os, platform, time, copy
|
||||||
import threading
|
import threading
|
||||||
import shutil, random, traceback
|
import shutil, random, traceback
|
||||||
|
|
||||||
messages = []
|
messages: list = []
|
||||||
sys.path.insert(
|
sys.path.insert(
|
||||||
0, os.path.abspath("../..")
|
0, os.path.abspath("../..")
|
||||||
) # Adds the parent directory to the system path - for litellm local dev
|
) # Adds the parent directory to the system path - for litellm local dev
|
||||||
|
@ -27,7 +27,7 @@ except ImportError:
|
||||||
try:
|
try:
|
||||||
from .llm import litellm_completion
|
from .llm import litellm_completion
|
||||||
except ImportError as e:
|
except ImportError as e:
|
||||||
from llm import litellm_completion
|
from llm import litellm_completion # type: ignore
|
||||||
|
|
||||||
import random
|
import random
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue