test_anthrophic.py 1.1 KB

123456789101112131415161718192021222324252627282930313233
  1. import os
  2. from unittest.mock import patch
  3. import pytest
  4. from langchain.schema import HumanMessage, SystemMessage
  5. from embedchain.config import BaseLlmConfig
  6. from embedchain.llm.anthropic import AnthropicLlm
  7. @pytest.fixture
  8. def anthropic_llm():
  9. os.environ["ANTHROPIC_API_KEY"] = "test_api_key"
  10. config = BaseLlmConfig(temperature=0.5, model="gpt2")
  11. return AnthropicLlm(config)
  12. def test_get_llm_model_answer(anthropic_llm):
  13. with patch.object(AnthropicLlm, "_get_answer", return_value="Test Response") as mock_method:
  14. prompt = "Test Prompt"
  15. response = anthropic_llm.get_llm_model_answer(prompt)
  16. assert response == "Test Response"
  17. mock_method.assert_called_once_with(prompt=prompt, config=anthropic_llm.config)
  18. def test_get_messages(anthropic_llm):
  19. prompt = "Test Prompt"
  20. system_prompt = "Test System Prompt"
  21. messages = anthropic_llm._get_messages(prompt, system_prompt)
  22. assert messages == [
  23. SystemMessage(content="Test System Prompt", additional_kwargs={}),
  24. HumanMessage(content="Test Prompt", additional_kwargs={}, example=False),
  25. ]