MCPcopy Create free account
hub / github.com/Tiiny-AI/PowerInfer / read_user_input

Function read_user_input

smallthinker/tools/run/run.cpp:1027–1060  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1025}
1026
1027static int read_user_input(std::string & user_input) {
1028 static const char * prompt_prefix_env = std::getenv("LLAMA_PROMPT_PREFIX");
1029 static const char * prompt_prefix = prompt_prefix_env ? prompt_prefix_env : "> ";
1030#ifdef WIN32
1031 printf("\r" LOG_CLR_TO_EOL LOG_COL_DEFAULT "%s", prompt_prefix);
1032
1033 std::getline(std::cin, user_input);
1034 if (std::cin.eof()) {
1035 printf("\n");
1036 return 1;
1037 }
1038#else
1039 std::unique_ptr<char, decltype(&std::free)> line(const_cast<char *>(linenoise(prompt_prefix)), free);
1040 if (!line) {
1041 return 1;
1042 }
1043
1044 user_input = line.get();
1045#endif
1046
1047 if (user_input == "/bye") {
1048 return 1;
1049 }
1050
1051 if (user_input.empty()) {
1052 return 2;
1053 }
1054
1055#ifndef WIN32
1056 linenoiseHistoryAdd(line.get());
1057#endif
1058
1059 return 0; // Should have data in happy path
1060}
1061
1062// Function to generate a response based on the prompt
1063static int generate_response(LlamaData & llama_data, const std::string & prompt, std::string & response,

Callers 1

handle_user_inputFunction · 0.85

Calls 6

printfFunction · 0.85
linenoiseFunction · 0.85
linenoiseHistoryAddFunction · 0.85
eofMethod · 0.80
getMethod · 0.45
emptyMethod · 0.45

Tested by

no test coverage detected