The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix: fix minor linting errors
Krrish Dholakiaebeefd2be1fe
diff --git a/litellm/llms/anthropic/completion/transformation.py b/litellm/llms/anthropic/completion/transformation.pyindex 9e3287aa8a1..a8798cd5d0e 100644--- a/litellm/llms/anthropic/completion/transformation.py+++ b/litellm/llms/anthropic/completion/transformation.py@@ -55,9 +55,9 @@ class AnthropicTextConfig(BaseConfig):to pass metadata to anthropic, it's {"user_id": "any-relevant-information"}"""- max_tokens_to_sample: Optional[- int- ] = litellm.max_tokens # anthropic requires a default+ max_tokens_to_sample: Optional[int] = (+ litellm.max_tokens+ ) # anthropic requires a defaultstop_sequences: Optional[list] = Nonetemperature: Optional[int] = Nonetop_p: Optional[int] = None@@ -291,7 +291,7 @@ class AnthropicTextCompletionResponseIterator(BaseModelResponseIterator):_chunk_text = chunk.get("completion", None)if _chunk_text is not None and isinstance(_chunk_text, str):text = _chunk_text- finish_reason = chunk.get("stop_reason", None)+ finish_reason = chunk.get("stop_reason") or ""if finish_reason is not None:is_finished = Truereturned_chunk = GenericStreamingChunk(diff --git a/litellm/llms/anthropic/cost_calculation.py b/litellm/llms/anthropic/cost_calculation.pyindex 56a83324d91..8f34eb00ce5 100644--- a/litellm/llms/anthropic/cost_calculation.py+++ b/litellm/llms/anthropic/cost_calculation.py@@ -49,7 +49,7 @@ def get_cost_for_anthropic_web_search(## Get the cost per web search requestsearch_context_pricing: SearchContextCostPerQuery = (- model_info.get("search_context_cost_per_query", {}) or {}+ model_info.get("search_context_cost_per_query") or SearchContextCostPerQuery())cost_per_web_search_request = search_context_pricing.get("search_context_size_medium", 0.0diff --git a/litellm/llms/bedrock/chat/invoke_handler.py b/litellm/llms/bedrock/chat/invoke_handler.pyindex 0d1b4102c94..71aadffe5bb 100644--- a/litellm/llms/bedrock/chat/invoke_handler.py+++ b/litellm/llms/bedrock/chat/invoke_handler.py@@ -7,7 +7,6 @@ import jsonimport timeimport typesimport urllib.parse-from litellm._uuid import uuidfrom functools import partialfrom typing import (Any,@@ -26,6 +25,7 @@ import httpx # type: ignoreimport litellmfrom litellm import verbose_logger+from litellm._uuid import uuidfrom litellm.caching.caching import InMemoryCachefrom litellm.litellm_core_utils.core_helpers import map_finish_reasonfrom litellm.litellm_core_utils.litellm_logging import Logging@@ -498,9 +498,9 @@ class BedrockLLM(BaseAWSLLM):content=None,)model_response.choices[0].message = _message # type: ignore- model_response._hidden_params[- "original_response"- ] = outputText # allow user to access raw anthropic tool calling response+ model_response._hidden_params["original_response"] = (+ outputText # allow user to access raw anthropic tool calling response+ )if (_is_function_call is Trueand stream is not None@@ -808,9 +808,9 @@ class BedrockLLM(BaseAWSLLM):): # completion(top_k=3) > anthropic_config(top_k=3) <- allows for dynamic variables to be passed ininference_params[k] = vif stream is True:- inference_params[- "stream"- ] = True # cohere requires stream = True in inference params+ inference_params["stream"] = (+ True # cohere requires stream = True in inference params+ )data = json.dumps({"prompt": prompt, **inference_params})elif provider == "anthropic":if model.startswith("anthropic.claude-3"):@@ -1352,9 +1352,11 @@ class AWSEventStreamDecoder:"name": None,"arguments": delta_obj["toolUse"]["input"],},- "index": self.tool_calls_index- if self.tool_calls_index is not None- else index,+ "index": (+ self.tool_calls_index+ if self.tool_calls_index is not None+ else index+ ),}elif "reasoningContent" in delta_obj:provider_specific_fields = {@@ -1384,9 +1386,11 @@ class AWSEventStreamDecoder:"name": None,"arguments": "{}",},- "index": self.tool_calls_index- if self.tool_calls_index is not None- else index,+ "index": (+ self.tool_calls_index+ if self.tool_calls_index is not None+ else index+ ),}elif "stopReason" in chunk_data:finish_reason = map_finish_reason(chunk_data.get("stopReason", "stop"))@@ -1448,7 +1452,7 @@ class AWSEventStreamDecoder:######### /bedrock/invoke nova mappings ###############elif "contentBlockDelta" in chunk_data:# when using /bedrock/invoke/nova, the chunk_data is nested under "contentBlockDelta"- _chunk_data = chunk_data.get("contentBlockDelta", None)+ _chunk_data = chunk_data.get("contentBlockDelta", {})return self.converse_chunk_parser(chunk_data=_chunk_data)######## bedrock.mistral mappings ###############elif "outputs" in chunk_data:diff --git a/litellm/llms/huggingface/embedding/transformation.py b/litellm/llms/huggingface/embedding/transformation.pyindex 60bd5dcd617..88d42cfcdcc 100644--- a/litellm/llms/huggingface/embedding/transformation.py+++ b/litellm/llms/huggingface/embedding/transformation.py@@ -40,17 +40,17 @@ class HuggingFaceEmbeddingConfig(BaseConfig):Reference: https://huggingface.github.io/text-generation-inference/#/Text%20Generation%20Inference/compat_generate"""- hf_task: Optional[- hf_tasks- ] = None # litellm-specific param, used to know the api spec to use when calling huggingface api+ hf_task: Optional[hf_tasks] = (+ None # litellm-specific param, used to know the api spec to use when calling huggingface api+ )best_of: Optional[int] = Nonedecoder_input_details: Optional[bool] = Nonedetails: Optional[bool] = True # enables returning logprobs + best ofmax_new_tokens: Optional[int] = Nonerepetition_penalty: Optional[float] = None- return_full_text: Optional[- bool- ] = False # by default don't return the input as part of the output+ return_full_text: Optional[bool] = (+ False # by default don't return the input as part of the output+ )seed: Optional[int] = Nonetemperature: Optional[float] = Nonetop_k: Optional[int] = None@@ -120,9 +120,9 @@ class HuggingFaceEmbeddingConfig(BaseConfig):optional_params["top_p"] = valueif param == "n":optional_params["best_of"] = value- optional_params[- "do_sample"- ] = True # Need to sample if you want best of for hf inference endpoints+ optional_params["do_sample"] = (+ True # Need to sample if you want best of for hf inference endpoints+ )if param == "stream":optional_params["stream"] = valueif param == "stop":@@ -268,7 +268,7 @@ class HuggingFaceEmbeddingConfig(BaseConfig):# check if the model has a registered custom promptmodel_prompt_details = litellm.custom_prompt_dict[model]prompt = custom_prompt(- role_dict=model_prompt_details.get("roles", None),+ role_dict=model_prompt_details.get("roles") or {},initial_prompt_value=model_prompt_details.get("initial_prompt_value", ""),@@ -363,9 +363,9 @@ class HuggingFaceEmbeddingConfig(BaseConfig):"content-type": "application/json",}if api_key is not None:- default_headers[- "Authorization"- ] = f"Bearer {api_key}" # Huggingface Inference Endpoint default is to accept bearer tokens+ default_headers["Authorization"] = (+ f"Bearer {api_key}" # Huggingface Inference Endpoint default is to accept bearer tokens+ )headers = {**headers, **default_headers}return headers