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

Function run_interactive

src/main.cpp:514–592  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

512}
513
514void run_interactive(Session& session) {
515 std::string input = "";
516 while (true) {
517 std::cout << "> " << std::flush;
518 std::getline(std::cin, input);
519 if (input == "exit") {
520 break;
521 }
522 // Split string by space
523 std::vector<std::string> arg_strs;
524 std::stringstream ss(input);
525 std::string arg;
526 while (ss >> arg) {
527 if (arg_strs.size() > 0 && arg_strs[arg_strs.size() - 1].starts_with("\"") && !arg_strs[arg_strs.size() - 1].ends_with("\"")) {
528 // Double quotes enclose strings that can contain spaces
529 arg_strs[arg_strs.size() - 1] += " " + arg;
530 if (arg.ends_with("\"")) {
531 // Remove the double quotes
532 arg_strs[arg_strs.size() - 1] = arg_strs[arg_strs.size() - 1].substr(1, arg_strs[arg_strs.size() - 1].size() - 2);
533 }
534 } else {
535 arg_strs.push_back(arg);
536 }
537 }
538 if (arg_strs.size() == 0) {
539 help_usage_interactive();
540 continue;
541 }
542 std::string mode = arg_strs[0];
543 if (std::string("completion").starts_with(mode)) {
544 mode = "completion";
545 } else if (std::string("passkey").starts_with(mode) && mode != "p") {
546 mode = "passkey";
547 } else if (std::string("perplexity").starts_with(mode) && mode != "p") {
548 mode = "perplexity";
549 } else if (std::string("interactive").starts_with(mode)) {
550 mode = "interactive";
551 } else {
552 help_usage_interactive();
553 continue;
554 }
555 std::vector<const char*> args;
556 for (size_t i = 1; i < arg_strs.size(); i++) {
557 args.push_back(arg_strs[i].c_str());
558 }
559 if (mode == "completion") {
560 CompletionArgs completion_args;
561 if (!completion_args.parse_args(args)) {
562 help_usage_interactive();
563 continue;
564 }
565 run_completion(session, completion_args.prompt, completion_args.num_steps, completion_args.temperature, completion_args.top_p);
566 } else if (mode == "passkey") {
567 PasskeyArgs passkey_args;
568 if (!passkey_args.parse_args(args)) {
569 help_usage_interactive();
570 continue;
571 }

Callers 1

mainFunction · 0.85

Calls 6

help_usage_interactiveFunction · 0.85
run_completionFunction · 0.85
run_passkeyFunction · 0.85
encode_promptFunction · 0.85
run_perplexityFunction · 0.85
parse_argsMethod · 0.45

Tested by

no test coverage detected