@@ -62,6 +62,7 @@ namespace xcpp
62
62
class ChatHistory
63
63
{
64
64
public:
65
+
65
66
static std::string chat (const std::string& model, const std::string& user, const std::string& cell)
66
67
{
67
68
return appendAndReadBack (model, user, " \" " + cell + " \" " );
@@ -80,8 +81,9 @@ namespace xcpp
80
81
81
82
private:
82
83
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
+ {
85
87
std::string chatHistoryFilePath = model + " _chat_history.txt" ;
86
88
std::ofstream out;
87
89
bool isEmpty = isFileEmpty (chatHistoryFilePath);
@@ -98,7 +100,7 @@ namespace xcpp
98
100
out << " , " ;
99
101
}
100
102
101
- if (model == " gemini" )
103
+ if (model == " gemini" )
102
104
{
103
105
out << " { \" role\" : \" " << user << R"( ", "parts": [ { "text": )" << serializedCell << " }]}\n " ;
104
106
}
@@ -114,10 +116,10 @@ namespace xcpp
114
116
115
117
static bool isFileEmpty (const std::string& filePath)
116
118
{
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
119
121
{
120
- return true ; // Consider non-existent files as empty
122
+ return true ; // Consider non-existent files as empty
121
123
}
122
124
return file.tellg () == 0 ;
123
125
}
@@ -219,7 +221,11 @@ namespace xcpp
219
221
return " " ;
220
222
}
221
223
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
+ );
223
229
224
230
return j[" candidates" ][0 ][" content" ][" parts" ][0 ][" text" ];
225
231
}
@@ -231,7 +237,8 @@ namespace xcpp
231
237
const std::string chatMessage = xcpp::ChatHistory::chat (" openai" , " user" , cell);
232
238
const std::string postData = R"( {
233
239
"model": "gpt-3.5-turbo-16k",
234
- "messages": [)" + chatMessage + R"( ],
240
+ "messages": [)" + chatMessage
241
+ + R"( ],
235
242
"temperature": 0.7
236
243
})" ;
237
244
std::string authHeader = " Authorization: Bearer " + key;
@@ -246,7 +253,11 @@ namespace xcpp
246
253
return " " ;
247
254
}
248
255
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
+ );
250
261
251
262
return j[" choices" ][0 ][" message" ][" content" ];
252
263
}
@@ -274,8 +285,8 @@ namespace xcpp
274
285
{
275
286
xcpp::APIKeyManager::saveApiKey (model, cell);
276
287
return ;
277
- }
278
-
288
+ }
289
+
279
290
if (tokens[2 ] == " --refresh" )
280
291
{
281
292
xcpp::ChatHistory::refresh (model);
0 commit comments