@@ -88,7 +88,7 @@ void remove_invalid_prompt_char(char& c)
8888 c = ' ' ;
8989}
9090
91- static void send_ollama_request (const std::string& prompt, std::string& response)
91+ static bool send_ollama_request (const std::string& prompt, std::string& response)
9292{
9393 std::string command = " curl -X POST -H \" Content-Type: application/json\" -v localhost:11434/api/generate -d '" ;
9494 command += " {\" model\" : \" gemma3:1b\" ,\" prompt\" :\" " ;
@@ -100,13 +100,16 @@ static void send_ollama_request(const std::string& prompt, std::string& response
100100 LOG_d_CMD (command);
101101
102102 int code = ::system (command.c_str ());
103- if (code == -1 ) {
103+ LOG_w_CMD (code);
104+ if (code != 0 ) {
104105 LOG_E_SERVER (" error sending API LLama request" , command);
106+ return false ;
105107 }
106108
107109 ::usleep (BOT_PROCESS_TIME_MS);
108110 std::ifstream file (" llama_response.txt" );
109111 response.assign ((std::istreambuf_iterator<char >(file)), std::istreambuf_iterator<char >());
112+ return true ;
110113}
111114
112115bool Bot::_connect_to_server (Server& s, TcpSocket& so)
@@ -194,7 +197,8 @@ void Bot::execute(Server& s, Client& c)
194197 LOG_DV_CMD (prompt);
195198
196199 std::string response = " \"\" " ;
197- send_ollama_request (prompt, response);
200+ if (!send_ollama_request (prompt, response))
201+ response = " \" Bot is under maintenance\" " ;
198202
199203 if (!_connect_to_server (s, _socket))
200204 return ;
0 commit comments