Skip to content

Commit

Permalink
[Feat] Add a verbose option for json_schema_converter (#97)
Browse files Browse the repository at this point in the history
This PR provides a verbose option for json_schema_converter.
  • Loading branch information
Ubospica authored Nov 25, 2024
1 parent 566455c commit bea9cbc
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions cpp/json_schema_converter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,12 +158,12 @@ class JSONSchemaConverter {

/*! \brief Warn if any keyword is existing in the schema but not supported. */
static void WarnUnsupportedKeywords(
const picojson::value& schema, const std::vector<std::string>& keywords
const picojson::value& schema, const std::vector<std::string>& keywords, bool verbose = false
);

/*! \brief Warn if any keyword is existing in the object but not supported. */
static void WarnUnsupportedKeywords(
const picojson::object& schema, const std::vector<std::string>& keywords
const picojson::object& schema, const std::vector<std::string>& keywords, bool verbose = false
);

/*! \brief Visit the schema and return the rule body for later constructing the rule. */
Expand Down Expand Up @@ -417,19 +417,22 @@ std::string JSONSchemaConverter::NextSeparator(bool is_end) {
}

void JSONSchemaConverter::WarnUnsupportedKeywords(
const picojson::value& schema, const std::vector<std::string>& keywords
const picojson::value& schema, const std::vector<std::string>& keywords, bool verbose
) {
if (schema.is<bool>()) {
return;
}

XGRAMMAR_DCHECK(schema.is<picojson::object>());
WarnUnsupportedKeywords(schema.get<picojson::object>(), keywords);
WarnUnsupportedKeywords(schema.get<picojson::object>(), keywords, verbose);
}

void JSONSchemaConverter::WarnUnsupportedKeywords(
const picojson::object& schema, const std::vector<std::string>& keywords
const picojson::object& schema, const std::vector<std::string>& keywords, bool verbose
) {
if (!verbose) {
return;
}
for (const auto& keyword : keywords) {
if (schema.find(keyword) != schema.end()) {
XGRAMMAR_LOG(WARNING) << "Keyword " << keyword << " is not supported in schema "
Expand Down

0 comments on commit bea9cbc

Please sign in to comment.