LiteLLM Minor Fixes & Improvements (10/05/2024) (#6083)

* docs(prompt_caching.md): add prompt caching cost calc example to docs

* docs(prompt_caching.md): add proxy examples to docs

* feat(utils.py): expose new helper `supports_prompt_caching()` to check if a model supports prompt caching

* docs(prompt_caching.md): add docs on checking model support for prompt caching

* build: fix invalid json
This commit is contained in:
Krish Dholakia 2024-10-05 18:59:11 -04:00 committed by GitHub
parent fac3b2ee42
commit f2c0a31e3c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 459 additions and 59 deletions

View file

@ -1,4 +1,6 @@
import os, sys, traceback
import importlib.resources
import json
sys.path.insert(
0, os.path.abspath("../..")
@ -6,7 +8,18 @@ sys.path.insert(
import litellm
import pytest
try:
print(litellm.get_model_cost_map(url="fake-url"))
except Exception as e:
pytest.fail(f"An exception occurred: {e}")
def test_get_model_cost_map():
try:
print(litellm.get_model_cost_map(url="fake-url"))
except Exception as e:
pytest.fail(f"An exception occurred: {e}")
def test_get_backup_model_cost_map():
with importlib.resources.open_text(
"litellm", "model_prices_and_context_window_backup.json"
) as f:
print("inside backup")
content = json.load(f)
print("content", content)

View file

@ -111,3 +111,11 @@ def test_prompt_caching_model(model):
# assert (response.usage.cache_read_input_tokens > 0) or (
# response.usage.cache_creation_input_tokens > 0
# )
def test_supports_prompt_caching():
from litellm.utils import supports_prompt_caching
supports_pc = supports_prompt_caching(model="anthropic/claude-3-5-sonnet-20240620")
assert supports_pc