MCPcopy Create free account
hub / github.com/antirez/llama.cpp-deepseek-v4-flash / generate_response

Function generate_response

tools/mtmd/mtmd-cli.cpp:178–219  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

176};
177
178static int generate_response(mtmd_cli_context & ctx, int n_predict) {
179 llama_tokens generated_tokens;
180 for (int i = 0; i < n_predict; i++) {
181 if (i > n_predict || !g_is_generating || g_is_interrupted) {
182 LOG("\n");
183 break;
184 }
185
186 llama_token token_id = common_sampler_sample(ctx.smpl, ctx.lctx, -1);
187 generated_tokens.push_back(token_id);
188 common_sampler_accept(ctx.smpl, token_id, true);
189
190 if (llama_vocab_is_eog(ctx.vocab, token_id) || ctx.check_antiprompt(generated_tokens)) {
191 LOG("\n");
192 break; // end of generation
193 }
194
195 LOG("%s", common_token_to_piece(ctx.lctx, token_id).c_str());
196 fflush(stdout);
197
198 if (g_is_interrupted) {
199 LOG("\n");
200 break;
201 }
202
203 // eval the token
204 common_batch_clear(ctx.batch);
205 common_batch_add(ctx.batch, token_id, ctx.n_past++, {0}, true);
206 if (llama_decode(ctx.lctx, ctx.batch)) {
207 LOG_ERR("failed to decode token\n");
208 return 1;
209 }
210 }
211
212 std::string generated_text = common_detokenize(ctx.lctx, generated_tokens);
213 common_chat_msg msg;
214 msg.role = "assistant";
215 msg.content = generated_text;
216 ctx.chat_history.push_back(std::move(msg));
217
218 return 0;
219}
220
221static std::string chat_add_and_format(mtmd_cli_context & ctx, common_chat_msg & new_msg) {
222 LOG_DBG("chat_add_and_format: new_msg.role='%s', new_msg.content='%s'\n",

Callers 1

mainFunction · 0.85

Calls 10

common_sampler_sampleFunction · 0.85
common_sampler_acceptFunction · 0.85
llama_vocab_is_eogFunction · 0.85
common_token_to_pieceFunction · 0.85
common_batch_clearFunction · 0.85
common_batch_addFunction · 0.85
llama_decodeFunction · 0.85
common_detokenizeFunction · 0.85
check_antipromptMethod · 0.80
push_backMethod · 0.45

Tested by

no test coverage detected