@@ -62,6 +62,7 @@ namespace xcpp
6262 class ChatHistory
6363 {
6464 public:
65+
6566 static std::string chat (const std::string& model, const std::string& user, const std::string& cell)
6667 {
6768 return appendAndReadBack (model, user, " \" " + cell + " \" " );
@@ -80,8 +81,9 @@ namespace xcpp
8081
8182 private:
8283
83- static std::string appendAndReadBack (const std::string& model, const std::string& user, const std::string& serializedCell)
84- {
84+ static std::string
85+ appendAndReadBack (const std::string& model, const std::string& user, const std::string& serializedCell)
86+ {
8587 std::string chatHistoryFilePath = model + " _chat_history.txt" ;
8688 std::ofstream out;
8789 bool isEmpty = isFileEmpty (chatHistoryFilePath);
@@ -98,7 +100,7 @@ namespace xcpp
98100 out << " , " ;
99101 }
100102
101- if (model == " gemini" )
103+ if (model == " gemini" )
102104 {
103105 out << " { \" role\" : \" " << user << R"( ", "parts": [ { "text": )" << serializedCell << " }]}\n " ;
104106 }
@@ -114,10 +116,10 @@ namespace xcpp
114116
115117 static bool isFileEmpty (const std::string& filePath)
116118 {
117- std::ifstream file (filePath, std::ios::ate); // Open the file at the end
118- if (!file) // If the file cannot be opened, it might not exist
119+ std::ifstream file (filePath, std::ios::ate); // Open the file at the end
120+ if (!file) // If the file cannot be opened, it might not exist
119121 {
120- return true ; // Consider non-existent files as empty
122+ return true ; // Consider non-existent files as empty
121123 }
122124 return file.tellg () == 0 ;
123125 }
@@ -219,7 +221,11 @@ namespace xcpp
219221 return " " ;
220222 }
221223
222- const std::string chat = xcpp::ChatHistory::chat (" gemini" , " model" , j[" candidates" ][0 ][" content" ][" parts" ][0 ][" text" ]);
224+ const std::string chat = xcpp::ChatHistory::chat (
225+ " gemini" ,
226+ " model" ,
227+ j[" candidates" ][0 ][" content" ][" parts" ][0 ][" text" ]
228+ );
223229
224230 return j[" candidates" ][0 ][" content" ][" parts" ][0 ][" text" ];
225231 }
@@ -231,7 +237,8 @@ namespace xcpp
231237 const std::string chatMessage = xcpp::ChatHistory::chat (" openai" , " user" , cell);
232238 const std::string postData = R"( {
233239 "model": "gpt-3.5-turbo-16k",
234- "messages": [)" + chatMessage + R"( ],
240+ "messages": [)" + chatMessage
241+ + R"( ],
235242 "temperature": 0.7
236243 })" ;
237244 std::string authHeader = " Authorization: Bearer " + key;
@@ -246,7 +253,11 @@ namespace xcpp
246253 return " " ;
247254 }
248255
249- const std::string chat = xcpp::ChatHistory::chat (" openai" , " assistant" , j[" choices" ][0 ][" message" ][" content" ]);
256+ const std::string chat = xcpp::ChatHistory::chat (
257+ " openai" ,
258+ " assistant" ,
259+ j[" choices" ][0 ][" message" ][" content" ]
260+ );
250261
251262 return j[" choices" ][0 ][" message" ][" content" ];
252263 }
@@ -274,8 +285,8 @@ namespace xcpp
274285 {
275286 xcpp::APIKeyManager::saveApiKey (model, cell);
276287 return ;
277- }
278-
288+ }
289+
279290 if (tokens[2 ] == " --refresh" )
280291 {
281292 xcpp::ChatHistory::refresh (model);
0 commit comments