|
|
@@ -1948,6 +1948,23 @@ common_params_context common_params_parser_init(common_params & params, llama_ex
|
|
|
params.sampling.grammar = json_schema_to_grammar(json::parse(value));
|
|
|
}
|
|
|
).set_sparam());
|
|
|
+ add_opt(common_arg(
|
|
|
+ {"-jf", "--json-schema-file"}, "FILE",
|
|
|
+ "File containing a 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) {
|
|
|
+ std::ifstream file(value);
|
|
|
+ if (!file) {
|
|
|
+ throw std::runtime_error(string_format("error: failed to open file '%s'\n", value.c_str()));
|
|
|
+ }
|
|
|
+ std::string schema;
|
|
|
+ std::copy(
|
|
|
+ std::istreambuf_iterator<char>(file),
|
|
|
+ std::istreambuf_iterator<char>(),
|
|
|
+ std::back_inserter(schema)
|
|
|
+ );
|
|
|
+ params.sampling.grammar = json_schema_to_grammar(json::parse(schema));
|
|
|
+ }
|
|
|
+ ).set_sparam());
|
|
|
add_opt(common_arg(
|
|
|
{"--pooling"}, "{none,mean,cls,last,rank}",
|
|
|
"pooling type for embeddings, use model default if unspecified",
|