(code quality) add ruff check PLR0915 for too-many-statements (#6309)

* ruff add PLR0915

* add noqa for PLR0915

* fix noqa

* add # noqa: PLR0915

* # noqa: PLR0915

* # noqa: PLR0915

* # noqa: PLR0915

* add # noqa: PLR0915

* # noqa: PLR0915

* # noqa: PLR0915

* # noqa: PLR0915

* # noqa: PLR0915
This commit is contained in:
Ishaan Jaff 2024-10-18 15:36:49 +05:30 committed by GitHub
parent 7724d5895c
commit 610974b4fc
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
56 changed files with 137 additions and 119 deletions

View file

@ -17,7 +17,7 @@ db = Prisma(
)
async def check_view_exists():
async def check_view_exists(): # noqa: PLR0915
"""
Checks if the LiteLLM_VerificationTokenView and MonthlyGlobalSpend exists in the user's db.

View file

@ -220,7 +220,7 @@ class Cache:
if self.namespace is not None and isinstance(self.cache, RedisCache):
self.cache.namespace = self.namespace
def get_cache_key(self, *args, **kwargs) -> str:
def get_cache_key(self, *args, **kwargs) -> str: # noqa: PLR0915
"""
Get the cache key for the given arguments.

View file

@ -20,7 +20,7 @@ from .base_cache import BaseCache
class QdrantSemanticCache(BaseCache):
def __init__(
def __init__( # noqa: PLR0915
self,
qdrant_api_base=None,
qdrant_api_key=None,

View file

@ -79,7 +79,7 @@ def _cost_per_token_custom_pricing_helper(
return None
def cost_per_token(
def cost_per_token( # noqa: PLR0915
model: str = "",
prompt_tokens: int = 0,
completion_tokens: int = 0,
@ -474,7 +474,7 @@ def _select_model_name_for_cost_calc(
return return_model
def completion_cost(
def completion_cost( # noqa: PLR0915
completion_response=None,
model: Optional[str] = None,
prompt="",

View file

@ -287,7 +287,7 @@ class SlackAlerting(CustomBatchLogger):
except Exception:
return 0
async def send_daily_reports(self, router) -> bool:
async def send_daily_reports(self, router) -> bool: # noqa: PLR0915
"""
Send a daily report on:
- Top 5 deployments with most failed requests
@ -573,7 +573,7 @@ class SlackAlerting(CustomBatchLogger):
ttl=self.alerting_args.budget_alert_ttl,
)
async def budget_alerts(
async def budget_alerts( # noqa: PLR0915
self,
type: Literal[
"token_budget",

View file

@ -125,7 +125,9 @@ class BraintrustLogger(CustomLogger):
self.default_project_id = project_dict["id"]
def log_success_event(self, kwargs, response_obj, start_time, end_time):
def log_success_event( # noqa: PLR0915
self, kwargs, response_obj, start_time, end_time
):
verbose_logger.debug("REACHES BRAINTRUST SUCCESS")
try:
litellm_call_id = kwargs.get("litellm_call_id")
@ -237,7 +239,9 @@ class BraintrustLogger(CustomLogger):
except Exception as e:
raise e # don't use verbose_logger.exception, if exception is raised
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
async def async_log_success_event( # noqa: PLR0915
self, kwargs, response_obj, start_time, end_time
):
verbose_logger.debug("REACHES BRAINTRUST SUCCESS")
try:
litellm_call_id = kwargs.get("litellm_call_id")

View file

@ -143,7 +143,7 @@ class LangFuseLogger:
# level ="ERROR" # can be any of DEBUG, DEFAULT, WARNING or ERROR
# status_message='error' # can be any string (e.g. stringified stack trace or error body)
# )
def log_event(
def log_event( # noqa: PLR0915
self,
kwargs,
response_obj,
@ -349,7 +349,7 @@ class LangFuseLogger:
)
)
def _log_langfuse_v2(
def _log_langfuse_v2( # noqa: PLR0915
self,
user_id,
metadata,

View file

@ -132,7 +132,9 @@ class LangsmithLogger(CustomBatchLogger):
LANGSMITH_PROJECT=_credentials_project,
)
def _prepare_log_data(self, kwargs, response_obj, start_time, end_time):
def _prepare_log_data( # noqa: PLR0915
self, kwargs, response_obj, start_time, end_time
):
import json
from datetime import datetime as dt

View file

@ -393,7 +393,7 @@ class OpenTelemetry(CustomLogger):
except Exception:
return ""
def set_attributes(self, span: Span, kwargs, response_obj):
def set_attributes(self, span: Span, kwargs, response_obj): # noqa: PLR0915
try:
if self.callback_name == "arize":
from litellm.integrations.arize_ai import set_arize_ai_attributes

View file

@ -182,7 +182,7 @@ class OpikLogger(CustomBatchLogger):
url=self.span_url, headers=self.headers, batch={"spans": spans}
)
def _create_opik_payload(
def _create_opik_payload( # noqa: PLR0915
self, kwargs, response_obj, start_time, end_time
) -> List[Dict]:

View file

@ -321,7 +321,9 @@ class PrometheusLogger(CustomLogger):
print_verbose(f"Got exception on init prometheus client {str(e)}")
raise e
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
async def async_log_success_event( # noqa: PLR0915
self, kwargs, response_obj, start_time, end_time
):
# Define prometheus client
from litellm.proxy.common_utils.callback_utils import (
get_model_group_from_litellm_kwargs,

View file

@ -89,7 +89,7 @@ def _get_response_headers(original_exception: Exception) -> Optional[httpx.Heade
return _response_headers
def exception_type( # type: ignore
def exception_type( # type: ignore # noqa: PLR0915
model,
original_exception,
custom_llm_provider,

View file

@ -67,7 +67,7 @@ def handle_cohere_chat_model_custom_llm_provider(
return model, custom_llm_provider
def get_llm_provider(
def get_llm_provider( # noqa: PLR0915
model: str,
custom_llm_provider: Optional[str] = None,
api_base: Optional[str] = None,

View file

@ -428,7 +428,7 @@ class Logging:
): # if model name was changes pre-call, overwrite the initial model call name with the new one
self.model_call_details["model"] = model
def pre_call(self, input, api_key, model=None, additional_args={}):
def pre_call(self, input, api_key, model=None, additional_args={}): # noqa: PLR0915
# Log the exact input to the LLM API
litellm.error_logs["PRE_CALL"] = locals()
try:
@ -868,7 +868,7 @@ class Logging:
except Exception as e:
raise Exception(f"[Non-Blocking] LiteLLM.Success_Call Error: {str(e)}")
def success_handler(
def success_handler( # noqa: PLR0915
self, result=None, start_time=None, end_time=None, cache_hit=None, **kwargs
):
print_verbose(f"Logging Details LiteLLM-Success Call: Cache_hit={cache_hit}")
@ -1494,7 +1494,7 @@ class Logging:
),
)
async def async_success_handler(
async def async_success_handler( # noqa: PLR0915
self, result=None, start_time=None, end_time=None, cache_hit=None, **kwargs
):
"""
@ -1833,7 +1833,7 @@ class Logging:
kwargs=self.model_call_details,
) # type: ignore
def failure_handler(
def failure_handler( # noqa: PLR0915
self, exception, traceback_exception, start_time=None, end_time=None
):
verbose_logger.debug(
@ -2191,7 +2191,7 @@ class Logging:
return None
def set_callbacks(callback_list, function_id=None):
def set_callbacks(callback_list, function_id=None): # noqa: PLR0915
"""
Globally sets the callback client
"""
@ -2301,7 +2301,7 @@ def set_callbacks(callback_list, function_id=None):
raise e
def _init_custom_logger_compatible_class(
def _init_custom_logger_compatible_class( # noqa: PLR0915
logging_integration: litellm._custom_logger_compatible_callbacks_literal,
internal_usage_cache: Optional[DualCache],
llm_router: Optional[
@ -2629,7 +2629,7 @@ def is_valid_sha256_hash(value: str) -> bool:
return bool(re.fullmatch(r"[a-fA-F0-9]{64}", value))
def get_standard_logging_object_payload(
def get_standard_logging_object_payload( # noqa: PLR0915
kwargs: Optional[dict],
init_response_obj: Union[Any, BaseModel, dict],
start_time: dt_object,

View file

@ -344,7 +344,7 @@ class AzureChatCompletion(BaseLLM):
except Exception as e:
raise e
def completion(
def completion( # noqa: PLR0915
self,
model: str,
messages: list,

View file

@ -612,7 +612,7 @@ class OpenAIChatCompletion(BaseLLM):
else:
raise e
def completion( # type: ignore
def completion( # type: ignore # noqa: PLR0915
self,
model_response: ModelResponse,
timeout: Union[float, httpx.Timeout],

View file

@ -73,7 +73,7 @@ class AnthropicExperimentalPassThroughConfig:
"""
return ["messages", "metadata", "system", "tool_choice", "tools"]
def translate_anthropic_messages_to_openai(
def translate_anthropic_messages_to_openai( # noqa: PLR0915
self,
messages: List[
Union[

View file

@ -141,7 +141,7 @@ class AzureTextCompletion(BaseLLM):
headers["Authorization"] = f"Bearer {azure_ad_token}"
return headers
def completion(
def completion( # noqa: PLR0915
self,
model: str,
messages: list,

View file

@ -38,7 +38,7 @@ class BaseAWSLLM(BaseLLM):
credential_str = json.dumps(credential_args, sort_keys=True)
return hashlib.sha256(credential_str.encode()).hexdigest()
def get_credentials(
def get_credentials( # noqa: PLR0915
self,
aws_access_key_id: Optional[str] = None,
aws_secret_access_key: Optional[str] = None,

View file

@ -200,7 +200,7 @@ class BedrockConverseLLM(BaseAWSLLM):
encoding=encoding,
)
def completion(
def completion( # noqa: PLR0915
self,
model: str,
messages: list,

View file

@ -308,7 +308,7 @@ class BedrockLLM(BaseAWSLLM):
prompt += f"{message['content']}"
return prompt, chat_history # type: ignore
def process_response(
def process_response( # noqa: PLR0915
self,
model: str,
response: Union[requests.Response, httpx.Response],
@ -574,7 +574,7 @@ class BedrockLLM(BaseAWSLLM):
"""
return urllib.parse.quote(model_id, safe="")
def completion(
def completion( # noqa: PLR0915
self,
model: str,
messages: list,

View file

@ -333,7 +333,7 @@ class Huggingface(BaseLLM):
headers = default_headers
return headers
def convert_to_model_response_object(
def convert_to_model_response_object( # noqa: PLR0915
self,
completion_response,
model_response: litellm.ModelResponse,
@ -447,7 +447,7 @@ class Huggingface(BaseLLM):
model_response._hidden_params["original_response"] = completion_response
return model_response
def completion(
def completion( # noqa: PLR0915
self,
model: str,
messages: list,

View file

@ -213,7 +213,7 @@ class OllamaChatConfig:
# ollama implementation
def get_ollama_response(
def get_ollama_response( # noqa: PLR0915
model_response: litellm.ModelResponse,
messages: list,
optional_params: dict,

View file

@ -240,7 +240,7 @@ class PredibaseChatCompletion(BaseLLM):
generated_text = generated_text[::-1].replace(token[::-1], "", 1)[::-1]
return generated_text
def process_response(
def process_response( # noqa: PLR0915
self,
model: str,
response: Union[requests.Response, httpx.Response],

View file

@ -385,7 +385,9 @@ known_tokenizer_config = {
}
def hf_chat_template(model: str, messages: list, chat_template: Optional[Any] = None):
def hf_chat_template( # noqa: PLR0915
model: str, messages: list, chat_template: Optional[Any] = None
):
# Define Jinja2 environment
env = ImmutableSandboxedEnvironment()
@ -1339,7 +1341,7 @@ def add_cache_control_to_content(
return anthropic_content_element
def anthropic_messages_pt(
def anthropic_messages_pt( # noqa: PLR0915
messages: List[AllMessageValues],
model: str,
llm_provider: str,
@ -1797,7 +1799,7 @@ def convert_to_cohere_tool_invoke(tool_calls: list) -> List[ToolCallObject]:
return cohere_tool_invoke
def cohere_messages_pt_v2(
def cohere_messages_pt_v2( # noqa: PLR0915
messages: List,
model: str,
llm_provider: str,
@ -2409,7 +2411,7 @@ def _insert_assistant_continue_message(
return messages
def _bedrock_converse_messages_pt(
def _bedrock_converse_messages_pt( # noqa: PLR0915
messages: List,
model: str,
llm_provider: str,

View file

@ -248,7 +248,7 @@ class SagemakerLLM(BaseAWSLLM):
return prompt
def completion(
def completion( # noqa: PLR0915
self,
model: str,
messages: list,

View file

@ -742,7 +742,7 @@ class VertexLLM(VertexBase):
def __init__(self) -> None:
super().__init__()
def _process_response(
def _process_response( # noqa: PLR0915
self,
model: str,
response: httpx.Response,

View file

@ -131,7 +131,7 @@ def _process_gemini_image(image_url: str) -> PartType:
raise e
def _gemini_convert_messages_with_history(
def _gemini_convert_messages_with_history( # noqa: PLR0915
messages: List[AllMessageValues],
) -> List[ContentType]:
"""
@ -279,7 +279,7 @@ def _set_client_in_cache(client_cache_key: str, vertex_llm_model: Any):
litellm.in_memory_llm_clients_cache[client_cache_key] = vertex_llm_model
def completion(
def completion( # noqa: PLR0915
model: str,
messages: list,
model_response: ModelResponse,
@ -770,7 +770,7 @@ def completion(
)
async def async_completion(
async def async_completion( # noqa: PLR0915
llm_model,
mode: str,
prompt: str,
@ -1010,7 +1010,7 @@ async def async_completion(
raise VertexAIError(status_code=500, message=str(e))
async def async_streaming(
async def async_streaming( # noqa: PLR0915
llm_model,
mode: str,
prompt: str,

View file

@ -657,7 +657,7 @@ def mock_completion(
@client
def completion( # type: ignore
def completion( # type: ignore # noqa: PLR0915
model: str,
# Optional OpenAI params: see https://platform.openai.com/docs/api-reference/chat/create
messages: List = [],
@ -3136,7 +3136,7 @@ async def aembedding(*args, **kwargs) -> EmbeddingResponse:
@client
def embedding(
def embedding( # noqa: PLR0915
model,
input=[],
# Optional params
@ -3911,7 +3911,7 @@ async def atext_completion(
@client
def text_completion(
def text_completion( # noqa: PLR0915
prompt: Union[
str, List[Union[str, List[Union[str, List[int]]]]]
], # Required: The prompt(s) to generate completions for.
@ -4378,7 +4378,7 @@ async def aimage_generation(*args, **kwargs) -> ImageResponse:
@client
def image_generation(
def image_generation( # noqa: PLR0915
prompt: str,
model: Optional[str] = None,
n: Optional[int] = None,
@ -5111,7 +5111,7 @@ def speech(
##### Health Endpoints #######################
async def ahealth_check(
async def ahealth_check( # noqa: PLR0915
model_params: dict,
mode: Optional[
Literal[
@ -5374,7 +5374,7 @@ def stream_chunk_builder_text_completion(
return TextCompletionResponse(**response)
def stream_chunk_builder(
def stream_chunk_builder( # noqa: PLR0915
chunks: list, messages: Optional[list] = None, start_time=None, end_time=None
) -> Optional[Union[ModelResponse, TextCompletionResponse]]:
try:

View file

@ -44,7 +44,7 @@ else:
all_routes = LiteLLMRoutes.openai_routes.value + LiteLLMRoutes.management_routes.value
def common_checks(
def common_checks( # noqa: PLR0915
request_body: dict,
team_object: Optional[LiteLLM_TeamTable],
user_object: Optional[LiteLLM_UserTable],

View file

@ -105,7 +105,7 @@ def _get_bearer_token(
return api_key
async def user_api_key_auth(
async def user_api_key_auth( # noqa: PLR0915
request: Request,
api_key: str = fastapi.Security(api_key_header),
azure_api_key_header: str = fastapi.Security(azure_api_key_header),

View file

@ -11,7 +11,7 @@ blue_color_code = "\033[94m"
reset_color_code = "\033[0m"
def initialize_callbacks_on_proxy(
def initialize_callbacks_on_proxy( # noqa: PLR0915
value: Any,
premium_user: bool,
config_file_path: str,

View file

@ -5,7 +5,7 @@ from litellm import verbose_logger
_db = Any
async def create_missing_views(db: _db):
async def create_missing_views(db: _db): # noqa: PLR0915
"""
--------------------------------------------------
NOTE: Copy of `litellm/db_scripts/create_views.py`.

View file

@ -119,7 +119,7 @@ class lakeraAI_Moderation(CustomGuardrail):
return None
async def _check(
async def _check( # noqa: PLR0915
self,
data: dict,
user_api_key_dict: UserAPIKeyAuth,

View file

@ -86,7 +86,7 @@ Map guardrail_name: <pre_call>, <post_call>, during_call
"""
def init_guardrails_v2(
def init_guardrails_v2( # noqa: PLR0915
all_guardrails: List[Dict],
config_file_path: Optional[str] = None,
):

View file

@ -53,7 +53,7 @@ async def test_endpoint(request: Request):
dependencies=[Depends(user_api_key_auth)],
include_in_schema=False,
)
async def health_services_endpoint(
async def health_services_endpoint( # noqa: PLR0915
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
service: Union[
Literal[

View file

@ -117,7 +117,7 @@ class _PROXY_MaxParallelRequestsHandler(CustomLogger):
headers={"retry-after": str(self.time_to_next_minute())},
)
async def async_pre_call_hook(
async def async_pre_call_hook( # noqa: PLR0915
self,
user_api_key_dict: UserAPIKeyAuth,
cache: DualCache,
@ -411,7 +411,9 @@ class _PROXY_MaxParallelRequestsHandler(CustomLogger):
return
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
async def async_log_success_event( # noqa: PLR0915
self, kwargs, response_obj, start_time, end_time
):
from litellm.proxy.common_utils.callback_utils import (
get_model_group_from_litellm_kwargs,
)

View file

@ -211,7 +211,7 @@ def add_litellm_data_for_backend_llm_call(
return data
async def add_litellm_data_to_request(
async def add_litellm_data_to_request( # noqa: PLR0915
data: dict,
request: Request,
user_api_key_dict: UserAPIKeyAuth,

View file

@ -308,7 +308,7 @@ def get_team_from_list(
# response_model=UserInfoResponse,
)
@management_endpoint_wrapper
async def user_info(
async def user_info( # noqa: PLR0915
user_id: Optional[str] = fastapi.Query(
default=None, description="User ID in the request parameters"
),

View file

@ -45,7 +45,7 @@ router = APIRouter()
response_model=GenerateKeyResponse,
)
@management_endpoint_wrapper
async def generate_key_fn(
async def generate_key_fn( # noqa: PLR0915
data: GenerateKeyRequest,
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
litellm_changed_by: Optional[str] = Header(
@ -768,7 +768,7 @@ async def info_key_fn(
)
async def generate_key_helper_fn(
async def generate_key_helper_fn( # noqa: PLR0915
request_type: Literal[
"user", "key"
], # identifies if this request is from /user/new or /key/generate

View file

@ -92,7 +92,7 @@ async def get_all_team_memberships(
response_model=LiteLLM_TeamTable,
)
@management_endpoint_wrapper
async def new_team(
async def new_team( # noqa: PLR0915
data: NewTeamRequest,
http_request: Request,
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),

View file

@ -46,7 +46,7 @@ router = APIRouter()
@router.get("/sso/key/generate", tags=["experimental"], include_in_schema=False)
async def google_login(request: Request):
async def google_login(request: Request): # noqa: PLR0915
"""
Create Proxy API Keys using Google Workspace SSO. Requires setting PROXY_BASE_URL in .env
PROXY_BASE_URL should be the your deployed proxy endpoint, e.g. PROXY_BASE_URL="https://litellm-production-7002.up.railway.app/"
@ -221,7 +221,7 @@ async def google_login(request: Request):
@router.get("/sso/callback", tags=["experimental"], include_in_schema=False)
async def auth_callback(request: Request):
async def auth_callback(request: Request): # noqa: PLR0915
"""Verify login"""
from litellm.proxy.management_endpoints.key_management_endpoints import (
generate_key_helper_fn,

View file

@ -105,7 +105,7 @@ async def set_env_variables_in_header(custom_headers: Optional[dict]) -> Optiona
return headers
async def chat_completion_pass_through_endpoint(
async def chat_completion_pass_through_endpoint( # noqa: PLR0915
fastapi_response: Response,
request: Request,
adapter_id: str,
@ -306,7 +306,7 @@ def get_endpoint_type(url: str) -> EndpointType:
return EndpointType.GENERIC
async def pass_through_request(
async def pass_through_request( # noqa: PLR0915
request: Request,
target: str,
custom_headers: dict,

View file

@ -216,7 +216,7 @@ def is_port_in_use(port):
envvar="SSL_CERTFILE_PATH",
)
@click.option("--local", is_flag=True, default=False, help="for local debugging")
def run_server(
def run_server( # noqa: PLR0915
host,
port,
api_base,

View file

@ -881,7 +881,7 @@ def _set_spend_logs_payload(
return prisma_client
async def update_database(
async def update_database( # noqa: PLR0915
token,
response_cost,
user_id=None,
@ -1063,7 +1063,7 @@ async def update_database(
)
async def update_cache(
async def update_cache( # noqa: PLR0915
token: Optional[str],
user_id: Optional[str],
end_user_id: Optional[str],
@ -1492,7 +1492,7 @@ class ProxyConfig:
## INIT PROXY REDIS USAGE CLIENT ##
redis_usage_cache = litellm.cache.cache
async def load_config(
async def load_config( # noqa: PLR0915
self, router: Optional[litellm.Router], config_file_path: str
):
"""
@ -2144,7 +2144,7 @@ class ProxyConfig:
added_models += 1
return added_models
async def _update_llm_router(
async def _update_llm_router( # noqa: PLR0915
self,
new_models: list,
proxy_logging_obj: ProxyLogging,
@ -2387,7 +2387,7 @@ def save_worker_config(**data):
os.environ["WORKER_CONFIG"] = json.dumps(data)
async def initialize(
async def initialize( # noqa: PLR0915
model=None,
alias=None,
api_base=None,
@ -2728,7 +2728,7 @@ def giveup(e):
@router.on_event("startup")
async def startup_event():
async def startup_event(): # noqa: PLR0915
global prisma_client, master_key, use_background_health_checks, llm_router, llm_model_list, general_settings, proxy_budget_rescheduler_min_time, proxy_budget_rescheduler_max_time, litellm_proxy_admin_name, db_writer_client, store_model_in_db, premium_user, _license_check
import json
@ -3078,7 +3078,7 @@ async def model_list(
giveup=giveup,
logger=verbose_proxy_logger,
)
async def chat_completion(
async def chat_completion( # noqa: PLR0915
request: Request,
fastapi_response: Response,
model: Optional[str] = None,
@ -3357,7 +3357,7 @@ async def chat_completion(
dependencies=[Depends(user_api_key_auth)],
tags=["completions"],
)
async def completion(
async def completion( # noqa: PLR0915
request: Request,
fastapi_response: Response,
model: Optional[str] = None,
@ -3580,7 +3580,7 @@ async def completion(
response_class=ORJSONResponse,
tags=["embeddings"],
) # azure compatible endpoint
async def embeddings(
async def embeddings( # noqa: PLR0915
request: Request,
fastapi_response: Response,
model: Optional[str] = None,
@ -5469,7 +5469,7 @@ async def moderations(
dependencies=[Depends(user_api_key_auth)],
response_model=AnthropicResponse,
)
async def anthropic_response(
async def anthropic_response( # noqa: PLR0915
anthropic_data: AnthropicMessagesRequest,
fastapi_response: Response,
request: Request,
@ -7278,7 +7278,7 @@ async def model_metrics_exceptions(
tags=["model management"],
dependencies=[Depends(user_api_key_auth)],
)
async def model_info_v1(
async def model_info_v1( # noqa: PLR0915
user_api_key_dict: UserAPIKeyAuth = Depends(user_api_key_auth),
litellm_model_id: Optional[str] = None,
):
@ -7985,7 +7985,7 @@ async def fallback_login(request: Request):
@router.post(
"/login", include_in_schema=False
) # hidden since this is a helper for UI sso login
async def login(request: Request):
async def login(request: Request): # noqa: PLR0915
global premium_user, general_settings
try:
import multipart
@ -8653,7 +8653,7 @@ async def invitation_delete(
dependencies=[Depends(user_api_key_auth)],
include_in_schema=False,
)
async def update_config(config_info: ConfigYAML):
async def update_config(config_info: ConfigYAML): # noqa: PLR0915
"""
For Admin UI - allows admin to update config via UI
@ -9156,7 +9156,7 @@ async def delete_config_general_settings(
include_in_schema=False,
dependencies=[Depends(user_api_key_auth)],
)
async def get_config():
async def get_config(): # noqa: PLR0915
"""
For Admin UI - allows admin to view config via UI
# return the callbacks and the env variables for the callback

View file

@ -1597,7 +1597,7 @@ async def calculate_spend(request: SpendCalculateRequest):
200: {"model": List[LiteLLM_SpendLogs]},
},
)
async def view_spend_logs(
async def view_spend_logs( # noqa: PLR0915
api_key: Optional[str] = fastapi.Query(
default=None,
description="Get spend logs based on api key",

View file

@ -1426,7 +1426,7 @@ class PrismaClient:
on_backoff=on_backoff, # specifying the function to call on backoff
)
@log_to_opentelemetry
async def get_data(
async def get_data( # noqa: PLR0915
self,
token: Optional[Union[str, list]] = None,
user_id: Optional[str] = None,
@ -1780,7 +1780,7 @@ class PrismaClient:
max_time=10, # maximum total time to retry for
on_backoff=on_backoff, # specifying the function to call on backoff
)
async def insert_data(
async def insert_data( # noqa: PLR0915
self,
data: dict,
table_name: Literal[
@ -1928,7 +1928,7 @@ class PrismaClient:
max_time=10, # maximum total time to retry for
on_backoff=on_backoff, # specifying the function to call on backoff
)
async def update_data(
async def update_data( # noqa: PLR0915
self,
token: Optional[str] = None,
data: dict = {},
@ -2617,7 +2617,7 @@ async def reset_budget(prisma_client: PrismaClient):
)
async def update_spend(
async def update_spend( # noqa: PLR0915
prisma_client: PrismaClient,
db_writer_client: Optional[HTTPHandler],
proxy_logging_obj: ProxyLogging,

View file

@ -156,7 +156,7 @@ class Router:
leastbusy_logger: Optional[LeastBusyLoggingHandler] = None
lowesttpm_logger: Optional[LowestTPMLoggingHandler] = None
def __init__(
def __init__( # noqa: PLR0915
self,
model_list: Optional[
Union[List[DeploymentTypedDict], List[Dict[str, Any]]]
@ -2565,7 +2565,7 @@ class Router:
#### [END] ASSISTANTS API ####
async def async_function_with_fallbacks(self, *args, **kwargs):
async def async_function_with_fallbacks(self, *args, **kwargs): # noqa: PLR0915
"""
Try calling the function_with_retries
If it fails after num_retries, fall back to another model group
@ -4170,7 +4170,7 @@ class Router:
model_name = model_info["model_name"]
return self.get_model_list(model_name=model_name)
def _set_model_group_info(
def _set_model_group_info( # noqa: PLR0915
self, model_group: str, user_facing_model_group_name: str
) -> Optional[ModelGroupInfo]:
"""
@ -4696,7 +4696,7 @@ class Router:
client = self.cache.get_cache(key=cache_key)
return client
def _pre_call_checks(
def _pre_call_checks( # noqa: PLR0915
self,
model: str,
healthy_deployments: List,

View file

@ -209,7 +209,7 @@ class LowestCostLoggingHandler(CustomLogger):
)
pass
async def async_get_available_deployments(
async def async_get_available_deployments( # noqa: PLR0915
self,
model_group: str,
healthy_deployments: list,

View file

@ -44,7 +44,9 @@ class LowestLatencyLoggingHandler(CustomLogger):
self.model_list = model_list
self.routing_args = RoutingArgs(**routing_args)
def log_success_event(self, kwargs, response_obj, start_time, end_time):
def log_success_event( # noqa: PLR0915
self, kwargs, response_obj, start_time, end_time
):
try:
"""
Update latency usage on success
@ -244,7 +246,9 @@ class LowestLatencyLoggingHandler(CustomLogger):
)
pass
async def async_log_success_event(self, kwargs, response_obj, start_time, end_time):
async def async_log_success_event( # noqa: PLR0915
self, kwargs, response_obj, start_time, end_time
):
try:
"""
Update latency usage on success
@ -375,7 +379,7 @@ class LowestLatencyLoggingHandler(CustomLogger):
)
pass
def get_available_deployments(
def get_available_deployments( # noqa: PLR0915
self,
model_group: str,
healthy_deployments: list,

View file

@ -166,7 +166,7 @@ class LowestTPMLoggingHandler(CustomLogger):
verbose_router_logger.debug(traceback.format_exc())
pass
def get_available_deployments(
def get_available_deployments( # noqa: PLR0915
self,
model_group: str,
healthy_deployments: list,

View file

@ -318,7 +318,7 @@ class LowestTPMLoggingHandler_v2(CustomLogger):
)
pass
def _common_checks_available_deployment(
def _common_checks_available_deployment( # noqa: PLR0915
self,
model_group: str,
healthy_deployments: list,

View file

@ -48,7 +48,7 @@ def should_initialize_sync_client(
return True
def set_client(litellm_router_instance: LitellmRouter, model: dict):
def set_client(litellm_router_instance: LitellmRouter, model: dict): # noqa: PLR0915
"""
- Initializes Azure/OpenAI clients. Stores them in cache, b/c of this - https://github.com/BerriAI/litellm/issues/1278
- Initializes Semaphore for client w/ rpm. Stores them in cache. b/c of this - https://github.com/BerriAI/litellm/issues/2994

View file

@ -67,7 +67,7 @@ def get_secret_str(
return value
def get_secret(
def get_secret( # noqa: PLR0915
secret_name: str,
default_value: Optional[Union[str, bool]] = None,
):

View file

@ -328,7 +328,7 @@ def custom_llm_setup():
litellm._custom_providers.append(custom_llm["provider"])
def function_setup(
def function_setup( # noqa: PLR0915
original_function: str, rules_obj, start_time, *args, **kwargs
): # just run once to check if user wants to send their data anywhere - PostHog/Sentry/Slack/etc.
### NOTICES ###
@ -605,7 +605,7 @@ def function_setup(
raise e
def client(original_function):
def client(original_function): # noqa: PLR0915
global liteDebuggerClient
rules_obj = Rules()
@ -721,7 +721,7 @@ def client(original_function):
raise e
@wraps(original_function)
def wrapper(*args, **kwargs):
def wrapper(*args, **kwargs): # noqa: PLR0915
# DO NOT MOVE THIS. It always needs to run first
# Check if this is an async function. If so only execute the async function
if (
@ -1007,7 +1007,7 @@ def client(original_function):
raise e
@wraps(original_function)
async def wrapper_async(*args, **kwargs):
async def wrapper_async(*args, **kwargs): # noqa: PLR0915
print_args_passed_to_litellm(original_function, args, kwargs)
start_time = datetime.datetime.now()
result = None
@ -1289,7 +1289,7 @@ def decode(model="", tokens: List[int] = [], custom_tokenizer: Optional[dict] =
return dec
def openai_token_counter(
def openai_token_counter( # noqa: PLR0915
messages: Optional[list] = None,
model="gpt-3.5-turbo-0613",
text: Optional[str] = None,
@ -1930,7 +1930,7 @@ def _update_dictionary(existing_dict: Dict, new_dict: dict) -> dict:
return existing_dict
def register_model(model_cost: Union[str, dict]):
def register_model(model_cost: Union[str, dict]): # noqa: PLR0915
"""
Register new / Override existing models (and their pricing) to specific providers.
Provide EITHER a model cost dictionary or a url to a hosted json blob
@ -2253,7 +2253,7 @@ def get_optional_params_image_gen(
return optional_params
def get_optional_params_embeddings(
def get_optional_params_embeddings( # noqa: PLR0915
# 2 optional params
model: str,
user: Optional[str] = None,
@ -2469,7 +2469,7 @@ def _remove_strict_from_schema(schema):
return schema
def get_optional_params(
def get_optional_params( # noqa: PLR0915
# use the openai defaults
# https://platform.openai.com/docs/api-reference/chat/create
model: str,
@ -4077,7 +4077,7 @@ def get_first_chars_messages(kwargs: dict) -> str:
return ""
def get_supported_openai_params(
def get_supported_openai_params( # noqa: PLR0915
model: str,
custom_llm_provider: Optional[str] = None,
request_type: Literal["chat_completion", "embeddings"] = "chat_completion",
@ -4573,7 +4573,9 @@ def _get_model_info_from_model_cost(key: str) -> dict:
return litellm.model_cost[key]
def get_model_info(model: str, custom_llm_provider: Optional[str] = None) -> ModelInfo:
def get_model_info( # noqa: PLR0915
model: str, custom_llm_provider: Optional[str] = None
) -> ModelInfo:
"""
Get a dict for the maximum tokens (context window), input_cost_per_token, output_cost_per_token for a given model.
@ -5116,7 +5118,7 @@ def create_proxy_transport_and_mounts():
return sync_proxy_mounts, async_proxy_mounts
def validate_environment(
def validate_environment( # noqa: PLR0915
model: Optional[str] = None, api_key: Optional[str] = None
) -> dict:
"""
@ -5605,7 +5607,7 @@ def _handle_invalid_parallel_tool_calls(
return tool_calls
def convert_to_model_response_object(
def convert_to_model_response_object( # noqa: PLR0915
response_object: Optional[dict] = None,
model_response_object: Optional[
Union[
@ -7170,7 +7172,7 @@ class CustomStreamWrapper:
is_empty = False
return is_empty
def chunk_creator(self, chunk): # type: ignore
def chunk_creator(self, chunk): # type: ignore # noqa: PLR0915
model_response = self.model_response_creator()
response_obj = {}
try:
@ -7881,7 +7883,7 @@ class CustomStreamWrapper:
model_response.choices[0].finish_reason = "tool_calls"
return model_response
def __next__(self):
def __next__(self): # noqa: PLR0915
cache_hit = False
if (
self.custom_llm_provider is not None
@ -8016,7 +8018,7 @@ class CustomStreamWrapper:
return self.completion_stream
async def __anext__(self):
async def __anext__(self): # noqa: PLR0915
cache_hit = False
if (
self.custom_llm_provider is not None

View file

@ -1,4 +1,4 @@
ignore = ["F405", "E402", "F401", "E501", "F403"]
extend-select = ["E501"]
extend-select = ["E501", "PLR0915"]
line-length = 120
exclude = ["litellm/types/*", "litellm/__init__.py", "litellm/proxy/example_config_yaml/*"]