| 1025 | } |
| 1026 | |
| 1027 | static 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 |
| 1063 | static int generate_response(LlamaData & llama_data, const std::string & prompt, std::string & response, |
no test coverage detected