Skip to content

Commit f8af329

Browse files
feat: fix issues
1 parent bbc0eba commit f8af329

4 files changed

Lines changed: 37 additions & 23 deletions

File tree

edgee/__init__.py

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,7 @@ def tool_calls(self) -> list | None:
209209
@dataclass
210210
class StreamToolCallDelta:
211211
"""Partial tool call in a stream."""
212+
212213
index: int
213214
id: str | None = None
214215
type: str | None = None
@@ -266,20 +267,23 @@ def tool_call_deltas(self) -> list[dict] | None:
266267
@dataclass
267268
class ChunkEvent:
268269
"""A chunk of streamed content."""
270+
269271
type: str = "chunk"
270272
chunk: StreamChunk = None
271273

272274

273275
@dataclass
274276
class ToolStartEvent:
275277
"""Tool execution is starting."""
278+
276279
type: str = "tool_start"
277280
tool_call: dict = None
278281

279282

280283
@dataclass
281284
class ToolResultEvent:
282285
"""Tool execution completed."""
286+
283287
type: str = "tool_result"
284288
tool_call_id: str = None
285289
tool_name: str = None
@@ -289,6 +293,7 @@ class ToolResultEvent:
289293
@dataclass
290294
class IterationCompleteEvent:
291295
"""One iteration of the tool loop completed."""
296+
292297
type: str = "iteration_complete"
293298
iteration: int = 0
294299

@@ -424,8 +429,12 @@ def _send_simple(
424429
total_usage.prompt_tokens += response.usage.prompt_tokens
425430
total_usage.completion_tokens += response.usage.completion_tokens
426431
total_usage.total_tokens += response.usage.total_tokens
427-
total_usage.input_tokens_details.cached_tokens += response.usage.input_tokens_details.cached_tokens
428-
total_usage.output_tokens_details.reasoning_tokens += response.usage.output_tokens_details.reasoning_tokens
432+
total_usage.input_tokens_details.cached_tokens += (
433+
response.usage.input_tokens_details.cached_tokens
434+
)
435+
total_usage.output_tokens_details.reasoning_tokens += (
436+
response.usage.output_tokens_details.reasoning_tokens
437+
)
429438

430439
# No tool calls? We're done - return final response
431440
if not response.tool_calls:
@@ -453,11 +462,13 @@ def _send_simple(
453462
result = {"error": f"Unknown tool: {tool_name}"}
454463

455464
# Add tool result to messages
456-
messages.append({
457-
"role": "tool",
458-
"tool_call_id": tool_call["id"],
459-
"content": result if isinstance(result, str) else json.dumps(result),
460-
})
465+
messages.append(
466+
{
467+
"role": "tool",
468+
"tool_call_id": tool_call["id"],
469+
"content": result if isinstance(result, str) else json.dumps(result),
470+
}
471+
)
461472

462473
# Loop continues - model will process tool results
463474

@@ -536,7 +547,9 @@ def _handle_non_streaming_response(self, request: Request) -> SendResponse:
536547
cached_tokens=usage_data.get("input_tokens_details", {}).get("cached_tokens", 0)
537548
),
538549
output_tokens_details=OutputTokenDetails(
539-
reasoning_tokens=usage_data.get("output_tokens_details", {}).get("reasoning_tokens", 0)
550+
reasoning_tokens=usage_data.get("output_tokens_details", {}).get(
551+
"reasoning_tokens", 0
552+
)
540553
),
541554
)
542555

@@ -746,11 +759,13 @@ def _stream_simple(
746759
)
747760

748761
# Add tool result to messages
749-
messages.append({
750-
"role": "tool",
751-
"tool_call_id": tool_call["id"],
752-
"content": result if isinstance(result, str) else json.dumps(result),
753-
})
762+
messages.append(
763+
{
764+
"role": "tool",
765+
"tool_call_id": tool_call["id"],
766+
"content": result if isinstance(result, str) else json.dumps(result),
767+
}
768+
)
754769

755770
# Yield iteration complete event
756771
yield IterationCompleteEvent(iteration=iteration)

examples/stream_tools.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,7 @@ def get_weather(params: WeatherParams) -> dict:
2828
"London": {"temperature": 12, "condition": "rainy"},
2929
"New York": {"temperature": 22, "condition": "sunny"},
3030
}
31-
data = weather_data.get(
32-
params.location, {"temperature": 20, "condition": "unknown"}
33-
)
31+
data = weather_data.get(params.location, {"temperature": 20, "condition": "unknown"})
3432
return {
3533
"location": params.location,
3634
"temperature": data["temperature"],
@@ -62,7 +60,12 @@ def calculate(params: CalculatorParams) -> dict:
6260
}
6361
op = ops.get(params.operation)
6462
if op:
65-
return {"operation": params.operation, "a": params.a, "b": params.b, "result": op(params.a, params.b)}
63+
return {
64+
"operation": params.operation,
65+
"a": params.a,
66+
"b": params.b,
67+
"result": op(params.a, params.b),
68+
}
6669
return {"error": f"Unknown operation: {params.operation}"}
6770

6871

examples/tools_auto.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,7 @@ def get_weather(params: WeatherParams) -> dict:
2929
"London": {"temperature": 12, "condition": "rainy"},
3030
"New York": {"temperature": 22, "condition": "sunny"},
3131
}
32-
data = weather_data.get(
33-
params.location, {"temperature": 20, "condition": "unknown"}
34-
)
32+
data = weather_data.get(params.location, {"temperature": 20, "condition": "unknown"})
3533
return {
3634
"location": params.location,
3735
"temperature": data["temperature"],

examples/tools_multiple.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,7 @@ def get_weather(params: WeatherParams) -> dict:
2626
"London": {"temperature": 12, "condition": "rainy"},
2727
"New York": {"temperature": 22, "condition": "sunny"},
2828
}
29-
data = weather_data.get(
30-
params.location, {"temperature": 20, "condition": "unknown"}
31-
)
29+
data = weather_data.get(params.location, {"temperature": 20, "condition": "unknown"})
3230
return {
3331
"location": params.location,
3432
"temperature": data["temperature"],

0 commit comments

Comments
 (0)