You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: examples/server/tool-call.hpp
+15-9Lines changed: 15 additions & 9 deletions
Original file line number
Diff line number
Diff line change
@@ -51,11 +51,9 @@ inline std::string format_chat_with_tool(enum llama_tool_format format, const st
51
51
std::stringstream ss;
52
52
auto chat = parse_chat_messages(messages);
53
53
if (format == LLAMA_TOOL_FORMAT_HERMES_3) {
54
-
ss << "<|im_start|>system\n\n";
55
-
ss << "You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools: <tools>\n\n";
56
-
for (auto tool : tools) {
57
-
ss << tool.dump(1, '\t') << "\n\n";
58
-
}
54
+
ss << "<|im_start|>system\n";
55
+
ss << "You are a function calling AI model. You are provided with function signatures within <tools></tools> XML tags. You may call one or more functions to assist with the user query. Don't make assumptions about what values to plug into functions. Here are the available tools: <tools> ";
56
+
ss << tools.dump() << "";
59
57
ss << "</tools> Use the following pydantic model json schema for each tool call you will make: {\"properties\": {\"arguments\": {\"title\": \"Arguments\", \"type\": \"object\"}, \"name\": {\"title\": \"Name\", \"type\": \"string\"}}, \"required\": [\"arguments\", \"name\"], \"title\": \"FunctionCall\", \"type\": \"object\"} For each function call return a json object with function name and arguments within <tool_call></tool_call> XML tags as follows:\n";
60
58
ss << "<tool_call>\n";
61
59
ss << "{\"arguments\": <args-dict>, \"name\": <function-name>}\n";
@@ -65,14 +63,22 @@ inline std::string format_chat_with_tool(enum llama_tool_format format, const st
65
63
if (role == "system") {
66
64
continue; // for optimal performance, we skip user-defined system message
67
65
}
68
-
ss << "<|im_start|>" << role << "\n\n";
66
+
ss << "<|im_start|>" << role << "\n";
69
67
if (role == "tool") {
70
68
ss << "<tool_response>\n" << string_strip(message.content) << "\n</tool_response>\n";
71
-
} else {
72
-
ss << string_strip(message.content) << "<|im_end|>\n";
73
69
}
70
+
elseif (role == "user") {
71
+
ss << string_strip(message.content);
72
+
}
73
+
elseif (role == "assistant") {
74
+
ss << string_strip(message.content);
75
+
if (!message.tool_calls.empty()) {
76
+
ss << "<tool_call>\n" << string_strip(message.tool_calls) << "\n</tool_call>";
77
+
}
78
+
}
79
+
ss << "<|im_end|>\n";
74
80
}
75
-
ss << "<|im_start|>assistant\n\n";
81
+
ss << "<|im_start|>assistant\n";
76
82
} else {
77
83
throwstd::runtime_error("tool_call is not supported by this model");
0 commit comments