-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cpp
More file actions
61 lines (46 loc) · 1.57 KB
/
Copy pathMain.cpp
File metadata and controls
61 lines (46 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "Capturer.h"
#include "Network.h"
#include "nlohmann/json.hpp"
#include <string>
#include <fstream>
#include <iostream>
#include <curl/curl.h>
using json = nlohmann::json;
int main() {
const std::string ConfigPath = "./config.json";
std::ifstream ConfigFile(ConfigPath);
if (!ConfigFile.is_open()) {
std::cout << "Open file failed: " << "./config.json" << std::endl;
return 1;
}
json Config;
ConfigFile >> Config;
ConfigFile.close();
const std::string ImagePath = Config["ImagePath"];
const std::string Apikey = Config["ApiKey"];
const std::string SystemPrompt = Config["SystemPrompt"];
const std::string UserPrompt = Config["UserPrompt"];
const std::string Model = Config["Model"];
const std::string OutputPath = Config["OutputPath"];
std::cout << "======== Start capture screen ========" << std::endl;
Capturer::Capture(ImagePath);
curl_global_init(CURL_GLOBAL_ALL);
std::string UploadImageRes;
Network::UploadImage(ImagePath, Apikey, UploadImageRes);
std::cout << "UploadImageRes: " << UploadImageRes << std::endl;
json ImageRes = json::parse(UploadImageRes);
std::string ImageId = ImageRes["id"];
std::string Body = Network::BuildBody(Model, ImageId, SystemPrompt, UserPrompt);
std::cout << Body << std::endl;
std::string OutputText;
Network::Request(Apikey, Body, OutputText);
curl_global_cleanup();
std::cout << "Response Text: " << OutputText << std::endl;
std::ofstream OutputFile(OutputPath);
if (!OutputFile.is_open()) {
std::cout << "Open file failed: " << OutputPath << std::endl;
return 1;
}
OutputFile << OutputText;
return 0;
}