diff --git a/tests/llm_translation/test_deepseek_completion.py b/tests/llm_translation/test_deepseek_completion.py index b9d2eafb414..6c27ea59d4a 100644 --- a/tests/llm_translation/test_deepseek_completion.py +++ b/tests/llm_translation/test_deepseek_completion.py @@ -1,6 +1,6 @@ from base_llm_unit_tests import BaseLLMChatTest import pytest - +import litellm # Test implementations @pytest.mark.skip(reason="Deepseek API is hanging") @@ -103,3 +103,75 @@ async def test_deepseek_provider_async_completion(stream): ) # Model name should be stripped of provider prefix assert request_body["messages"] == messages assert request_body["stream"] == stream + + + +def test_completion_cost_deepseek(): + litellm.set_verbose = True + model_name = "deepseek/deepseek-chat" + messages_1 = [ + { + "role": "system", + "content": "You are a history expert. The user will provide a series of questions, and your answers should be concise and start with `Answer:`", + }, + { + "role": "user", + "content": "In what year did Qin Shi Huang unify the six states?", + }, + {"role": "assistant", "content": "Answer: 221 BC"}, + {"role": "user", "content": "Who was the founder of the Han Dynasty?"}, + {"role": "assistant", "content": "Answer: Liu Bang"}, + {"role": "user", "content": "Who was the last emperor of the Tang Dynasty?"}, + {"role": "assistant", "content": "Answer: Li Zhu"}, + { + "role": "user", + "content": "Who was the founding emperor of the Ming Dynasty?", + }, + {"role": "assistant", "content": "Answer: Zhu Yuanzhang"}, + { + "role": "user", + "content": "Who was the founding emperor of the Qing Dynasty?", + }, + ] + + message_2 = [ + { + "role": "system", + "content": "You are a history expert. The user will provide a series of questions, and your answers should be concise and start with `Answer:`", + }, + { + "role": "user", + "content": "In what year did Qin Shi Huang unify the six states?", + }, + {"role": "assistant", "content": "Answer: 221 BC"}, + {"role": "user", "content": "Who was the founder of the Han Dynasty?"}, + {"role": "assistant", "content": "Answer: Liu Bang"}, + {"role": "user", "content": "Who was the last emperor of the Tang Dynasty?"}, + {"role": "assistant", "content": "Answer: Li Zhu"}, + { + "role": "user", + "content": "Who was the founding emperor of the Ming Dynasty?", + }, + {"role": "assistant", "content": "Answer: Zhu Yuanzhang"}, + {"role": "user", "content": "When did the Shang Dynasty fall?"}, + ] + try: + response_1 = litellm.completion(model=model_name, messages=messages_1) + response_2 = litellm.completion(model=model_name, messages=message_2) + # Add any assertions here to check the response + print(response_2) + assert response_2.usage.prompt_cache_hit_tokens is not None + assert response_2.usage.prompt_cache_miss_tokens is not None + assert ( + response_2.usage.prompt_tokens + == response_2.usage.prompt_cache_miss_tokens + + response_2.usage.prompt_cache_hit_tokens + ) + assert ( + response_2.usage._cache_read_input_tokens + == response_2.usage.prompt_cache_hit_tokens + ) + except litellm.APIError as e: + pass + except Exception as e: + pytest.fail(f"Error occurred: {e}") diff --git a/tests/local_testing/test_completion_cost.py b/tests/local_testing/test_completion_cost.py index 28ce28097cb..a8c7bc6bbe5 100644 --- a/tests/local_testing/test_completion_cost.py +++ b/tests/local_testing/test_completion_cost.py @@ -1004,77 +1004,6 @@ def test_completion_cost_anthropic(): print(output_cost) -def test_completion_cost_deepseek(): - litellm.set_verbose = True - model_name = "deepseek/deepseek-chat" - messages_1 = [ - { - "role": "system", - "content": "You are a history expert. The user will provide a series of questions, and your answers should be concise and start with `Answer:`", - }, - { - "role": "user", - "content": "In what year did Qin Shi Huang unify the six states?", - }, - {"role": "assistant", "content": "Answer: 221 BC"}, - {"role": "user", "content": "Who was the founder of the Han Dynasty?"}, - {"role": "assistant", "content": "Answer: Liu Bang"}, - {"role": "user", "content": "Who was the last emperor of the Tang Dynasty?"}, - {"role": "assistant", "content": "Answer: Li Zhu"}, - { - "role": "user", - "content": "Who was the founding emperor of the Ming Dynasty?", - }, - {"role": "assistant", "content": "Answer: Zhu Yuanzhang"}, - { - "role": "user", - "content": "Who was the founding emperor of the Qing Dynasty?", - }, - ] - - message_2 = [ - { - "role": "system", - "content": "You are a history expert. The user will provide a series of questions, and your answers should be concise and start with `Answer:`", - }, - { - "role": "user", - "content": "In what year did Qin Shi Huang unify the six states?", - }, - {"role": "assistant", "content": "Answer: 221 BC"}, - {"role": "user", "content": "Who was the founder of the Han Dynasty?"}, - {"role": "assistant", "content": "Answer: Liu Bang"}, - {"role": "user", "content": "Who was the last emperor of the Tang Dynasty?"}, - {"role": "assistant", "content": "Answer: Li Zhu"}, - { - "role": "user", - "content": "Who was the founding emperor of the Ming Dynasty?", - }, - {"role": "assistant", "content": "Answer: Zhu Yuanzhang"}, - {"role": "user", "content": "When did the Shang Dynasty fall?"}, - ] - try: - response_1 = litellm.completion(model=model_name, messages=messages_1) - response_2 = litellm.completion(model=model_name, messages=message_2) - # Add any assertions here to check the response - print(response_2) - assert response_2.usage.prompt_cache_hit_tokens is not None - assert response_2.usage.prompt_cache_miss_tokens is not None - assert ( - response_2.usage.prompt_tokens - == response_2.usage.prompt_cache_miss_tokens - + response_2.usage.prompt_cache_hit_tokens - ) - assert ( - response_2.usage._cache_read_input_tokens - == response_2.usage.prompt_cache_hit_tokens - ) - except litellm.APIError as e: - pass - except Exception as e: - pytest.fail(f"Error occurred: {e}") - - def test_completion_cost_azure_common_deployment_name(): from litellm.utils import ( CallTypes,