common : remove json.hpp from common.cpp (#12697)

* common : remove json.hpp from common.cpp

* fix comment
This commit is contained in:
Xuan-Son Nguyen 2025-04-02 09:58:34 +02:00 committed by GitHub
parent 9bacd6b374
commit 42eb248f46
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 34 additions and 38 deletions

View file

@ -7,9 +7,6 @@
#include "common.h"
#include "log.h"
// Change JSON_ASSERT from assert() to GGML_ASSERT:
#define JSON_ASSERT GGML_ASSERT
#include "json.hpp"
#include "llama.h"
#include <algorithm>
@ -56,8 +53,6 @@
#pragma warning(disable: 4244 4267) // possible loss of data
#endif
using json = nlohmann::ordered_json;
//
// CPU utils
//
@ -1545,26 +1540,3 @@ common_control_vector_data common_control_vector_load(const std::vector<common_c
return result;
}
template <>
json common_grammar_trigger::to_json() const {
json out {
{"type", (int) type},
{"value", value},
};
if (type == COMMON_GRAMMAR_TRIGGER_TYPE_TOKEN) {
out["token"] = (int) token;
}
return out;
}
template <>
common_grammar_trigger common_grammar_trigger::from_json(const json & in) {
common_grammar_trigger out;
out.type = (common_grammar_trigger_type) in.at("type").get<int>();
out.value = in.at("value").get<std::string>();
if (out.type == COMMON_GRAMMAR_TRIGGER_TYPE_TOKEN) {
out.token = (llama_token) in.at("token").get<int>();
}
return out;
}

View file

@ -121,10 +121,6 @@ struct common_grammar_trigger {
common_grammar_trigger_type type;
std::string value;
llama_token token = LLAMA_TOKEN_NULL;
// T can only be nlohmann::ordered_json
template <class T> T to_json() const;
template <class T> static common_grammar_trigger from_json(const T & in);
};
// sampling parameters