mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-28 01:32:17 +00:00
* test: move key-gated tests/test_litellm SDK tests into tests/llm_translation and drop empty folders * test: make token counter and health check unit tests run offline * ci: point unit shards, rust path filter, Makefile and docs at tests/unit * docs: fix stale test_litellm run paths in moved llm_translation tests * fix: correct databricks e2e sys.path depth and contributing example path --------- Co-authored-by: yuneng <yuneng@berri.ai> Co-authored-by: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
59 lines
1.8 KiB
Python
59 lines
1.8 KiB
Python
"""
|
|
Unit tests for litellm.compress().
|
|
"""
|
|
|
|
import os
|
|
|
|
import pytest
|
|
|
|
import litellm
|
|
from litellm.types.utils import CallTypes
|
|
|
|
CALL_TYPE = CallTypes.completion
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# BM25 scorer
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Content detection
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Message stubbing
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Retrieval tool
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# compress() — end-to-end
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
# ---------------------------------------------------------------------------
|
|
# Embedding scorer — integration test (skipped without API key)
|
|
# ---------------------------------------------------------------------------
|
|
|
|
|
|
@pytest.mark.skipif(not os.environ.get("OPENAI_API_KEY"), reason="Needs OPENAI_API_KEY")
|
|
def test_embedding_scorer():
|
|
result = litellm.compress(
|
|
messages=[
|
|
{"role": "user", "content": "Authentication code " * 2000},
|
|
{"role": "user", "content": "Unrelated cooking recipes " * 2000},
|
|
{"role": "user", "content": "Fix auth"},
|
|
],
|
|
model="gpt-4o",
|
|
call_type=CALL_TYPE,
|
|
compression_trigger=1000,
|
|
embedding_model="text-embedding-3-small",
|
|
)
|
|
assert result["compression_ratio"] > 0
|
|
assert len(result["cache"]) > 0
|