tool-call
: fix passing of tools to template + allow agent to finish
This commit is contained in:
parent
f62e688387
commit
e33b342da7
8 changed files with 8 additions and 11 deletions
|
@ -21,7 +21,6 @@ struct llama_tool_call_handler {
|
||||||
std::string grammar;
|
std::string grammar;
|
||||||
std::vector<std::string> grammar_trigger_words;
|
std::vector<std::string> grammar_trigger_words;
|
||||||
std::vector<std::string> additional_stop_words;
|
std::vector<std::string> additional_stop_words;
|
||||||
nlohmann::ordered_json updated_tools;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
llama_tool_calls parse_tool_calls(llama_tool_call_style style, const nlohmann::ordered_json & tools, const std::string& input);
|
llama_tool_calls parse_tool_calls(llama_tool_call_style style, const nlohmann::ordered_json & tools, const std::string& input);
|
||||||
|
|
|
@ -15,8 +15,7 @@
|
||||||
- Run some tools inside a docker container (check http://localhost:8088/docs once running):
|
- Run some tools inside a docker container (check http://localhost:8088/docs once running):
|
||||||
|
|
||||||
```bash
|
```bash
|
||||||
docker run -p 8088:8088 -w /src \
|
docker run -p 8088:8088 -w /src -v $PWD/examples/agent:/src \
|
||||||
-v $PWD/examples/agent:/src \
|
|
||||||
--rm -it ghcr.io/astral-sh/uv:python3.12-alpine \
|
--rm -it ghcr.io/astral-sh/uv:python3.12-alpine \
|
||||||
uv run fastify.py --port 8088 tools.py
|
uv run fastify.py --port 8088 tools.py
|
||||||
```
|
```
|
||||||
|
|
|
@ -182,6 +182,7 @@ def main(
|
||||||
else:
|
else:
|
||||||
assert content
|
assert content
|
||||||
print(content)
|
print(content)
|
||||||
|
return
|
||||||
|
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
|
|
|
@ -986,6 +986,7 @@ struct server_context {
|
||||||
|
|
||||||
{
|
{
|
||||||
slot.antiprompts.clear();
|
slot.antiprompts.clear();
|
||||||
|
slot.sparams.grammar_trigger_words.clear();
|
||||||
|
|
||||||
auto copy_string_array = [&](const json & data, const std::string & key, std::vector<std::string> & vec) {
|
auto copy_string_array = [&](const json & data, const std::string & key, std::vector<std::string> & vec) {
|
||||||
const auto & arr = data.find(key);
|
const auto & arr = data.find(key);
|
||||||
|
@ -1004,7 +1005,7 @@ struct server_context {
|
||||||
copy_string_array(data, "grammar_trigger_words", slot.sparams.grammar_trigger_words);
|
copy_string_array(data, "grammar_trigger_words", slot.sparams.grammar_trigger_words);
|
||||||
|
|
||||||
slot.antiprompts.build(ctx, stop_words, slot.sparams.grammar_trigger_words);
|
slot.antiprompts.build(ctx, stop_words, slot.sparams.grammar_trigger_words);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
|
|
|
@ -31,11 +31,11 @@ Feature: llama.cpp server
|
||||||
Examples: Prompts
|
Examples: Prompts
|
||||||
| template_name | n_predict | tool_name | tool_arguments | tools |
|
| template_name | n_predict | tool_name | tool_arguments | tools |
|
||||||
| meetkai-functionary-medium-v3.1 | 128 | test | {} | [{"type":"function", "function": {"name": "test", "description": "", "parameters": {"type": "object", "properties": {}}}}] |
|
| meetkai-functionary-medium-v3.1 | 128 | test | {} | [{"type":"function", "function": {"name": "test", "description": "", "parameters": {"type": "object", "properties": {}}}}] |
|
||||||
| meetkai-functionary-medium-v3.1 | 128 | ipython | {"code": "I'm sorry,"} | [{"type":"function", "function": {"name": "ipython", "description": "", "parameters": {"type": "object", "properties": {"code": {"type": "string", "description": ""}}, "required": ["code"]}}}] |
|
| meetkai-functionary-medium-v3.1 | 128 | ipython | {"code": "Yes, you can."} | [{"type":"function", "function": {"name": "ipython", "description": "", "parameters": {"type": "object", "properties": {"code": {"type": "string", "description": ""}}, "required": ["code"]}}}] |
|
||||||
| meetkai-functionary-medium-v3.2 | 128 | test | {} | [{"type":"function", "function": {"name": "test", "description": "", "parameters": {"type": "object", "properties": {}}}}] |
|
| meetkai-functionary-medium-v3.2 | 128 | test | {} | [{"type":"function", "function": {"name": "test", "description": "", "parameters": {"type": "object", "properties": {}}}}] |
|
||||||
| meetkai-functionary-medium-v3.2 | 128 | ipython | {"code": "Yes,"} | [{"type":"function", "function": {"name": "ipython", "description": "", "parameters": {"type": "object", "properties": {"code": {"type": "string", "description": ""}}, "required": ["code"]}}}] |
|
| meetkai-functionary-medium-v3.2 | 128 | ipython | {"code": "Yes,"} | [{"type":"function", "function": {"name": "ipython", "description": "", "parameters": {"type": "object", "properties": {"code": {"type": "string", "description": ""}}, "required": ["code"]}}}] |
|
||||||
| meta-llama-Meta-Llama-3.1-8B-Instruct | 64 | test | {} | [{"type":"function", "function": {"name": "test", "description": "", "parameters": {"type": "object", "properties": {}}}}] |
|
| meta-llama-Meta-Llama-3.1-8B-Instruct | 64 | test | {} | [{"type":"function", "function": {"name": "test", "description": "", "parameters": {"type": "object", "properties": {}}}}] |
|
||||||
| meta-llama-Meta-Llama-3.1-8B-Instruct | 16 | ipython | {"code": ". A"} | [{"type":"function", "function": {"name": "ipython", "description": "", "parameters": {"type": "object", "properties": {"code": {"type": "string", "description": ""}}, "required": ["code"]}}}] |
|
| meta-llama-Meta-Llama-3.1-8B-Instruct | 16 | ipython | {"code": "it and "} | [{"type":"function", "function": {"name": "ipython", "description": "", "parameters": {"type": "object", "properties": {"code": {"type": "string", "description": ""}}, "required": ["code"]}}}] |
|
||||||
|
|
||||||
|
|
||||||
Scenario Outline: OAI Compatibility w/ tools and auto tool_choice
|
Scenario Outline: OAI Compatibility w/ tools and auto tool_choice
|
||||||
|
|
|
@ -384,9 +384,6 @@ static json oaicompat_completion_params_parse(
|
||||||
}
|
}
|
||||||
llama_params["grammar_trigger_words"] = triggers;
|
llama_params["grammar_trigger_words"] = triggers;
|
||||||
}
|
}
|
||||||
if (handler.updated_tools.is_null()) {
|
|
||||||
tools = handler.updated_tools;
|
|
||||||
}
|
|
||||||
if (!handler.grammar.empty()) {
|
if (!handler.grammar.empty()) {
|
||||||
if (llama_params.contains("grammar")) {
|
if (llama_params.contains("grammar")) {
|
||||||
throw std::runtime_error("Cannot use custom grammar constraints with tools.");
|
throw std::runtime_error("Cannot use custom grammar constraints with tools.");
|
||||||
|
|
|
@ -1371,7 +1371,7 @@ static struct llama_sampler_i llama_sampler_grammar_i = {
|
||||||
/* .clone = */ llama_sampler_grammar_clone,
|
/* .clone = */ llama_sampler_grammar_clone,
|
||||||
/* .free = */ llama_sampler_grammar_free,
|
/* .free = */ llama_sampler_grammar_free,
|
||||||
};
|
};
|
||||||
|
|
||||||
bool llama_sampler_is_grammar_empty_impl(struct llama_sampler * gsmpl) {
|
bool llama_sampler_is_grammar_empty_impl(struct llama_sampler * gsmpl) {
|
||||||
struct llama_sampler_grammar * ctx = (struct llama_sampler_grammar *) gsmpl->ctx;
|
struct llama_sampler_grammar * ctx = (struct llama_sampler_grammar *) gsmpl->ctx;
|
||||||
return ctx->grammar == nullptr;
|
return ctx->grammar == nullptr;
|
||||||
|
|
|
@ -21312,7 +21312,7 @@ int32_t llama_chat_apply_template(
|
||||||
struct llama_sampler * llama_sampler_init_grammar(const struct llama_model * model, const char * grammar_str, const char * grammar_root) {
|
struct llama_sampler * llama_sampler_init_grammar(const struct llama_model * model, const char * grammar_str, const char * grammar_root) {
|
||||||
return llama_sampler_init_grammar_impl(model->vocab, grammar_str, grammar_root);
|
return llama_sampler_init_grammar_impl(model->vocab, grammar_str, grammar_root);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool llama_sampler_is_grammar_empty(struct llama_sampler * gsmpl) {
|
bool llama_sampler_is_grammar_empty(struct llama_sampler * gsmpl) {
|
||||||
return llama_sampler_is_grammar_empty_impl(gsmpl);
|
return llama_sampler_is_grammar_empty_impl(gsmpl);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue