Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions sgl-router/src/routers/grpc/processing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,8 @@ impl ResponseProcessor {
(tool_calls, processed_text) = utils::parse_json_schema_response(
&processed_text,
&original_request.tool_choice,
&original_request.model,
history_tool_calls_count,
);
} else if tool_parser_available {
(tool_calls, processed_text) = self
Expand Down
16 changes: 14 additions & 2 deletions sgl-router/src/routers/grpc/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -542,14 +542,21 @@ pub fn create_stop_decoder(
pub fn parse_json_schema_response(
processed_text: &str,
tool_choice: &Option<ToolChoice>,
model: &str,
history_tool_calls_count: usize,
) -> (Option<Vec<ToolCall>>, String) {
match tool_choice {
Some(ToolChoice::Function { function, .. }) => {
// Specific function: Parse parameters directly
match serde_json::from_str::<Value>(processed_text) {
Ok(params) => {
let tool_call = ToolCall {
id: format!("call_{}", Uuid::new_v4()),
id: generate_tool_call_id(
model,
&function.name,
0,
history_tool_calls_count,
),
tool_type: "function".to_string(),
function: FunctionCallResponse {
name: function.name.clone(),
Expand Down Expand Up @@ -580,7 +587,12 @@ pub fn parse_json_schema_response(
let parameters = obj.get("parameters")?;

Some(ToolCall {
id: format!("call_{}_{}", i, Uuid::new_v4()),
id: generate_tool_call_id(
model,
&name,
i,
history_tool_calls_count,
),
tool_type: "function".to_string(),
function: FunctionCallResponse {
name,
Expand Down
Loading