Skip to content

Commit 216b8ee

Browse files
committed
chore(llmo): run formatter
1 parent 299bd9e commit 216b8ee

File tree

4 files changed

+52
-39
lines changed

4 files changed

+52
-39
lines changed

posthog/ai/utils.py

Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -159,27 +159,29 @@ def format_response_openai(response):
159159
if hasattr(response, "choices"):
160160
content = []
161161
role = "assistant"
162-
162+
163163
for choice in response.choices:
164164
# Handle Chat Completions response format
165165
if hasattr(choice, "message") and choice.message:
166166
if choice.message.role:
167167
role = choice.message.role
168-
168+
169169
if choice.message.content:
170170
content.append(choice.message.content)
171171

172172
if hasattr(choice.message, "tool_calls") and choice.message.tool_calls:
173173
for tool_call in choice.message.tool_calls:
174-
content.append({
175-
"type": "function",
176-
"id": tool_call.id,
177-
"function": {
178-
"name": tool_call.function.name,
179-
"arguments": tool_call.function.arguments,
180-
},
181-
})
182-
174+
content.append(
175+
{
176+
"type": "function",
177+
"id": tool_call.id,
178+
"function": {
179+
"name": tool_call.function.name,
180+
"arguments": tool_call.function.arguments,
181+
},
182+
}
183+
)
184+
183185
if content:
184186
message = {
185187
"role": role,
@@ -211,22 +213,26 @@ def format_response_openai(response):
211213
and content_item.type == "input_image"
212214
and hasattr(content_item, "image_url")
213215
):
214-
content.append({
215-
"type": "image",
216-
"image": content_item.image_url,
217-
})
216+
content.append(
217+
{
218+
"type": "image",
219+
"image": content_item.image_url,
220+
}
221+
)
218222
elif hasattr(item, "content"):
219223
content.append(str(item.content))
220224

221225
elif hasattr(item, "type") and item.type == "function_call":
222-
content.append({
223-
"type": "function",
224-
"id": getattr(item, "call_id", getattr(item, "id", "")),
225-
"function": {
226-
"name": item.name,
227-
"arguments": getattr(item, "arguments", {}),
228-
},
229-
})
226+
content.append(
227+
{
228+
"type": "function",
229+
"id": getattr(item, "call_id", getattr(item, "id", "")),
230+
"function": {
231+
"name": item.name,
232+
"arguments": getattr(item, "arguments", {}),
233+
},
234+
}
235+
)
230236

231237
if content:
232238
message = {
@@ -252,13 +258,15 @@ def format_response_gemini(response):
252258
content.append(part.text)
253259
elif hasattr(part, "function_call") and part.function_call:
254260
function_call = part.function_call
255-
content.append({
256-
"type": "function",
257-
"function": {
258-
"name": function_call.name,
259-
"arguments": function_call.args,
260-
},
261-
})
261+
content.append(
262+
{
263+
"type": "function",
264+
"function": {
265+
"name": function_call.name,
266+
"arguments": function_call.args,
267+
},
268+
}
269+
)
262270

263271
if content:
264272
message = {

posthog/test/ai/anthropic/test_anthropic.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -594,7 +594,7 @@ def test_tool_calls_in_output_choices(
594594
"name": "get_weather",
595595
"arguments": {"location": "San Francisco"},
596596
},
597-
}
597+
},
598598
],
599599
}
600600
]
@@ -726,7 +726,7 @@ async def run_test():
726726
"name": "get_weather",
727727
"arguments": {"location": "San Francisco"},
728728
},
729-
}
729+
},
730730
],
731731
}
732732
]

posthog/test/ai/gemini/test_gemini.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ def test_function_calls_in_output_choices(
498498
"name": "get_current_weather",
499499
"arguments": {"location": "San Francisco"},
500500
},
501-
}
501+
},
502502
],
503503
}
504504
]

posthog/test/ai/openai/test_openai.py

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ def mock_openai_response_with_tool_calls():
259259
)
260260
],
261261
),
262-
)
262+
),
263263
],
264264
usage=CompletionUsage(
265265
completion_tokens=15,
@@ -335,7 +335,7 @@ def mock_responses_api_with_tool_calls():
335335
type="output_text",
336336
text=" Let me check that for you.",
337337
annotations=[],
338-
)
338+
),
339339
],
340340
),
341341
ResponseFunctionToolCall(
@@ -594,7 +594,7 @@ def test_tool_calls(mock_client, mock_openai_response_with_tool_calls):
594594
"name": "get_weather",
595595
"arguments": '{"location": "San Francisco", "unit": "celsius"}',
596596
},
597-
}
597+
},
598598
],
599599
}
600600
]
@@ -717,7 +717,7 @@ def test_responses_api_tool_calls(mock_client, mock_responses_api_with_tool_call
717717
"name": "get_weather",
718718
"arguments": '{"location": "Chicago"}',
719719
},
720-
}
720+
},
721721
],
722722
}
723723
]
@@ -885,7 +885,10 @@ def test_streaming_with_tool_calls(mock_client):
885885
assert defined_tool["function"]["parameters"] == {}
886886

887887
# Check that the content was also accumulated
888-
assert props["$ai_output_choices"][0]["content"] == "The weather in San Francisco is 15°C."
888+
assert (
889+
props["$ai_output_choices"][0]["content"]
890+
== "The weather in San Francisco is 15°C."
891+
)
889892

890893
# Check token usage
891894
assert props["$ai_input_tokens"] == 20
@@ -986,7 +989,9 @@ def test_responses_parse(mock_client, mock_parsed_response):
986989
assert props["$ai_output_choices"] == [
987990
{
988991
"role": "assistant",
989-
"content": ['{"name": "Science Fair", "date": "Friday", "participants": ["Alice", "Bob"]}'],
992+
"content": [
993+
'{"name": "Science Fair", "date": "Friday", "participants": ["Alice", "Bob"]}'
994+
],
990995
}
991996
]
992997
assert props["$ai_input_tokens"] == 15

0 commit comments

Comments
 (0)