MCPcopy Create free account
hub / github.com/andrewkchan/deepseek.cpp / parse_args

Method parse_args

src/main.cpp:203–254  ·  view source on GitHub ↗

Returns true if args are valid, false otherwise

Source from the content-addressed store, hash-verified

201 bool use_wikitext = false;
202 // Returns true if args are valid, false otherwise
203 bool parse_args(const std::vector<const char*>& args) {
204 std::string prompt_path = "";
205 for (size_t i = 0; i < args.size();) {
206 // do some basic validation
207 if (args[i][0] != '-') {
208 return false;
209 } // must start with dash
210 if (strlen(args[i]) != 2) {
211 return false;
212 } // must be -x (one dash, one letter)
213
214 // read in the args
215 if (args[i][1] == 'h') {
216 return false;
217 } else if (args[i][1] == 'i') {
218 if (i + 1 >= args.size()) {
219 return false;
220 }
221 prompt = args[i + 1];
222 i += 2;
223 } else if (args[i][1] == 'f') {
224 if (i + 1 >= args.size()) {
225 return false;
226 }
227 prompt_path = args[i + 1];
228 i += 2;
229 } else if (args[i][1] == 'w') {
230 use_wikitext = true;
231 i += 1;
232 } else {
233 return false;
234 }
235 }
236 int has_prompt = prompt.size() > 0 ? 1 : 0;
237 int has_prompt_path = prompt_path.size() > 0 ? 1 : 0;
238 int has_wikitext = use_wikitext ? 1 : 0;
239 if ((has_prompt + has_prompt_path + has_wikitext) != 1) {
240 std::cerr << "Error: must provide exactly one nonempty -i <input prompt> or -f <input filepath> or -w" << std::endl;
241 return false;
242 } else if (has_prompt_path) {
243 std::ifstream file(prompt_path);
244 if (!file.is_open()) {
245 std::cerr << "Error: could not open file " << prompt_path << std::endl;
246 return false;
247 }
248
249 std::stringstream buffer;
250 buffer << file.rdbuf();
251 prompt = buffer.str();
252 }
253 return true;
254 }
255};
256
257std::vector<int> encode_prompt(const std::string& prompt, Tokenizer& tokenizer) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected