Spaces:
Build error
Build error
File size: 2,149 Bytes
9c7d451 e4a41fa 9c7d451 e4a41fa 9c7d451 e4a41fa 9c7d451 e4a41fa 9c7d451 e4a41fa 9c7d451 e4a41fa 9c7d451 e4a41fa 9c7d451 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | """Tests for Anthropic provider."""
import pytest
class TestAnthropicTokenCounting:
@pytest.fixture
def anthropic_provider(self):
from headroom.providers.anthropic import AnthropicProvider
return AnthropicProvider()
def test_count_text_fallback(self, anthropic_provider):
# Without API client, should use tiktoken fallback
counter = anthropic_provider.get_token_counter("claude-3-5-sonnet-20241022")
count = counter.count_text("Hello world")
assert count > 0
def test_count_messages_basic(self, anthropic_provider):
counter = anthropic_provider.get_token_counter("claude-3-5-sonnet-20241022")
messages = [{"role": "user", "content": "Hello"}]
count = counter.count_messages(messages)
assert count > 0
class TestAnthropicModelLimits:
@pytest.fixture
def anthropic_provider(self):
from headroom.providers.anthropic import AnthropicProvider
return AnthropicProvider()
def test_get_context_limit_claude_sonnet(self, anthropic_provider):
limit = anthropic_provider.get_context_limit("claude-3-5-sonnet-20241022")
assert limit == 200000
def test_get_context_limit_claude_opus(self, anthropic_provider):
limit = anthropic_provider.get_context_limit("claude-3-opus-20240229")
assert limit == 200000
def test_supports_model_known(self, anthropic_provider):
assert anthropic_provider.supports_model("claude-3-5-sonnet-20241022")
def test_supports_model_prefix(self, anthropic_provider):
assert anthropic_provider.supports_model("claude-3-5-sonnet-latest")
class TestAnthropicCostEstimation:
@pytest.fixture
def anthropic_provider(self):
from headroom.providers.anthropic import AnthropicProvider
return AnthropicProvider()
def test_estimate_cost_basic(self, anthropic_provider):
cost = anthropic_provider.estimate_cost(
input_tokens=1000000,
output_tokens=0,
model="claude-3-5-sonnet-20241022",
)
# $3.00 per 1M input
assert cost == pytest.approx(3.00, rel=0.1)
|