fixed bugs in function_calling.rs that were breaking tests. All good now

This commit is contained in:
Salman Paracha 2025-11-15 14:52:55 -08:00
parent 60e489099d
commit 1f5784a9ff
5 changed files with 71 additions and 15 deletions

View file

@ -987,10 +987,13 @@ impl ArchFunctionHandler {
info!("[arch-fc]: raw model response: {}", response_dict.raw_response);
// General model response (no intent matched - should route to default target)
let model_message = if response_dict.response.as_ref().map_or(false, |s| !s.is_empty()) {
// When arch-fc returns a "response" field, it means no intent was matched
// Return empty content and empty tool_calls so prompt_gateway routes to default target
ResponseMessage {
role: Role::Assistant,
content: response_dict.response.clone(),
content: Some(String::new()),
refusal: None,
annotations: None,
audio: None,
@ -1105,6 +1108,14 @@ impl ArchFunctionHandler {
}
};
// Create metadata with the raw model response
let mut metadata = HashMap::new();
metadata.insert(
"x-arch-fc-model-response".to_string(),
serde_json::to_value(&response_dict.raw_response)
.unwrap_or_else(|_| Value::String(response_dict.raw_response.clone())),
);
let chat_completion_response = ChatCompletionsResponse {
id: format!("chatcmpl-{}", uuid::Uuid::new_v4()),
object: Some("chat.completion".to_string()),
@ -1125,7 +1136,7 @@ impl ArchFunctionHandler {
},
system_fingerprint: None,
service_tier: None,
metadata: None,
metadata: Some(metadata),
};
info!("[response arch-fc]: {:?}", chat_completion_response);

View file

@ -264,13 +264,6 @@ impl StreamContext {
.tool_calls
.clone_into(&mut self.tool_calls);
if self.tool_calls.as_ref().unwrap().len() > 1 {
warn!(
"multiple tool calls not supported yet, tool_calls count found: {}",
self.tool_calls.as_ref().unwrap().len()
);
}
if self.tool_calls.is_none() || self.tool_calls.as_ref().unwrap().is_empty() {
// This means that Arch FC did not have enough information to resolve the function call
// Arch FC probably responded with a message asking for more information.
@ -314,6 +307,14 @@ impl StreamContext {
);
}
// At this point, we know tool_calls is not None and not empty
if self.tool_calls.as_ref().unwrap().len() > 1 {
warn!(
"multiple tool calls not supported yet, tool_calls count found: {}",
self.tool_calls.as_ref().unwrap().len()
);
}
// update prompt target name from the tool call response
callout_context.prompt_target_name =
Some(self.tool_calls.as_ref().unwrap()[0].function.name.clone());