Skip to content

Commit c8da916

Browse files
committed
Add test cases for anthropic
1 parent 7c9f0f2 commit c8da916

1 file changed

Lines changed: 46 additions & 0 deletions

File tree

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import os
2+
3+
import pytest
4+
import aikido_zen.sinks.anthropic
5+
import anthropic
6+
7+
from aikido_zen.thread.thread_cache import get_cache
8+
9+
skip_no_api_key = pytest.mark.skipif(
10+
"ANTHROPIC_API_KEY" not in os.environ,
11+
reason="ANTHROPIC_API_KEY environment variable not set",
12+
)
13+
14+
15+
@pytest.fixture(autouse=True)
16+
def setup():
17+
get_cache().reset()
18+
yield
19+
get_cache().reset()
20+
21+
22+
def get_ai_stats():
23+
return get_cache().ai_stats.get_stats()
24+
25+
26+
@skip_no_api_key
27+
def test_anthropic_messages_create():
28+
client = anthropic.Anthropic()
29+
response = client.messages.create(
30+
model="claude-3-opus-20240229",
31+
max_tokens=20,
32+
messages=[
33+
{
34+
"role": "user",
35+
"content": "Write the longest response possible, just as I am writing a long content",
36+
}
37+
],
38+
)
39+
print(response)
40+
41+
assert get_ai_stats()[0]["model"] == "claude-3-opus-20240229"
42+
assert get_ai_stats()[0]["calls"] == 1
43+
assert get_ai_stats()[0]["provider"] == "anthropic"
44+
assert get_ai_stats()[0]["tokens"]["input"] == 21
45+
assert get_ai_stats()[0]["tokens"]["output"] == 20
46+
assert get_ai_stats()[0]["tokens"]["total"] == 41

0 commit comments

Comments
 (0)