2024-09-25 15:08:29 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include "ggml.h"
|
2024-09-26 05:50:51 +00:00
|
|
|
#include "common.h"
|
2024-10-01 22:12:24 +00:00
|
|
|
#include "chat-template.hpp"
|
2024-09-25 15:08:29 +00:00
|
|
|
// Change JSON_ASSERT from assert() to GGML_ASSERT:
|
|
|
|
#define JSON_ASSERT GGML_ASSERT
|
|
|
|
#include "json.hpp"
|
2024-10-01 22:12:24 +00:00
|
|
|
|
|
|
|
enum llama_tool_call_style {
|
|
|
|
UnknownToolCallStyle,
|
|
|
|
Llama31,
|
|
|
|
Llama32,
|
|
|
|
FunctionaryV3Llama3,
|
|
|
|
FunctionaryV3Llama31,
|
|
|
|
Hermes2Pro,
|
|
|
|
CommandRPlus,
|
|
|
|
};
|
2024-09-26 16:19:29 +00:00
|
|
|
|
|
|
|
struct llama_tool_call {
|
|
|
|
std::string name;
|
|
|
|
std::string arguments;
|
|
|
|
};
|
2024-09-25 15:08:29 +00:00
|
|
|
|
|
|
|
struct llama_tool_calls {
|
|
|
|
std::string content;
|
2024-09-26 16:19:29 +00:00
|
|
|
std::vector<llama_tool_call> tool_calls;
|
2024-09-25 15:08:29 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
struct llama_tool_call_handler {
|
2024-09-28 16:46:36 +00:00
|
|
|
std::string prompt;
|
2024-09-25 15:08:29 +00:00
|
|
|
std::string grammar;
|
|
|
|
std::vector<std::string> grammar_trigger_words;
|
|
|
|
std::vector<std::string> additional_stop_words;
|
|
|
|
};
|
|
|
|
|
2024-10-01 22:12:24 +00:00
|
|
|
llama_tool_call_style llama_tool_call_style_detect(const minja::chat_template & chat_template);
|
|
|
|
|
2024-09-26 16:19:29 +00:00
|
|
|
llama_tool_calls parse_tool_calls(llama_tool_call_style style, const nlohmann::ordered_json & tools, const std::string& input);
|
2024-09-25 15:08:29 +00:00
|
|
|
|
|
|
|
llama_tool_call_handler llama_tool_call_handler_init(
|
2024-10-01 22:12:24 +00:00
|
|
|
llama_tool_call_style style,
|
|
|
|
const minja::chat_template & tmpl,
|
2024-09-25 15:08:29 +00:00
|
|
|
bool allow_content,
|
|
|
|
bool parallel_tool_calls,
|
2024-09-28 16:46:36 +00:00
|
|
|
const nlohmann::ordered_json & messages,
|
2024-09-25 15:08:29 +00:00
|
|
|
const nlohmann::ordered_json & tools);
|