Skip to content

Commit a117630

Browse files
author
ochafik
committed
Ensure there's a non empty tool call id
1 parent 1e2f78a commit a117630

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

examples/server/server.cpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -750,7 +750,10 @@ struct server_task_result_cmpl_final : server_task_result {
750750
{"name", tc.name},
751751
{"arguments", tc.arguments},
752752
}},
753-
{"id", tc.id},
753+
// Some templates generate and require an id (sometimes in a very specific format, e.g. Mistral Nemo).
754+
// We only generate a random id for the ones that don't generate one by themselves
755+
// (they also won't get to see it as their template likely doesn't use it, so it's all for the client)
756+
{"id", tc.id.empty() ? gen_tool_call_id() : tc.id},
754757
});
755758
}
756759
message["tool_calls"] = tool_calls;

examples/server/utils.hpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -435,6 +435,10 @@ static std::string gen_chatcmplid() {
435435
return "chatcmpl-" + random_string();
436436
}
437437

438+
static std::string gen_tool_call_id() {
439+
return random_string();
440+
}
441+
438442
//
439443
// other common utils
440444
//

0 commit comments

Comments
 (0)