repositories
loading repo index
repositories
loading repo index
repository
loading code, commits, and activity
public Clawd ADK gateway launch mirror
stars
latest
clone command
git clone gitlawb://did:key:z6Mkq5mY...iFZ5/my-project-publ...git clone gitlawb://did:key:z6Mkq5mY.../my-project-publ...2fa351d6docs: add automaton and perps launch sources16d ago| #1 | import os |
| #2 | from unittest.mock import patch |
| #3 | |
| #4 | import pytest |
| #5 | from langchain.schema import HumanMessage, SystemMessage |
| #6 | |
| #7 | from embedchain.config import BaseLlmConfig |
| #8 | from embedchain.llm.anthropic import AnthropicLlm |
| #9 | |
| #10 | |
| #11 | @pytest.fixture |
| #12 | def anthropic_llm(): |
| #13 | os.environ["ANTHROPIC_API_KEY"] = "test_api_key" |
| #14 | config = BaseLlmConfig(temperature=0.5, model="claude-instant-1", token_usage=False) |
| #15 | return AnthropicLlm(config) |
| #16 | |
| #17 | |
| #18 | def test_get_llm_model_answer(anthropic_llm): |
| #19 | with patch.object(AnthropicLlm, "_get_answer", return_value="Test Response") as mock_method: |
| #20 | prompt = "Test Prompt" |
| #21 | response = anthropic_llm.get_llm_model_answer(prompt) |
| #22 | assert response == "Test Response" |
| #23 | mock_method.assert_called_once_with(prompt, anthropic_llm.config) |
| #24 | |
| #25 | |
| #26 | def test_get_messages(anthropic_llm): |
| #27 | prompt = "Test Prompt" |
| #28 | system_prompt = "Test System Prompt" |
| #29 | messages = anthropic_llm._get_messages(prompt, system_prompt) |
| #30 | assert messages == [ |
| #31 | SystemMessage(content="Test System Prompt", additional_kwargs={}), |
| #32 | HumanMessage(content="Test Prompt", additional_kwargs={}, example=False), |
| #33 | ] |
| #34 | |
| #35 | |
| #36 | def test_get_llm_model_answer_with_token_usage(anthropic_llm): |
| #37 | test_config = BaseLlmConfig( |
| #38 | temperature=anthropic_llm.config.temperature, model=anthropic_llm.config.model, token_usage=True |
| #39 | ) |
| #40 | anthropic_llm.config = test_config |
| #41 | with patch.object( |
| #42 | AnthropicLlm, "_get_answer", return_value=("Test Response", {"input_tokens": 1, "output_tokens": 2}) |
| #43 | ) as mock_method: |
| #44 | prompt = "Test Prompt" |
| #45 | response, token_info = anthropic_llm.get_llm_model_answer(prompt) |
| #46 | assert response == "Test Response" |
| #47 | assert token_info == { |
| #48 | "prompt_tokens": 1, |
| #49 | "completion_tokens": 2, |
| #50 | "total_tokens": 3, |
| #51 | "total_cost": 1.265e-05, |
| #52 | "cost_currency": "USD", |
| #53 | } |
| #54 | mock_method.assert_called_once_with(prompt, anthropic_llm.config) |
| #55 |