Skip to content

Commit 455f8fd

Browse files
committed
bug(llmo): run formatter
1 parent 8617292 commit 455f8fd

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

posthog/ai/utils.py

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,12 @@ def format_response(response, provider: str):
118118
def format_response_anthropic(response):
119119
output = []
120120
for choice in response.content:
121-
if hasattr(choice, "type") and choice.type == "text" and hasattr(choice, "text") and choice.text:
121+
if (
122+
hasattr(choice, "type")
123+
and choice.type == "text"
124+
and hasattr(choice, "text")
125+
and choice.text
126+
):
122127
output.append(
123128
{
124129
"role": "assistant",
@@ -230,8 +235,14 @@ def format_tool_calls(response, provider: str):
230235

231236
for content_item in response.content:
232237
if hasattr(content_item, "type") and content_item.type == "tool_use":
233-
tool_call_dict = vars(content_item)
234-
tool_calls.append(tool_call_dict)
238+
tool_calls.append(
239+
{
240+
"type": content_item.type,
241+
"id": content_item.id,
242+
"name": content_item.name,
243+
"input": content_item.input,
244+
}
245+
)
235246

236247
return tool_calls if tool_calls else None
237248
elif provider == "openai":

posthog/test/ai/anthropic/test_anthropic.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,12 @@ def mock_anthropic_response_with_tool_use():
9696
role="assistant",
9797
content=[
9898
{"type": "text", "text": "I'll help you with that."},
99-
{"type": "tool_use", "id": "tool_1", "name": "get_weather", "input": {"location": "New York"}}
99+
{
100+
"type": "tool_use",
101+
"id": "tool_1",
102+
"name": "get_weather",
103+
"input": {"location": "New York"},
104+
},
100105
],
101106
model="claude-3-opus-20240229",
102107
usage=Usage(
@@ -479,7 +484,9 @@ def test_tool_use_response(mock_client, mock_anthropic_response_with_tool_use):
479484
assert call_args["event"] == "$ai_generation"
480485
assert props["$ai_provider"] == "anthropic"
481486
assert props["$ai_model"] == "claude-3-opus-20240229"
482-
assert props["$ai_input"] == [{"role": "user", "content": "What's the weather like?"}]
487+
assert props["$ai_input"] == [
488+
{"role": "user", "content": "What's the weather like?"}
489+
]
483490
# Should only include text content, not tool_use content
484491
assert props["$ai_output_choices"] == [
485492
{"role": "assistant", "content": "I'll help you with that."}
@@ -490,4 +497,11 @@ def test_tool_use_response(mock_client, mock_anthropic_response_with_tool_use):
490497
assert props["foo"] == "bar"
491498
assert isinstance(props["$ai_latency"], float)
492499
# Verify that tools are captured separately
493-
assert props["$ai_tools"] == [{"type": "tool_use", "id": "tool_1", "name": "get_weather", "input": {"location": "New York"}}]
500+
assert props["$ai_tools"] == [
501+
{
502+
"type": "tool_use",
503+
"id": "tool_1",
504+
"name": "get_weather",
505+
"input": {"location": "New York"},
506+
}
507+
]

0 commit comments

Comments
 (0)