litellm-mirror/tests/llm_translation/test_prompt_caching.py
Ishaan Jaff 4e88fd65e1
(feat) openai prompt caching (non streaming) - add prompt_tokens_details in usage response (#6039)
* add prompt_tokens_details in usage response

* use _prompt_tokens_details as a param in Usage

* fix linting errors

* fix type error

* fix ci/cd deps

* bump deps for openai

* bump deps openai

* fix llm translation testing

* fix llm translation embedding
2024-10-03 23:31:10 +05:30

34 lines
937 B
Python

import json
import os
import sys
from datetime import datetime
from unittest.mock import AsyncMock
sys.path.insert(
0, os.path.abspath("../..")
) # Adds the parent directory to the system path
import httpx
import pytest
from respx import MockRouter
import litellm
from litellm import Choices, Message, ModelResponse
from litellm.types.utils import PromptTokensDetails
@pytest.mark.asyncio
async def test_prompt_caching():
"""
Tests that:
- prompt_tokens_details is correctly handled and returned as PromptTokensDetails type
"""
response1 = await litellm.acompletion(
model="gpt-4o-mini",
messages=[{"role": "user", "content": "hi"}],
)
print("response1", response1)
print("response1.usage", response1.usage)
print("type of prompt_tokens_details", type(response1.usage.prompt_tokens_details))
assert isinstance(response1.usage.prompt_tokens_details, PromptTokensDetails)