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

Method parse_args

src/main.cpp:91–155  ·  view source on GitHub ↗

Returns true if args are valid, false otherwise

Source from the content-addressed store, hash-verified

89 float top_p = 0.95;
90 // Returns true if args are valid, false otherwise
91 bool parse_args(const std::vector<const char*>& args) {
92 std::string prompt_path = "";
93 for (size_t i = 0; i < args.size();) {
94 // do some basic validation
95 if (args[i][0] != '-') {
96 return false;
97 } // must start with dash
98 if (strlen(args[i]) != 2) {
99 return false;
100 } // must be -x (one dash, one letter)
101
102 // read in the args
103 if (args[i][1] == 'h') {
104 return false;
105 } else if (args[i][1] == 'i') {
106 if (i + 1 >= args.size()) {
107 return false;
108 }
109 prompt = args[i + 1];
110 i += 2;
111 } else if (args[i][1] == 't') {
112 if (i + 1 >= args.size()) {
113 return false;
114 }
115 temperature = std::stof(args[i + 1]);
116 i += 2;
117 } else if (args[i][1] == 'p') {
118 if (i + 1 >= args.size()) {
119 return false;
120 }
121 top_p = std::stof(args[i + 1]);
122 i += 2;
123 } else if (args[i][1] == 'f') {
124 if (i + 1 >= args.size()) {
125 return false;
126 }
127 prompt_path = args[i + 1];
128 i += 2;
129 } else if (args[i][1] == 'n') {
130 if (i + 1 >= args.size()) {
131 return false;
132 }
133 num_steps = std::stoi(args[i + 1]);
134 i += 2;
135 } else {
136 return false;
137 }
138 }
139 int has_prompt = prompt.size() > 0 ? 1 : 0;
140 int has_prompt_path = prompt_path.size() > 0 ? 1 : 0;
141 if ((has_prompt + has_prompt_path) != 1) {
142 return false;
143 } else if (has_prompt_path) {
144 std::ifstream file(prompt_path);
145 if (!file.is_open()) {
146 std::cerr << "Error: could not open file " << prompt_path << std::endl;
147 return false;
148 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected