File tree 1 file changed +54
-5
lines changed 1 file changed +54
-5
lines changed Original file line number Diff line number Diff line change @@ -279,6 +279,52 @@ namespace xcpp
279
279
}
280
280
};
281
281
282
+ std::string escape_special_cases (const std::string& input)
283
+ {
284
+ std::string escaped;
285
+ for (char c : input)
286
+ {
287
+ switch (c)
288
+ {
289
+ case ' \\ ' :
290
+ escaped += " \\\\ " ;
291
+ break ;
292
+ case ' \" ' :
293
+ escaped += " \\\" " ;
294
+ break ;
295
+ case ' \n ' :
296
+ escaped += " \\ n" ;
297
+ break ;
298
+ case ' \t ' :
299
+ escaped += " \\ t" ;
300
+ break ;
301
+ case ' \r ' :
302
+ escaped += " \\ r" ;
303
+ break ;
304
+ case ' \b ' :
305
+ escaped += " \\ b" ;
306
+ break ;
307
+ case ' \f ' :
308
+ escaped += " \\ f" ;
309
+ break ;
310
+ default :
311
+ if (c < 0x20 || c > 0x7E )
312
+ {
313
+ // Escape non-printable ASCII characters and non-ASCII characters
314
+ char buffer[7 ];
315
+ snprintf (buffer, sizeof (buffer), " \\ u%04x" , c & 0xFFFF );
316
+ escaped += buffer;
317
+ }
318
+ else
319
+ {
320
+ escaped += c;
321
+ }
322
+ break ;
323
+ }
324
+ }
325
+ return escaped;
326
+ }
327
+
282
328
std::string gemini (const std::string& cell, const std::string& key)
283
329
{
284
330
curl_helper curl_helper;
@@ -369,8 +415,8 @@ namespace xcpp
369
415
}
370
416
371
417
const std::string post_data = R"( {
372
- "model": [ )" + model
373
- + R"( ] ,
418
+ "model": " )" + model
419
+ + R"( " ,
374
420
"messages": [)" + chat_message
375
421
+ R"( ],
376
422
"temperature": 0.7
@@ -453,18 +499,21 @@ namespace xcpp
453
499
}
454
500
}
455
501
502
+
503
+ const std::string prompt = escape_special_cases (cell);
504
+
456
505
std::string response;
457
506
if (model == " gemini" )
458
507
{
459
- response = gemini (cell , key);
508
+ response = gemini (prompt , key);
460
509
}
461
510
else if (model == " openai" )
462
511
{
463
- response = openai (cell , key);
512
+ response = openai (prompt , key);
464
513
}
465
514
else if (model == " ollama" )
466
515
{
467
- response = ollama (cell );
516
+ response = ollama (prompt );
468
517
}
469
518
470
519
std::cout << response;
You can’t perform that action at this time.
0 commit comments