diff --git a/src/api/routes.py b/src/api/routes.py index 4dc594d..49ed246 100644 --- a/src/api/routes.py +++ b/src/api/routes.py @@ -317,6 +317,26 @@ async def chat_completions(request: ChatCompletionRequest): response_text = result.final_response tokens_generated = len(response_text.split()) # Rough estimate + # Parse tool calls if tools were provided + content = response_text + tool_calls = [] + finish_reason = "stop" + + if has_tools: + content, tool_calls_parsed = parse_tool_calls(response_text) + if tool_calls_parsed: + finish_reason = "tool_calls" + # Convert to ToolCall objects + from api.models import ToolCall + tool_calls = [ + ToolCall( + id=tc.get("id", f"call_{i}"), + type=tc.get("type", "function"), + function=tc.get("function", {}) + ) + for i, tc in enumerate(tool_calls_parsed) + ] + # Estimate prompt tokens (rough approximation) prompt_tokens = len(prompt) // 4 @@ -329,10 +349,10 @@ async def chat_completions(request: ChatCompletionRequest): index=0, message=ChatMessage( role="assistant", - content=response_text, - tool_calls=[] + content=content, + tool_calls=tool_calls ), - finish_reason="stop" + finish_reason=finish_reason ) ], usage=UsageInfo( @@ -359,8 +379,8 @@ async def chat_completions(request: ChatCompletionRequest): finish_reason = "stop" if has_tools: - content, tool_calls = parse_tool_calls(response_text) - if tool_calls: + content, tool_calls_parsed = parse_tool_calls(response_text) + if tool_calls_parsed: finish_reason = "tool_calls" # Convert to ToolCall objects from api.models import ToolCall @@ -370,7 +390,7 @@ async def chat_completions(request: ChatCompletionRequest): type=tc.get("type", "function"), function=tc.get("function", {}) ) - for i, tc in enumerate(tool_calls) + for i, tc in enumerate(tool_calls_parsed) ] # Estimate prompt tokens (rough approximation) diff --git a/src/network/federation.py b/src/network/federation.py index 6c7aea9..b366460 100644 --- a/src/network/federation.py +++ b/src/network/federation.py @@ -208,6 +208,8 @@ class FederatedSwarm: ) print(f" 🌐 Requesting votes from {len(peers)} peer(s)...") + for peer in peers: + print(f" → Contacting {peer.name} at {peer.api_url}") peer_votes = [] vote_tasks = [