Merge remote-tracking branch 'origin/litellm_internal_staging' into litellm_fix_unscoped_managed_files

# Conflicts:
#	tests/test_litellm/proxy/openai_files_endpoint/test_files_endpoint.py
This commit is contained in:
mateo-berri 2026-08-22 09:56:50 -07:00
commit 7d61d9d71e
1002 changed files with 470 additions and 3832 deletions

View file

@ -1,6 +1,6 @@
[project]
name = "litellm-enterprise"
version = "0.1.58"
version = "0.1.59"
description = "Package for LiteLLM Enterprise features"
readme = "README.md"
requires-python = ">=3.9"
@ -26,7 +26,7 @@ required-version = ">=0.10.9"
module-root = ""
[tool.commitizen]
version = "0.1.58"
version = "0.1.59"
version_files = [
"pyproject.toml:^version",
"../pyproject.toml:litellm-enterprise==",

View file

@ -1,6 +1,6 @@
[project]
name = "litellm-proxy-extras"
version = "0.4.88"
version = "0.4.89"
description = "Additional files for the LiteLLM Proxy. Reduces the size of the main litellm package."
readme = "README.md"
requires-python = ">=3.9"
@ -26,7 +26,7 @@ required-version = ">=0.10.9"
module-root = ""
[tool.commitizen]
version = "0.4.88"
version = "0.4.89"
version_files = [
"pyproject.toml:^version",
"../pyproject.toml:litellm-proxy-extras==",

View file

@ -1,3 +1,4 @@
from collections.abc import Sequence
from typing import Final
from litellm.types.utils import ProviderSpecificHeader
@ -6,13 +7,17 @@ from litellm.types.utils import ProviderSpecificHeader
class ProviderSpecificHeaderUtils:
@staticmethod
def get_provider_specific_headers(
provider_specific_header: ProviderSpecificHeader | None,
provider_specific_header: ProviderSpecificHeader | Sequence[ProviderSpecificHeader] | None,
custom_llm_provider: str | None,
) -> dict:
"""
Get the provider specific headers for the given custom llm provider.
Supports comma-separated provider lists for headers that work across multiple providers.
Accepts either a single ProviderSpecificHeader or a sequence of them. Each entry
carries its own comma-separated provider list, so headers that are safe for several
providers and headers that are safe for exactly one can travel on the same request
without sharing a scope. Entries whose provider list does not contain
`custom_llm_provider` contribute nothing.
Returns:
Dict: The provider specific headers for the given custom llm provider
@ -20,10 +25,15 @@ class ProviderSpecificHeaderUtils:
if provider_specific_header is None or custom_llm_provider is None:
return {}
stored_providers: Final = provider_specific_header.get("custom_llm_provider", "")
provider_list: Final = [p.strip() for p in stored_providers.split(",")]
scoped_headers: Final = (
(provider_specific_header,) if isinstance(provider_specific_header, dict) else provider_specific_header
)
if custom_llm_provider in provider_list:
return provider_specific_header.get("extra_headers", {})
matched_headers: Final = {}
for scoped_header in scoped_headers:
stored_providers = scoped_header.get("custom_llm_provider", "")
provider_list = [p.strip() for p in stored_providers.split(",")]
if custom_llm_provider in provider_list:
matched_headers.update(scoped_header.get("extra_headers", {}))
return {}
return matched_headers

View file

@ -2056,7 +2056,7 @@ class BaseLLMHTTPHandler:
# Prepare headers
kwargs = kwargs or {}
provider_specific_header: Final = cast(
litellm.types.utils.ProviderSpecificHeader | None,
litellm.types.utils.ProviderSpecificHeader | Sequence[litellm.types.utils.ProviderSpecificHeader] | None,
kwargs.get("provider_specific_header", None),
)
provider_specific_headers: Final = ProviderSpecificHeaderUtils.get_provider_specific_headers(

View file

@ -5091,14 +5091,16 @@ def completion(
model_info: Final = kwargs.get("model_info", None)
proxy_server_request: Final = kwargs.get("proxy_server_request", None)
fallbacks = kwargs.get("fallbacks", None)
provider_specific_header: Final = cast(ProviderSpecificHeader | None, kwargs.get("provider_specific_header", None))
provider_specific_header: Final = cast(
ProviderSpecificHeader | Sequence[ProviderSpecificHeader] | None,
kwargs.get("provider_specific_header", None),
)
headers = kwargs.get("headers", None) or extra_headers
ensure_alternating_roles: Final[bool | None] = kwargs.get("ensure_alternating_roles", None)
user_continue_message: Final[ChatCompletionUserMessage | None] = kwargs.get("user_continue_message", None)
assistant_continue_message: ChatCompletionAssistantMessage | None = kwargs.get("assistant_continue_message", None)
if headers is None:
headers = {}
headers = {} if headers is None else dict(headers)
if extra_headers is not None:
headers.update(extra_headers)
# Inject proxy auth headers if configured

View file

@ -3044,36 +3044,36 @@ async def add_guardrails_from_policy_engine(
)
_ANTHROPIC_API_HEADER_PROVIDERS: Final = ",".join(
(LlmProviders.ANTHROPIC.value, LlmProviders.BEDROCK.value, LlmProviders.VERTEX_AI.value)
)
_ANTHROPIC_OAUTH_CREDENTIAL_PROVIDERS: Final = LlmProviders.ANTHROPIC.value
def add_provider_specific_headers_to_request(
data: dict,
headers: dict,
):
from litellm.llms.anthropic.common_utils import is_anthropic_oauth_key
anthropic_headers: Final = {}
# boolean to indicate if a header was added
added_header = False
for header in ANTHROPIC_API_HEADERS:
if header in headers:
header_value = headers[header]
anthropic_headers[header] = header_value
added_header = True
anthropic_api_headers: Final = {header: headers[header] for header in ANTHROPIC_API_HEADERS if header in headers}
anthropic_oauth_credential_headers: Final = {
header: value
for header, value in headers.items()
if header.lower() == "authorization" and is_anthropic_oauth_key(value)
}
# Check for Authorization header with Anthropic OAuth token (sk-ant-oat*)
# This needs to be handled via provider-specific headers to ensure it only
# goes to Anthropic-compatible providers, not all providers in the router
for header, value in headers.items():
if header.lower() == "authorization" and is_anthropic_oauth_key(value):
anthropic_headers[header] = value
added_header = True
break
if added_header is True:
# Anthropic headers work across multiple providers
# Store as comma-separated list so retrieval can match any of them
data["provider_specific_header"] = ProviderSpecificHeader(
custom_llm_provider=f"{LlmProviders.ANTHROPIC.value},{LlmProviders.BEDROCK.value},{LlmProviders.VERTEX_AI.value}",
extra_headers=anthropic_headers,
scoped_headers: Final = [
ProviderSpecificHeader(custom_llm_provider=providers, extra_headers=extra_headers)
for providers, extra_headers in (
(_ANTHROPIC_API_HEADER_PROVIDERS, anthropic_api_headers),
(_ANTHROPIC_OAUTH_CREDENTIAL_PROVIDERS, anthropic_oauth_credential_headers),
)
if extra_headers
]
if scoped_headers:
data["provider_specific_header"] = scoped_headers[0] if len(scoped_headers) == 1 else scoped_headers
def _add_otel_traceparent_to_data(data: dict, request: Request):

View file

@ -67,8 +67,8 @@ proxy = [
"azure-identity>=1.25.2,<2.0",
"azure-storage-blob>=12.28.0,<13.0",
"mcp>=1.28.1,<2.0",
"litellm-proxy-extras==0.4.88",
"litellm-enterprise==0.1.58",
"litellm-proxy-extras==0.4.89",
"litellm-enterprise==0.1.59",
"RestrictedPython>=8.1,<9.0",
"rich>=13.9.4,<14.0",
"InquirerPy>=0.3.4,<1.0",

View file

@ -36,6 +36,10 @@
# `re.search`, so a `.` copied out of an error message is a wildcard and the block
# accepts messages the author never meant to accept. Mark a real regex raw, wrap a
# literal message in `re.escape`, and the pattern says which one it is
# F823 a module-level name read inside a function that also binds it lower down. The
# later binding makes the name local for the whole body, so the read raises
# UnboundLocalError, and in an autouse fixture that takes every test in the
# directory down with it
#
# No target-version here on purpose: it resolves from requires-python (>=3.10), so
# 3.11-only builtins like BaseExceptionGroup are correctly flagged in a tree that
@ -58,4 +62,5 @@ lint.select = [
"PLR0133",
"PLW0127",
"RUF043",
"F823",
]

View file

@ -6,13 +6,13 @@
"limit": 742
},
"TQ003": {
"limit": 1068
"limit": 62
},
"TQ004": {
"limit": 469
},
"TQ005": {
"limit": 2436
"limit": 2405
},
"TQ006": {
"limit": 34

View file

@ -6,8 +6,6 @@ Run with:
"""
import asyncio
import os
import sys
import json
from typing import Optional
from uuid import uuid4
@ -18,9 +16,6 @@ import litellm
from litellm.integrations.custom_logger import CustomLogger
from litellm.types.utils import StandardLoggingPayload
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from a2a.types import MessageSendParams, SendMessageRequest

View file

@ -10,13 +10,10 @@ Prerequisites:
- LangGraph server running on localhost:2024
"""
import os
import sys
from uuid import uuid4
import pytest
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from a2a.types import MessageSendParams, SendMessageRequest, SendStreamingMessageRequest

View file

@ -1,9 +1,6 @@
import os
import sys
import pytest
sys.path.insert(0, os.path.abspath("../.."))
from tests._vcr_conftest_common import ( # noqa: E402,F401
VerboseReporterState,

View file

@ -4,7 +4,6 @@
import asyncio
import os
import random
import sys
import time
import traceback
from litellm._uuid import uuid
@ -13,9 +12,6 @@ from dotenv import load_dotenv
load_dotenv()
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from pathlib import Path
from unittest.mock import AsyncMock, MagicMock, patch

View file

@ -4,7 +4,6 @@
import asyncio
import logging
import os
import sys
import time
import traceback
from typing import Optional
@ -41,9 +40,6 @@ def _audio_file2():
load_dotenv()
sys.path.insert(
0, os.path.abspath("../")
) # Adds the parent directory to the system path
from litellm import Router

View file

@ -1,12 +1,7 @@
import asyncio
import os
import sys
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm # noqa: E402,F401
from tests._vcr_conftest_common import ( # noqa: E402,F401

View file

@ -5,14 +5,10 @@ Integration Tests for Batch Rate Limits
import asyncio
import json
import os
import sys
import pytest
from fastapi import HTTPException
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm import DualCache

View file

@ -1,15 +1,10 @@
import asyncio
import json
import os
import sys
import traceback
from unittest.mock import AsyncMock, MagicMock, patch
from dotenv import load_dotenv
load_dotenv()
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system-path
import logging
import time

View file

@ -3,15 +3,11 @@
import asyncio
import json as json_module
import os
import sys
import traceback
import tempfile
from dotenv import load_dotenv
load_dotenv()
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system-path
import pytest

View file

@ -1,12 +1,7 @@
import os
import sys
import traceback
import json
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from openai import APITimeoutError as Timeout
import litellm

View file

@ -3,14 +3,10 @@
import asyncio
import json
import os
import sys
import tempfile
from dotenv import load_dotenv
load_dotenv()
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system-path
import logging
import time
@ -103,6 +99,25 @@ def load_vertex_ai_credentials():
print("created gcs path service account=", os.environ["GCS_PATH_SERVICE_ACCOUNT"])
async def cancel_batch_unless_already_terminal(batch_id: str, provider: str) -> None:
try:
cancel_batch_response = await litellm.acancel_batch(batch_id=batch_id, custom_llm_provider=provider)
except openai.ConflictError as e:
if "Cannot cancel a batch with status 'completed'" in str(e):
print(f"Batch already completed, cannot cancel: {e}")
return
if "Cannot cancel a batch with status 'failed'" not in str(e):
raise
failed_batch = await litellm.aretrieve_batch(batch_id=batch_id, custom_llm_provider=provider)
print(f"Batch failed before cancel, errors={failed_batch.errors}")
failure_codes = {err.code for err in (failed_batch.errors.data if failed_batch.errors else None) or []}
assert failure_codes == {"token_limit_exceeded"}, (
f"batch failed for a reason other than the org's enqueued token limit: {failed_batch.errors}"
)
return
print("cancel_batch_response=", cancel_batch_response)
@pytest.mark.parametrize("provider", ["openai"]) # , "azure"
@pytest.mark.asyncio
@skip_if_no_openai_network
@ -176,24 +191,7 @@ async def test_create_batch(provider, tmp_path):
result_file_path = tmp_path / "batch_job_results_furniture.jsonl"
result_file_path.write_bytes(result)
# Cancel Batch - handle race condition where batch may already be completed
try:
cancel_batch_response = await litellm.acancel_batch(
batch_id=create_batch_response.id,
custom_llm_provider=provider,
)
print("cancel_batch_response=", cancel_batch_response)
except openai.ConflictError as e:
# Only allow to pass if it's specifically the "batch already completed" error
if "Cannot cancel a batch with status 'completed'" in str(e):
print(f"Batch already completed, cannot cancel: {e}")
else:
# Re-raise other ConflictError types
raise
except Exception as e:
# Re-raise any other unexpected errors
print(f"Unexpected error during batch cancellation: {e}")
raise
await cancel_batch_unless_already_terminal(batch_id=create_batch_response.id, provider=provider)
pass
@ -395,24 +393,7 @@ async def test_async_create_batch(provider, tmp_path):
result_file_path = tmp_path / "batch_job_results_furniture.jsonl"
result_file_path.write_bytes(file_content.content)
# Cancel Batch - handle race condition where batch may already be completed
try:
cancel_batch_response = await litellm.acancel_batch(
batch_id=create_batch_response.id,
custom_llm_provider=provider,
)
print("cancel_batch_response=", cancel_batch_response)
except openai.ConflictError as e:
# Only allow to pass if it's specifically the "batch already completed" error
if "Cannot cancel a batch with status 'completed'" in str(e):
print(f"Batch already completed, cannot cancel: {e}")
else:
# Re-raise other ConflictError types
raise
except Exception as e:
# Re-raise any other unexpected errors
print(f"Unexpected error during batch cancellation: {e}")
raise
await cancel_batch_unless_already_terminal(batch_id=create_batch_response.id, provider=provider)
mock_file_response = {

View file

@ -1,7 +1,5 @@
import os
import sys
sys.path.insert(0, os.path.abspath("../.."))
import litellm
import requests
from bs4 import BeautifulSoup

View file

@ -27,10 +27,8 @@ import ast
import os
import re
from typing import List, Tuple
import sys
# Add parent directory to path so we can import litellm
sys.path.insert(0, os.path.abspath("../.."))
import litellm

View file

@ -1,8 +1,6 @@
import ast
import os
import sys
sys.path.insert(0, os.path.abspath("../.."))
import litellm

View file

@ -4,14 +4,9 @@ Test that all cache calls in async functions in router_strategy/ are async
"""
import os
import sys
from typing import Dict, List, Tuple
import ast
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import os
class AsyncCacheCallVisitor(ast.NodeVisitor):

View file

@ -4,11 +4,7 @@ import os
from dataclasses import dataclass
import argparse
import re
import sys
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm

View file

@ -11,9 +11,6 @@ import re
# Backup the original sys.path
original_sys_path = sys.path.copy()
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
public_exceptions = litellm.LITELLM_EXCEPTION_TYPES

View file

@ -2,11 +2,7 @@ import os
import re
import inspect
from typing import Type
import sys
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm

View file

@ -1,12 +1,7 @@
import os
import re
import sys
from typing import get_type_hints
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from litellm.types.utils import StandardLoggingPayload

View file

@ -3,13 +3,9 @@
import asyncio
import importlib
import os
import sys
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
@ -31,9 +27,6 @@ def setup_and_teardown():
This fixture reloads litellm before every function. To speed up testing by removing callbacks being chained.
"""
curr_dir = os.getcwd() # Get the current working directory
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the project directory to the system path
from litellm import Router
@ -41,8 +34,6 @@ def setup_and_teardown():
try:
if hasattr(litellm, "proxy") and hasattr(litellm.proxy, "proxy_server"):
import litellm.proxy.proxy_server
importlib.reload(litellm.proxy.proxy_server)
except Exception as e:
print(f"Error reloading litellm.proxy.proxy_server: {e}")

View file

@ -1,7 +1,4 @@
import os
import sys
sys.path.insert(0, os.path.abspath("../.."))
import asyncio
import logging

View file

@ -1,9 +1,4 @@
import os
import sys
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system-path
from litellm.integrations.custom_guardrail import CustomGuardrail
from litellm.types.guardrails import GuardrailEventHooks, Mode

View file

@ -3,15 +3,10 @@ Mock prometheus unit tests, these don't rely on LLM API calls
"""
import json
import os
import sys
import pytest
from fastapi.testclient import TestClient
sys.path.insert(
0, os.path.abspath("../../..")
) # Adds the parent directory to the system path
from unittest.mock import patch

View file

@ -9,16 +9,12 @@ except Exception:
PrometheusLogger = None
import asyncio
import sys
from dotenv import load_dotenv
load_dotenv()
import os
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system-path
from unittest.mock import MagicMock
import pytest

View file

@ -1,10 +1,6 @@
import os
import sys
from unittest.mock import MagicMock, patch
sys.path.insert(
0, os.path.abspath("../../../..")
) # Adds the parent directory to the system path
import pytest
from fastapi import HTTPException

View file

@ -2,13 +2,10 @@
Test the /guardrails/apply_guardrail endpoint
"""
import os
import sys
from unittest.mock import AsyncMock, Mock, patch
import pytest
sys.path.insert(0, os.path.abspath("../../../../.."))
from fastapi import HTTPException

View file

@ -2,13 +2,10 @@
Test the Bedrock guardrail apply_guardrail functionality
"""
import os
import sys
from unittest.mock import AsyncMock, Mock, patch
import pytest
sys.path.insert(0, os.path.abspath("../../../../.."))
from litellm.proxy._types import UserAPIKeyAuth

View file

@ -1,5 +1,4 @@
import os
import sys
import traceback
from litellm._uuid import uuid
from unittest import mock
@ -10,7 +9,6 @@ from fastapi import Request
load_dotenv()
import time
sys.path.insert(0, os.path.abspath("../.."))
import logging
import pytest

View file

@ -7,13 +7,9 @@
import importlib
import os
import sys
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from tests._vcr_conftest_common import ( # noqa: E402,F401
@ -122,7 +118,6 @@ def setup_and_teardown():
Module-scoped setup. Reloads litellm only in single-process mode
(skipped under xdist to avoid cross-worker interference).
"""
sys.path.insert(0, os.path.abspath("../.."))
import litellm

View file

@ -1,9 +1,6 @@
import sys
import os
import io, asyncio
import pytest
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.proxy.guardrails.guardrail_hooks.bedrock_guardrails import (
BedrockGuardrail,

View file

@ -3,11 +3,8 @@ Test custom guardrail + unit tests for guardrails
"""
import io
import os
import sys
sys.path.insert(0, os.path.abspath("../.."))
import asyncio
import gzip

View file

@ -1,5 +1,4 @@
import os
import sys
from unittest.mock import patch, AsyncMock
from httpx import Response, Request
@ -13,9 +12,6 @@ from litellm.proxy.guardrails.guardrail_hooks.deepkeep.deepkeep import (
)
from litellm.exceptions import GuardrailRaisedException
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm.proxy.guardrails.init_guardrails import init_guardrails_v2

View file

@ -2,11 +2,8 @@
Test DynamoAI Guardrails integration
"""
import sys
import os
import pytest
sys.path.insert(0, os.path.abspath("../.."))
from litellm.proxy.guardrails.guardrail_hooks.dynamoai import DynamoAIGuardrails
from litellm.proxy._types import UserAPIKeyAuth

View file

@ -8,11 +8,9 @@ Tests 40 different sentences to validate the conditional matching logic:
- identifier or block word alone should ALLOW
"""
import sys
import os
import pytest
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.content_filter import (
ContentFilterGuardrail,
@ -162,7 +160,6 @@ def content_filter_guardrail():
"""Initialize content filter guardrail with EU AI Act Article 5 template."""
# Get absolute path to the policy template
import os
content_filter_dir = os.path.join(
os.path.dirname(__file__),

View file

@ -7,11 +7,9 @@ Tests the exact 3 scenarios requested:
3. Request 3: Safe query in French that should pass (allowed)
"""
import sys
import os
import pytest
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.content_filter import (
ContentFilterGuardrail,

View file

@ -2,11 +2,8 @@
Test guardrail load balancing through the Router and ProxyLogging.
"""
import os
import sys
from unittest.mock import MagicMock, patch, AsyncMock
sys.path.insert(0, os.path.abspath("../.."))
import litellm
import pytest

View file

@ -2,8 +2,6 @@
## Unit Tests for guardrails config
import asyncio
import inspect
import os
import sys
import time
import traceback
from litellm._uuid import uuid
@ -15,7 +13,6 @@ from pydantic import BaseModel
import litellm.litellm_core_utils
import litellm.litellm_core_utils.litellm_logging
sys.path.insert(0, os.path.abspath("../.."))
from typing import Any, List, Literal, Optional, Tuple, Union
from unittest.mock import AsyncMock, MagicMock, patch

View file

@ -1,10 +1,7 @@
import sys
import os
import pytest
from unittest.mock import AsyncMock, patch
from fastapi import HTTPException
sys.path.insert(0, os.path.abspath("../.."))
from litellm.proxy.guardrails.guardrail_hooks.javelin import JavelinGuardrail
import litellm
from litellm.proxy._types import UserAPIKeyAuth

View file

@ -1,12 +1,9 @@
import sys
import os
import io, asyncio
import pytest
import time
from litellm import mock_completion
from unittest.mock import MagicMock, AsyncMock, patch
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.proxy.guardrails.guardrail_hooks.lakera_ai_v2 import LakeraAIGuardrail
from litellm.types.guardrails import PiiEntityType, PiiAction

View file

@ -1,5 +1,4 @@
import os
import sys
from fastapi.exceptions import HTTPException
from unittest.mock import patch
from httpx import Response, Request
@ -14,9 +13,6 @@ from litellm.proxy.guardrails.guardrail_hooks.lasso.lasso import (
LassoGuardrailAPIError,
)
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm.proxy.guardrails.init_guardrails import init_guardrails_v2

View file

@ -1,10 +1,8 @@
import sys
import os
import pytest
from litellm import mock_completion
from unittest.mock import patch
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.proxy.guardrails.guardrail_hooks.presidio import (
_OPTIONAL_PresidioPIIMasking,

View file

@ -3,9 +3,7 @@ Tests for the Semantic Guard guardrail — embedding-based prompt injection dete
"""
import os
import sys
sys.path.insert(0, os.path.abspath("../.."))
from unittest.mock import MagicMock

View file

@ -10,11 +10,9 @@ for Singapore financial institutions:
5. sg_mas_model_security Adversarial attacks on financial AI
"""
import sys
import os
import pytest
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.content_filter import (
ContentFilterGuardrail,

View file

@ -15,11 +15,9 @@ Each sub-guardrail validates:
- identifier or block word alone ALLOW (no match)
"""
import sys
import os
import pytest
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.proxy.guardrails.guardrail_hooks.litellm_content_filter.content_filter import (
ContentFilterGuardrail,

View file

@ -1,4 +1,3 @@
import sys
import os
import io, asyncio
import json
@ -7,7 +6,6 @@ import time
from litellm import mock_completion
from unittest.mock import MagicMock, AsyncMock, patch
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.proxy.guardrails.guardrail_hooks.presidio import (
_OPTIONAL_PresidioPIIMasking,

View file

@ -2,14 +2,9 @@ import asyncio
import httpx
import json
import pytest
import sys
from typing import Any, Dict, List, Optional
from unittest.mock import MagicMock, Mock, patch
import os
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm.exceptions import BadRequestError
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler

View file

@ -1,12 +1,7 @@
import asyncio
import os
import sys
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm # noqa: E402,F401
from tests._vcr_conftest_common import ( # noqa: E402,F401

View file

@ -1,14 +1,9 @@
import logging
import os
import sys
import traceback
from dotenv import load_dotenv
from openai.types.image import Image
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from litellm.llms.bedrock.image_generation.amazon_nova_canvas_transformation import (
AmazonNovaCanvasConfig,
@ -18,13 +13,9 @@ logging.basicConfig(level=logging.DEBUG)
load_dotenv()
import asyncio
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import pytest
from litellm.llms.bedrock.image_generation.cost_calculator import cost_calculator
from litellm.types.utils import ImageResponse, ImageObject
import os
import litellm
from litellm.llms.bedrock.image_generation.amazon_stability3_transformation import (

View file

@ -1,11 +1,8 @@
import asyncio
import os
import sys
from unittest.mock import MagicMock, patch
import pytest
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm import aimage_generation

View file

@ -1,6 +1,5 @@
import logging
import os
import sys
import traceback
import asyncio
from typing import Optional
@ -11,9 +10,6 @@ from unittest.mock import patch, AsyncMock
import json
from abc import ABC, abstractmethod
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm.utils import ImageResponse

View file

@ -3,14 +3,10 @@
import logging
import os
import sys
import traceback
from unittest.mock import AsyncMock, MagicMock, patch
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from dotenv import load_dotenv
from openai.types.image import Image
@ -19,7 +15,6 @@ from litellm.caching import InMemoryCache
logging.basicConfig(level=logging.DEBUG)
load_dotenv()
import asyncio
import os
import pytest
import litellm

View file

@ -2,14 +2,9 @@
## This tests the litellm support for the openai /generations endpoint
import logging
import os
import sys
import traceback
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from dotenv import load_dotenv
from openai.types.image import Image
@ -18,7 +13,6 @@ from litellm.caching import InMemoryCache
logging.basicConfig(level=logging.DEBUG)
load_dotenv()
import asyncio
import os
import pytest
import litellm

View file

@ -1,14 +1,9 @@
import logging
import os
import sys
import traceback
import pytest
import json
from unittest.mock import Mock, patch, AsyncMock
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm.types.utils import ImageObject

View file

@ -20,12 +20,10 @@ Run only these tests:
import math
import os
import sys
from typing import NamedTuple, Optional
import pytest
sys.path.insert(0, os.path.abspath("../.."))
# ---------------------------------------------------------------------------
# Fixtures / helpers

View file

@ -10,16 +10,11 @@ Usage:
the abstract methods to provide provider-specific configuration.
"""
import os
import sys
from abc import ABC, abstractmethod
from typing import Any, Dict, List, Optional
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from litellm.llms.base_llm.base_utils import BaseTokenCounter
from litellm.types.utils import TokenCountResponse

View file

@ -2,14 +2,9 @@
import asyncio
import importlib
import os
import sys
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm # noqa: E402,F401
from tests._vcr_conftest_common import ( # noqa: E402,F401
@ -38,9 +33,6 @@ def setup_and_teardown():
"""
This fixture reloads litellm before every function. To speed up testing by removing callbacks being chained.
"""
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the project directory to the system path
importlib.reload(litellm)

View file

@ -1,6 +1,5 @@
import asyncio
import copy
import sys
import time
from datetime import datetime
from unittest import mock
@ -10,11 +9,7 @@ from dotenv import load_dotenv
from litellm.types.utils import StandardCallbackDynamicParams
load_dotenv()
import os
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system-path
import pytest
import litellm

View file

@ -5,14 +5,10 @@ Tests for the Anthropic token counter implementation using the base test suite.
"""
import os
import sys
from typing import Any, Dict, List
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from litellm.llms.anthropic.count_tokens import AnthropicTokenCounter
from litellm.llms.base_llm.base_utils import BaseTokenCounter

View file

@ -5,14 +5,10 @@ Tests for the Azure AI Anthropic token counter implementation using the base tes
"""
import os
import sys
from typing import Any, Dict, List
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from litellm.llms.azure_ai.anthropic.count_tokens import AzureAIAnthropicTokenCounter
from litellm.llms.base_llm.base_utils import BaseTokenCounter

View file

@ -9,15 +9,11 @@ counting, the test will be skipped.
"""
import os
import sys
from typing import Any, Dict, List
from unittest.mock import patch
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from litellm.llms.base_llm.base_utils import BaseTokenCounter
from litellm.llms.bedrock.count_tokens.bedrock_token_counter import BedrockTokenCounter

View file

@ -3,14 +3,12 @@ Integration test for CyberArk Conjur Secret Manager.
"""
import os
import sys
import pytest
import yaml
from dotenv import load_dotenv
load_dotenv()
sys.path.insert(0, os.path.abspath("../.."))
from unittest.mock import AsyncMock, MagicMock, patch
from litellm._uuid import uuid

View file

@ -1,12 +1,7 @@
import json
import os
import sys
from datetime import datetime
from unittest.mock import AsyncMock, Mock, patch
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import pytest
import litellm

View file

@ -1,14 +1,10 @@
import os
import sys
import pytest
from dotenv import load_dotenv
load_dotenv()
import httpx
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from unittest.mock import patch, MagicMock
import logging
from litellm._logging import verbose_logger

View file

@ -2,14 +2,10 @@
# This tests if ahealth_check() actually works
import os
import sys
import pytest
from unittest.mock import AsyncMock, patch
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import asyncio
import litellm

View file

@ -1,14 +1,10 @@
import json
import os
import sys
import time
from datetime import datetime
from unittest.mock import AsyncMock, patch, MagicMock
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm.integrations.custom_logger import CustomLogger
from litellm.litellm_core_utils.logging_callback_manager import LoggingCallbackManager

View file

@ -1,6 +1,4 @@
import asyncio
import os
import sys
from datetime import datetime, timedelta, timezone
from unittest.mock import AsyncMock, MagicMock, patch
@ -11,9 +9,6 @@ load_dotenv()
from litellm.proxy._types import LiteLLM_BudgetTableFull
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from litellm.proxy.common_utils.reset_budget_job import ResetBudgetJob

View file

@ -1,6 +1,5 @@
import base64
import os
import sys
import time
import traceback
from litellm._uuid import uuid
@ -12,9 +11,6 @@ load_dotenv()
import tempfile
from uuid import uuid4
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import pytest
import litellm
from litellm.llms.azure.azure import get_azure_ad_token_from_oidc

View file

@ -1,6 +1,5 @@
import copy
import logging
import sys
import time
from datetime import datetime
from unittest import mock
@ -12,9 +11,6 @@ from litellm.types.utils import StandardCallbackDynamicParams
load_dotenv()
import os
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system-path
import pytest
import litellm

View file

@ -1,8 +1,5 @@
import pytest
import sys
import os
sys.path.insert(0, os.path.abspath("../.."))
from litellm.utils import validate_chat_completion_tool_choice

View file

@ -1,17 +1,12 @@
import httpx
import json
import pytest
import sys
from typing import Any, Dict, List, Optional
from unittest.mock import MagicMock, Mock, patch
import os
from litellm._uuid import uuid
import time
import base64
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from abc import ABC, abstractmethod

View file

@ -2,14 +2,9 @@
import asyncio
import importlib
import os
import sys
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm # noqa: E402
@ -77,17 +72,12 @@ def setup_and_teardown():
"""
This fixture reloads litellm before every function. To speed up testing by removing callbacks being chained.
"""
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the project directory to the system path
importlib.reload(litellm)
try:
if hasattr(litellm, "proxy") and hasattr(litellm.proxy, "proxy_server"):
import litellm.proxy.proxy_server
importlib.reload(litellm.proxy.proxy_server)
except Exception as e:
print(f"Error reloading litellm.proxy.proxy_server: {e}")

View file

@ -1,5 +1,3 @@
import os
import sys
import pytest
import asyncio
from typing import Optional
@ -13,7 +11,6 @@ from litellm.responses.litellm_completion_transformation.transformation import (
from litellm.types.utils import ModelResponse
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.integrations.custom_logger import CustomLogger
import json

View file

@ -11,12 +11,9 @@ The issue occurs when:
3. The message is sent to Anthropic without a corresponding tool_use block
"""
import os
import sys
import pytest
from unittest.mock import patch, MagicMock
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.responses.litellm_completion_transformation.transformation import (
LiteLLMCompletionResponsesConfig,

View file

@ -5,13 +5,10 @@ This test verifies that when using previous_response_id with tool_result,
the fix ensures tool_calls are added to the previous assistant message.
"""
import os
import sys
import pytest
import json
from unittest.mock import patch, AsyncMock
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.responses.litellm_completion_transformation.transformation import (
LiteLLMCompletionResponsesConfig,

View file

@ -1,10 +1,8 @@
import os
import sys
import pytest
import asyncio
from unittest.mock import patch, AsyncMock
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.integrations.custom_logger import CustomLogger
import json

View file

@ -13,15 +13,12 @@ response tracking and logging.
"""
import json
import os
import sys
from datetime import datetime
from typing import Any, Dict, Optional
from unittest.mock import Mock, patch
import pytest
sys.path.insert(0, os.path.abspath("../.."))
from litellm.constants import STREAM_SSE_DONE_STRING
from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLoggingObj

View file

@ -1,9 +1,7 @@
import os
import sys
import pytest
from unittest.mock import patch, AsyncMock
sys.path.insert(0, os.path.abspath("../.."))
import litellm
import json
from base_responses_api import BaseResponsesAPITest

View file

@ -1,5 +1,4 @@
import os
import sys
import pytest
import asyncio
from typing import Optional, cast
@ -10,7 +9,6 @@ from litellm.litellm_core_utils.litellm_logging import Logging as LiteLLMLogging
import time
import json
sys.path.insert(0, os.path.abspath("../.."))
import litellm
from litellm.integrations.custom_logger import CustomLogger
from litellm.types.utils import StandardLoggingPayload

View file

@ -1,15 +1,11 @@
import httpx
import json
import pytest
import sys
from typing import Any, Dict, List
from unittest.mock import MagicMock, Mock, patch
import os
from litellm._uuid import uuid
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm import transcription
from litellm.litellm_core_utils.get_supported_openai_params import (

View file

@ -2,14 +2,10 @@ import asyncio
import httpx
import json
import pytest
import sys
from typing import Any, Dict, List
from unittest.mock import MagicMock, Mock, patch
import os
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm import embedding
from litellm.exceptions import BadRequestError

View file

@ -10,9 +10,6 @@ import time
import base64
import inspect
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm.exceptions import BadRequestError
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler

View file

@ -2,14 +2,10 @@ import asyncio
import httpx
import json
import pytest
import sys
from typing import Any, Dict, List
from unittest.mock import MagicMock, Mock, patch
import os
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm.exceptions import BadRequestError
from litellm.llms.custom_httpx.http_handler import AsyncHTTPHandler, HTTPHandler

View file

@ -7,14 +7,9 @@
import asyncio
import importlib
import os
import sys
import pytest
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm # noqa: E402
@ -123,7 +118,6 @@ def event_loop():
@pytest.fixture(scope="function", autouse=True)
def setup_and_teardown(event_loop): # Add event_loop as a dependency
sys.path.insert(0, os.path.abspath("../.."))
import litellm

View file

@ -8,14 +8,12 @@ across different providers (OpenAI, xAI, etc.)
import asyncio
import json
import os
import sys
from abc import ABC, abstractmethod
from typing import Optional, Tuple, Union
import pytest
import websockets
sys.path.insert(0, os.path.abspath("../../.."))
import litellm

View file

@ -1,13 +1,9 @@
import os
import sys
from unittest.mock import AsyncMock, MagicMock
import pytest
from websockets.exceptions import ConnectionClosedError, ConnectionClosedOK
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import litellm
from litellm.types.realtime import RealtimeQueryParams

View file

@ -5,12 +5,9 @@ Tests OpenAI's Realtime API through LiteLLM's realtime interface.
Uses the base test class to ensure consistent behavior across providers.
"""
import os
import sys
import pytest
sys.path.insert(0, os.path.abspath("../../.."))
from tests.llm_translation.realtime.base_realtime_tests import BaseRealtimeTest

View file

@ -5,13 +5,10 @@ Tests xAI's Grok Voice Agent API through LiteLLM's realtime interface.
Uses the base test class to ensure consistent behavior across providers.
"""
import os
import sys
from typing import Tuple
import pytest
sys.path.insert(0, os.path.abspath("../../.."))
from tests.llm_translation.realtime.base_realtime_tests import BaseRealtimeTest

View file

@ -6,11 +6,9 @@ streaming and non-streaming requests.
"""
import os
import sys
import pytest
sys.path.insert(0, os.path.abspath("../.."))
import litellm

View file

@ -3,7 +3,6 @@
import asyncio
import os
import sys
import traceback
from dotenv import load_dotenv
@ -15,9 +14,6 @@ from litellm.llms.anthropic.chat import ModelResponseIterator
load_dotenv()
import io
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from typing import Optional
from unittest.mock import MagicMock, patch

View file

@ -25,9 +25,7 @@ See: https://learn.microsoft.com/en-us/azure/ai-foundry/agents/quickstart
import json
import os
import sys
sys.path.insert(0, os.path.abspath("../.."))
import pytest
from unittest.mock import MagicMock

View file

@ -3,7 +3,6 @@
import asyncio
import os
import sys
import traceback
from dotenv import load_dotenv
@ -20,9 +19,6 @@ from litellm.llms.custom_httpx.http_handler import HTTPHandler
load_dotenv()
import io
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
from typing import Optional
from unittest.mock import MagicMock, patch

Some files were not shown because too many files have changed in this diff Show more