fix: add tool parsing to federation path and debug logging
- Add tool call parsing when using federation (was missing) - Add debug output showing which peers are being contacted - Fix variable shadowing in tool_calls parsing
This commit is contained in:
+26
-6
@@ -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)
|
||||
|
||||
@@ -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 = [
|
||||
|
||||
Reference in New Issue
Block a user