mirror of
				https://github.com/ggml-org/llama.cpp.git
				synced 2025-11-03 09:22:01 +00:00 
			
		
		
		
	common : add -jf / --json-schema-file flag (#12011)
This commit is contained in:
		@@ -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",
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user