MCPcopy Create free account
hub / github.com/antirez/ds4 / run_repl

Function run_repl

ds4_cli.c:1221–1335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1219 if (rc == 0) {
1220 fprintf(stderr, "ds4: diagnostic run completed on the native %s path.\n",
1221 ds4_backend_name(cfg->engine.backend));
1222 }
1223 } else {
1224 if (cfg->engine.distributed.role == DS4_DISTRIBUTED_COORDINATOR ||
1225 cfg->engine.tp.role == DS4_TP_LEADER ||
1226 getenv("DS4_CLI_FORCE_SESSION") != NULL ||
1227 cfg->gen.temperature > 0.0f ||
1228 ds4_engine_mtp_draft_tokens(engine) > 1) {
1229 /* TP leaders always drive the session path: the sync/eval
1230 * mirroring that keeps the worker in lockstep lives there.
1231 * The env override exists so TP-vs-single-node validation
1232 * compares like with like. */
1233 rc = run_sampled_generation(engine, cfg, &prompt);
1234 } else {
1235 token_printer printer = {
1236 .engine = engine,
1237 .fp = stdout,
1238 .format_thinking = ds4_think_mode_enabled(cli_effective_think_mode(&cfg->gen)),
1239 .in_think = ds4_think_mode_enabled(cli_effective_think_mode(&cfg->gen)),
1240 .use_color = isatty(fileno(stdout)) != 0,
1241 .last_output_newline = true,
1242 };
1243 cli_prefill_progress progress = {
1244 .base_tokens = 0,
1245 .input_tokens = prompt.len,
1246 .use_color = ds4_log_is_tty(stderr),
1247 };
1248 rc = ds4_engine_generate_argmax(engine, &prompt, cfg->gen.n_predict,
1249 cfg->gen.ctx_size,
1250 print_generated_token,
1251 generation_done,
1252 &printer,
1253 cli_prefill_progress_cb,
1254 &progress);
1255 }
1256 }
1257
1258 ds4_tokens_free(&prompt);
1259 return rc;
1260}
1261
1262static char *trim_inplace(char *s) {
1263 while (*s && isspace((unsigned char)*s)) s++;
1264 char *end = s + strlen(s);
1265 while (end > s && isspace((unsigned char)end[-1])) end--;
1266 *end = '\0';
1267 return s;
1268}
1269
1270static void print_repl_help(void) {
1271 puts("Commands:");
1272 puts(" /help Show this help.");
1273 puts(" /think Use normal thinking mode.");
1274 puts(" /think-max Use Think Max only when context is at least 393216 tokens.");
1275 puts(" /nothink Disable thinking mode.");
1276 puts(" /ctx N Set context size for following prompts.");
1277 puts(" /power N Set GPU duty cycle percentage, 1..100.");
1278 puts(" /read FILE Read a prompt from FILE and run it.");

Callers 1

mainFunction · 0.85

Calls 15

repl_chat_initFunction · 0.85
cli_interrupt_clearFunction · 0.85
history_file_pathFunction · 0.85
linenoiseSetMultiLineFunction · 0.85
linenoiseHistoryLoadFunction · 0.85
print_repl_helpFunction · 0.85
linenoiseFunction · 0.85
cli_interrupt_requestedFunction · 0.85
trim_inplaceFunction · 0.85
linenoiseFreeFunction · 0.85
linenoiseHistoryAddFunction · 0.85

Tested by

no test coverage detected