mirror of
https://github.com/ggml-org/llama.cpp.git
synced 2026-09-14 18:02:52 +02:00
revert redundant changes
This commit is contained in:
+8
-7
@@ -54,6 +54,7 @@
|
||||
|
||||
#define LLAMA_MAX_URL_LENGTH 2084 // Maximum URL Length in Chrome: 2083
|
||||
|
||||
using json = common_json;
|
||||
using namespace common_arg_utils;
|
||||
|
||||
static std::initializer_list<enum llama_example> mmproj_examples = {
|
||||
@@ -2270,7 +2271,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
||||
{"-j", "--json-schema"}, "SCHEMA",
|
||||
"JSON schema to constrain generations (https://json-schema.org/), e.g. `{}` for any JSON object\nFor schemas w/ external $refs, use --grammar + example/json_schema_to_grammar.py instead",
|
||||
[](common_params & params, const std::string & value) {
|
||||
params.sampling.grammar = {COMMON_GRAMMAR_TYPE_OUTPUT_FORMAT, json_schema_to_grammar(common_json::parse(value))};
|
||||
params.sampling.grammar = {COMMON_GRAMMAR_TYPE_OUTPUT_FORMAT, json_schema_to_grammar(json::parse(value))};
|
||||
}
|
||||
).set_sampling());
|
||||
add_opt(common_arg(
|
||||
@@ -2287,7 +2288,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
||||
std::istreambuf_iterator<char>(),
|
||||
std::back_inserter(schema)
|
||||
);
|
||||
params.sampling.grammar = {COMMON_GRAMMAR_TYPE_OUTPUT_FORMAT, json_schema_to_grammar(common_json::parse(schema))};
|
||||
params.sampling.grammar = {COMMON_GRAMMAR_TYPE_OUTPUT_FORMAT, json_schema_to_grammar(json::parse(schema))};
|
||||
}
|
||||
).set_sampling());
|
||||
add_opt(common_arg(
|
||||
@@ -3498,13 +3499,13 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
||||
{"--chat-template-kwargs"}, "STRING",
|
||||
"sets additional params for the json template parser, must be a valid json object string, e.g. '{\"key1\":\"value1\",\"key2\":\"value2\"}'",
|
||||
[](common_params & params, const std::string & value) {
|
||||
auto parsed = common_json::parse(value);
|
||||
for (const auto & [key, val] : parsed.items()) {
|
||||
if (key == "enable_thinking") {
|
||||
auto parsed = json::parse(value);
|
||||
for (const auto & item : parsed.items()) {
|
||||
if (item.key() == "enable_thinking") {
|
||||
LOG_WRN("Setting 'enable_thinking' via --chat-template-kwargs is deprecated. "
|
||||
"Use --reasoning on / --reasoning off instead.\n");
|
||||
}
|
||||
params.default_template_kwargs[key] = val.dump();
|
||||
params.default_template_kwargs[item.key()] = item.value().dump();
|
||||
}
|
||||
}
|
||||
).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_CHAT_TEMPLATE_KWARGS"));
|
||||
@@ -3672,7 +3673,7 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
||||
if (value == "default") {
|
||||
params.default_template_kwargs.erase("reasoning_effort");
|
||||
} else {
|
||||
params.default_template_kwargs["reasoning_effort"] = common_json::make(value).dump();
|
||||
params.default_template_kwargs["reasoning_effort"] = json(value).dump();
|
||||
}
|
||||
}
|
||||
).set_examples({LLAMA_EXAMPLE_SERVER, LLAMA_EXAMPLE_COMPLETION, LLAMA_EXAMPLE_CLI}).set_env("LLAMA_ARG_REASONING_EFFORT"));
|
||||
|
||||
@@ -6,9 +6,9 @@
|
||||
#include "log.h"
|
||||
#include "peg-parser.h"
|
||||
|
||||
#include <numeric>
|
||||
#include <algorithm>
|
||||
#include <cctype>
|
||||
#include <numeric>
|
||||
#include <ostream>
|
||||
#include <sstream>
|
||||
|
||||
@@ -930,9 +930,9 @@ void analyze_tools::analyze_tool_call_format_json_native(const std::string & cle
|
||||
std::string cut = clean_haystack.substr(json_start, json_end - json_start + 1);
|
||||
json call_struct = json::parse(cut);
|
||||
auto register_field = [&](const std::string & prefix, const common_json_entry & subel) {
|
||||
if (subel.value().is_string() && subel.value().get<std::string>().find("call0000") != std::string::npos) {
|
||||
if (subel.value().is_string() && std::string(subel.value()).find("call0000") != std::string::npos) {
|
||||
format.id_field = !prefix.empty() ? prefix + "." + subel.key() : subel.key();
|
||||
} else if (subel.value().is_string() && subel.value().get<std::string>() == fun_name_needle) {
|
||||
} else if (subel.value().is_string() && std::string(subel.value()) == fun_name_needle) {
|
||||
format.name_field = !prefix.empty() ? prefix + "." + subel.key() : subel.key();
|
||||
} else if (subel.value().dump().find(arg_name_needle) !=
|
||||
std::string::npos) { // handle both string and JSON obj variants
|
||||
|
||||
@@ -4,7 +4,6 @@
|
||||
#include "ggml.h"
|
||||
#include "peg-parser.h"
|
||||
|
||||
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
|
||||
|
||||
+2
-3
@@ -14,7 +14,6 @@
|
||||
#include "jinja/caps.h"
|
||||
#include "peg-parser.h"
|
||||
|
||||
|
||||
#include <algorithm>
|
||||
#include <cstdio>
|
||||
#include <cstdlib>
|
||||
@@ -596,7 +595,7 @@ std::vector<common_chat_tool> common_chat_tools_parse_oaicompat(const json & too
|
||||
|
||||
const auto & function = tool.at("function");
|
||||
result.push_back({
|
||||
/* .name = */ function.at("name").get<std::string>(),
|
||||
/* .name = */ function.at("name"),
|
||||
/* .description = */ function.value("description", ""),
|
||||
/* .parameters = */ function.value("parameters", json::object()).dump(),
|
||||
});
|
||||
@@ -2483,7 +2482,7 @@ static common_chat_params common_chat_params_init_kimi_k3(const common_chat_temp
|
||||
std::string type = "string";
|
||||
if (prop.value().is_object() && prop.value().contains("type") &&
|
||||
prop.value().at("type").is_string()) {
|
||||
type = prop.value().at("type");
|
||||
type = prop.value().at("type").get<std::string>();
|
||||
}
|
||||
|
||||
auto value = type == "string" ? p.tool_arg_string_value(p.until(ARG_END)) :
|
||||
|
||||
+1
-1
@@ -924,7 +924,7 @@ std::string common_docker_resolve_model(const std::string & docker) {
|
||||
std::string media_type = layer["mediaType"].get<std::string>();
|
||||
if (media_type == "application/vnd.docker.ai.gguf.v3" ||
|
||||
media_type.find("gguf") != std::string::npos) {
|
||||
gguf_digest = layer["digest"];
|
||||
gguf_digest = layer["digest"].get<std::string>();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
+4
-4
@@ -213,7 +213,7 @@ static common_json api_get(const std::string & url,
|
||||
return common_json::parse(res->body);
|
||||
}
|
||||
try {
|
||||
body = common_json::parse(res->body)["error"];
|
||||
body = common_json::parse(res->body)["error"].get<std::string>();
|
||||
} catch (...) { }
|
||||
|
||||
throw std::runtime_error("GET failed (" + std::to_string(res->status) + "): " + body);
|
||||
@@ -320,7 +320,7 @@ hf_files get_repo_files(const std::string & repo_id,
|
||||
|
||||
hf_file file;
|
||||
file.repo_id = repo_id;
|
||||
file.path = item["path"];
|
||||
file.path = item["path"].get<std::string>();
|
||||
|
||||
if (!is_valid_subpath(commit_path, file.path)) {
|
||||
LOG_WRN("%s: skip invalid path: %s\n", __func__, file.path.c_str());
|
||||
@@ -329,10 +329,10 @@ hf_files get_repo_files(const std::string & repo_id,
|
||||
|
||||
if (item.contains("lfs") && item["lfs"].is_object()) {
|
||||
if (item["lfs"].contains("oid") && item["lfs"]["oid"].is_string()) {
|
||||
file.oid = item["lfs"]["oid"];
|
||||
file.oid = item["lfs"]["oid"].get<std::string>();
|
||||
}
|
||||
} else if (item.contains("oid") && item["oid"].is_string()) {
|
||||
file.oid = item["oid"];
|
||||
file.oid = item["oid"].get<std::string>();
|
||||
}
|
||||
|
||||
if (!file.oid.empty() && !is_valid_oid(file.oid)) {
|
||||
|
||||
@@ -370,7 +370,7 @@ caps caps_get(jinja::program & prog) {
|
||||
caps_try_execute(
|
||||
prog,
|
||||
[&]() {
|
||||
json args = json::make(R"({"arg": "value"})");
|
||||
json args = json(R"({"arg": "value"})");
|
||||
if (result.supports_object_arguments) {
|
||||
args = json{{"arg", "value"}};
|
||||
}
|
||||
|
||||
@@ -1378,8 +1378,8 @@ static value from_json(const common_json & j, bool mark_input) {
|
||||
return arr;
|
||||
} else if (j.is_object()) {
|
||||
auto obj = mk_val<value_object>();
|
||||
for (const auto & [key, val] : j.items()) {
|
||||
obj->insert(key, from_json(val, mark_input));
|
||||
for (auto it = j.begin(); it != j.end(); ++it) {
|
||||
obj->insert(it.key(), from_json(it.value(), mark_input));
|
||||
}
|
||||
return obj;
|
||||
} else {
|
||||
@@ -1451,19 +1451,18 @@ bool value_compare(const value & a, const value & b, value_compare_op op) {
|
||||
return result;
|
||||
}
|
||||
|
||||
template<typename T_JSON>
|
||||
void global_from_json(context & ctx, const T_JSON & json_obj, bool mark_input) {
|
||||
template<>
|
||||
void global_from_json(context & ctx, const common_json & json_obj, bool mark_input) {
|
||||
// printf("global_from_json: %s\n" , json_obj.dump(2).c_str());
|
||||
if (json_obj.is_null() || !json_obj.is_object()) {
|
||||
throw std::runtime_error("global_from_json: input JSON value must be an object");
|
||||
}
|
||||
for (const auto & [key, val] : json_obj.items()) {
|
||||
JJ_DEBUG("global_from_json: setting key '%s'", key.c_str());
|
||||
ctx.set_val(key, from_json(val, mark_input));
|
||||
for (auto it = json_obj.begin(); it != json_obj.end(); ++it) {
|
||||
JJ_DEBUG("global_from_json: setting key '%s'", it.key().c_str());
|
||||
ctx.set_val(it.key(), from_json(it.value(), mark_input));
|
||||
}
|
||||
}
|
||||
|
||||
template void global_from_json<common_json>(context &, const common_json &, bool);
|
||||
|
||||
// recursively convert value to JSON string
|
||||
// TODO: avoid circular references
|
||||
static void value_to_json_internal(std::ostringstream & oss, const value & val, int curr_lvl, int indent, const std::string_view item_sep, const std::string_view key_sep) {
|
||||
|
||||
@@ -916,7 +916,7 @@ public:
|
||||
std::string rule_name = is_reserved_name(name) ? name + "-" : name.empty() ? "root" : name;
|
||||
|
||||
if (schema.contains("$ref")) {
|
||||
return _add_rule(rule_name, _resolve_ref(schema["$ref"].get<std::string>()));
|
||||
return _add_rule(rule_name, _resolve_ref(schema["$ref"]));
|
||||
}
|
||||
if (schema.contains("oneOf") || schema.contains("anyOf")) {
|
||||
const json & alts = schema.contains("oneOf") ? schema.at("oneOf") : schema.at("anyOf");
|
||||
@@ -974,7 +974,7 @@ public:
|
||||
const std::string& hybrid_name = name;
|
||||
std::function<void(const json &, bool)> add_component = [&](const json & comp_schema, bool is_required) {
|
||||
if (comp_schema.contains("$ref")) {
|
||||
add_component(_refs[comp_schema["$ref"].get<std::string>()], is_required);
|
||||
add_component(_refs[comp_schema["$ref"]], is_required);
|
||||
} else if (comp_schema.contains("properties")) {
|
||||
for (const auto & prop : comp_schema["properties"].items()) {
|
||||
properties.emplace_back(prop.key(), prop.value());
|
||||
@@ -1037,7 +1037,7 @@ public:
|
||||
return _add_rule(rule_name, "\"[\" space " + build_repetition(item_rule_name, min_items, max_items, "\",\" space") + " space \"]\"");
|
||||
}
|
||||
if ((schema_type.is_null() || schema_type == "string") && schema.contains("pattern")) {
|
||||
return _visit_pattern(schema["pattern"].get<std::string>(), rule_name);
|
||||
return _visit_pattern(schema["pattern"], rule_name);
|
||||
}
|
||||
if ((schema_type.is_null() || schema_type == "string") && std::regex_match(schema_format, std::regex("^uuid[1-5]?$"))) {
|
||||
return _add_primitive(rule_name == "root" ? "root" : schema_format, PRIMITIVE_RULES.at("uuid"));
|
||||
@@ -1135,7 +1135,7 @@ bool common_schema_info::resolves_to_string(const common_json & schema) {
|
||||
|
||||
// Handle $ref
|
||||
if (s.contains("$ref")) {
|
||||
const std::string ref = s["$ref"];
|
||||
const std::string & ref = s["$ref"];
|
||||
if (visited_refs.find(ref) != visited_refs.end()) {
|
||||
// Circular reference, assume not a string to be safe
|
||||
return false;
|
||||
@@ -1218,7 +1218,7 @@ bool common_schema_info::resolves_to_string(const common_json & schema) {
|
||||
|
||||
// Check format - many formats imply string
|
||||
if (s.contains("format")) {
|
||||
const std::string fmt = s["format"];
|
||||
const std::string & fmt = s["format"];
|
||||
if (fmt == "date" || fmt == "time" || fmt == "date-time" ||
|
||||
fmt == "uri" || fmt == "email" || fmt == "hostname" ||
|
||||
fmt == "ipv4" || fmt == "ipv6" || fmt == "uuid" ||
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
|
||||
#include "json.h"
|
||||
|
||||
|
||||
#include <functional>
|
||||
#include <memory>
|
||||
#include <string>
|
||||
|
||||
@@ -82,6 +82,10 @@ common_json_value::common_json_value(const char * val) {
|
||||
common_json_value::common_json_value(const common_json & val) :
|
||||
type(VAL_JSON), val_json(std::make_shared<common_json>(val)) {}
|
||||
|
||||
common_json_value::common_json_value(const std::map<std::string, std::string> & vals) : type(VAL_JSON) {
|
||||
val_json = std::make_shared<common_json>(common_json_from_raw(ordered_json(vals)));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
common_json_value::common_json_value(const std::vector<T> & vals) : type(VAL_JSON) {
|
||||
common_json out = common_json::array();
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <cstdint>
|
||||
#include <initializer_list>
|
||||
#include <iterator>
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
@@ -58,6 +59,8 @@ struct common_json_value {
|
||||
common_json_value(std::string_view val) : type(VAL_STRING), val_string(val) {}
|
||||
common_json_value(const char * val);
|
||||
common_json_value(const common_json & val);
|
||||
// becomes an object, so a plain string map can be passed where a JSON value is expected
|
||||
common_json_value(const std::map<std::string, std::string> & vals);
|
||||
// only for the types instantiated in json.cpp, the rest fails at link time
|
||||
template <typename T> common_json_value(const std::vector<T> & vals);
|
||||
|
||||
|
||||
@@ -299,10 +299,10 @@ void run_single(const std::string& contents, json input, bool use_common, bool d
|
||||
std::string bos_token = "<s>";
|
||||
std::string eos_token = "</s>";
|
||||
if (input.contains("bos_token")) {
|
||||
bos_token = input["bos_token"];
|
||||
bos_token = input["bos_token"].get<std::string>();
|
||||
}
|
||||
if (input.contains("eos_token")) {
|
||||
eos_token = input["eos_token"];
|
||||
eos_token = input["eos_token"].get<std::string>();
|
||||
}
|
||||
common_json msgs_json = input["messages"];
|
||||
common_json tools_json = input["tools"];
|
||||
|
||||
@@ -341,7 +341,7 @@ json server_chat_convert_anthropic_to_oai(const json & body) {
|
||||
std::string system_content;
|
||||
|
||||
if (system_param.is_string()) {
|
||||
system_content = system_param;
|
||||
system_content = system_param.get<std::string>();
|
||||
normalize_anthropic_billing_header(system_content);
|
||||
} else if (system_param.is_array()) {
|
||||
for (const auto & block : system_param) {
|
||||
|
||||
@@ -8,7 +8,6 @@
|
||||
|
||||
#include "json.h"
|
||||
|
||||
|
||||
// Convert OpenAI Responses API format to OpenAI Chat Completions API format
|
||||
json server_chat_convert_responses_to_chatcmpl(const json & body);
|
||||
|
||||
|
||||
@@ -9,7 +9,6 @@
|
||||
|
||||
#include "server-common.h"
|
||||
|
||||
|
||||
#include <random>
|
||||
#include <sstream>
|
||||
#include <fstream>
|
||||
@@ -978,9 +977,9 @@ static server_tokens tokenize_input_subprompt(const llama_vocab * vocab, mtmd_co
|
||||
// JSON object with prompt and multimodal key.
|
||||
std::vector<raw_buffer> files;
|
||||
for (const auto & entry : json_prompt.at(JSON_MTMD_DATA_KEY)) {
|
||||
files.push_back(base64_decode(entry.get<std::string>()));
|
||||
files.push_back(base64_decode(entry));
|
||||
}
|
||||
return process_mtmd_prompt(mctx, json_prompt.at(JSON_STRING_PROMPT_KEY).get<std::string>(), files);
|
||||
return process_mtmd_prompt(mctx, json_prompt.at(JSON_STRING_PROMPT_KEY), files);
|
||||
} else {
|
||||
// Not multimodal, but contains a subobject.
|
||||
llama_tokens tmp = tokenize_mixed(vocab, json_prompt.at(JSON_STRING_PROMPT_KEY), add_special, parse_special);
|
||||
@@ -1301,8 +1300,7 @@ json oaicompat_chat_params_parse(
|
||||
}
|
||||
|
||||
// parse the "enable_thinking" kwarg to override the default value
|
||||
const auto kwarg_it = inputs.chat_template_kwargs.find("enable_thinking");
|
||||
std::string enable_thinking_kwarg = kwarg_it == inputs.chat_template_kwargs.end() ? "" : kwarg_it->second;
|
||||
auto enable_thinking_kwarg = json_value(inputs.chat_template_kwargs, "enable_thinking", std::string(""));
|
||||
if (enable_thinking_kwarg == "true") {
|
||||
inputs.enable_thinking = true;
|
||||
} else if (enable_thinking_kwarg == "false") {
|
||||
@@ -1318,7 +1316,7 @@ json oaicompat_chat_params_parse(
|
||||
inputs.enable_thinking = false;
|
||||
inputs.chat_template_kwargs.erase("reasoning_effort");
|
||||
} else if (!reasoning_effort.empty()) {
|
||||
inputs.chat_template_kwargs["reasoning_effort"] = json::make(reasoning_effort).dump();
|
||||
inputs.chat_template_kwargs["reasoning_effort"] = json(reasoning_effort).dump();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1467,10 +1465,7 @@ json format_response_rerank(
|
||||
});
|
||||
|
||||
elements.resize(std::min(top_n, (int)elements.size()));
|
||||
json results = json::array();
|
||||
for (const auto & el : elements) {
|
||||
results.push_back(el);
|
||||
}
|
||||
json results = elements;
|
||||
|
||||
if (is_tei_format) return results;
|
||||
|
||||
@@ -1795,12 +1790,12 @@ server_tokens format_prompt_rerank(
|
||||
std::string prompt = rerank_prompt;
|
||||
string_replace_all(prompt, "{query}" , query);
|
||||
string_replace_all(prompt, "{document}", doc );
|
||||
server_tokens tokens = tokenize_input_subprompt(vocab, mctx, json::make(prompt), false, true);
|
||||
server_tokens tokens = tokenize_input_subprompt(vocab, mctx, prompt, false, true);
|
||||
result.push_back(tokens);
|
||||
} else {
|
||||
// Get EOS token - use SEP token as fallback if EOS is not available
|
||||
server_tokens query_tokens = tokenize_input_subprompt(vocab, mctx, json::make(query), false, false);
|
||||
server_tokens doc_tokens = tokenize_input_subprompt(vocab, mctx, json::make(doc), false, false);
|
||||
server_tokens query_tokens = tokenize_input_subprompt(vocab, mctx, query, false, false);
|
||||
server_tokens doc_tokens = tokenize_input_subprompt(vocab, mctx, doc, false, false);
|
||||
llama_token eos_token = llama_vocab_eos(vocab);
|
||||
if (eos_token == LLAMA_TOKEN_NULL) {
|
||||
eos_token = llama_vocab_sep(vocab);
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
|
||||
constexpr int HTTP_POLLING_SECONDS = 1;
|
||||
|
||||
static common_speculative_output_limits server_output_limits(const common_params & params) {
|
||||
|
||||
@@ -157,7 +157,7 @@ std::vector<server_mcp_server_config> server_mcp_server_config::parse_cursor_for
|
||||
}
|
||||
if (cfg.contains("env") && cfg.at("env").is_object()) {
|
||||
for (const auto & [k, v] : cfg.at("env").items()) {
|
||||
sc.env[k] = v;
|
||||
sc.env[k] = v.get<std::string>();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -487,7 +487,7 @@ std::vector<std::unique_ptr<field>> make_llama_cmpl_schema(const common_params &
|
||||
const auto & stop = data.at("stop");
|
||||
if (stop.is_array()) {
|
||||
for (const auto & word : stop) {
|
||||
if (!word.empty()) ctx.params.antiprompt.push_back(word.get<std::string>());
|
||||
if (!word.empty()) ctx.params.antiprompt.push_back(word);
|
||||
}
|
||||
} else if (stop.is_string()) {
|
||||
ctx.params.antiprompt.push_back(stop.get<std::string>());
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
#include "server-task.h"
|
||||
|
||||
|
||||
#include "build-info.h"
|
||||
#include "server-chat.h"
|
||||
#include "chat.h"
|
||||
@@ -13,7 +12,6 @@
|
||||
|
||||
#include <sstream>
|
||||
|
||||
|
||||
//
|
||||
// task_params
|
||||
//
|
||||
|
||||
@@ -1420,8 +1420,8 @@ struct server_tool_edit_file : server_tool {
|
||||
edits.reserve(edits_json.size());
|
||||
for (const auto & e : edits_json) {
|
||||
edit_req er;
|
||||
er.old_text = e.at("old_text");
|
||||
er.new_text = e.at("new_text");
|
||||
er.old_text = e.at("old_text").get<std::string>();
|
||||
er.new_text = e.at("new_text").get<std::string>();
|
||||
if (er.old_text.empty()) {
|
||||
return {{"error", string_format("edits[%zu].old_text must not be empty", edits.size())}};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user