Felipe97/llama-cpp-compiled
01.1k
1#pragma once2 3#include "common.h"4#include "arg.h"5 6#include <string>7#include <vector>8#include <map>9#include <set>10 11//12// INI preset parser and writer13//14 15constexpr const char * COMMON_PRESET_DEFAULT_NAME = "default";16 17struct common_preset_context;18 19struct common_preset {20 std::string name;21 22 // options are stored as common_arg to string mapping, representing CLI arg and its value23 std::map<common_arg, std::string> options;24 25 // convert preset to CLI argument list26 std::vector<std::string> to_args(const std::string & bin_path = "") const;27 28 // convert preset to INI format string29 std::string to_ini() const;30 31 // TODO: maybe implement to_env() if needed32 33 // modify preset options where argument is identified by its env variable34 void set_option(const common_preset_context & ctx, const std::string & env, const std::string & value);35 36 // unset option by its env variable37 void unset_option(const std::string & env);38 39 // get option value by its env variable, return false if not found40 bool get_option(const std::string & env, std::string & value) const;41 42 // merge another preset into this one, overwriting existing options43 void merge(const common_preset & other);44 45 // apply preset options to common_params46 // optionally specify handled_keys to only apply a subset of options (identified by their env), if empty, apply all options47 void apply_to_params(common_params & params, const std::set<std::string> & handled_keys = std::set<std::string>()) const;48};49 50// interface for multiple presets in one file51using common_presets = std::map<std::string, common_preset>;52 53// context for loading and editing presets54struct common_preset_context {55 common_params default_params; // unused for now56 common_params_context ctx_params;57 std::map<std::string, common_arg> key_to_opt;58 59 bool filter_allowed_keys = false;60 std::set<std::string> allowed_keys;61 62 // if true, options unknown to the current example are skipped instead of being an error63 // used for config files shared by all binaries, where each binary only knows a subset of options64 bool ignore_unknown_keys = false;65 66 // if only_remote_allowed is true, only accept whitelisted keys67 common_preset_context(llama_example ex);68 69 // load presets from INI file70 common_presets load_from_ini(const std::string & path, common_preset & global) const;71 72 // generate presets from cached models73 common_presets load_from_cache() const;74 75 // generate presets from local models directory76 // for the directory structure, see "Using multiple models" in server/README.md77 common_presets load_from_models_dir(const std::string & models_dir) const;78 79 // generate one preset from CLI arguments80 common_preset load_from_args(int argc, char ** argv) const;81 82 // cascade multiple presets if exist on both: base < added83 // if preset does not exist in base, it will be added without modification84 common_presets cascade(const common_presets & base, const common_presets & added) const;85 86 // apply presets over a base preset (same idea as CSS cascading)87 common_presets cascade(const common_preset & base, const common_presets & presets) const;88};89 