summary.cpp (1652B)
1 #include "../include/openai.hpp" 2 #include <iostream> 3 #include "../include/nlohmann/json.hpp" 4 #include "../include/researcher.hpp" 5 #include <fstream> 6 7 int main(int argc, char* argv[]) { 8 9 10 openai::start(); 11 openai::OpenAI connection = openai::OpenAI(); 12 13 std::string envVariable = "GROQ_API_KEY"; 14 std::string model = "moonshotai/kimi-k2-instruct-0905"; 15 std::string baseURL = "https://api.groq.com/openai/v1/"; 16 std::string priorRuns = ""; 17 int linkNum = 1; 18 19 connection.setToken(getenv(envVariable.c_str())); 20 connection.setBaseUrl(baseURL); 21 22 std::string filepath; 23 if(argc == 2){ 24 filepath = argv[1]; 25 } 26 else{ 27 std::cout << "Please specify file to read." << std::endl; 28 exit(-1); 29 } 30 31 Researcher summarizer = Researcher(); 32 summarizer.setSystemPrompt( 33 R"( 34 You are a highly capable AI assistant. Your mission is to consider the audio transcript below and summarize it with extreme precision. As much as possible, use direct quotes from the source to ensure your summary is faithful to the original piece. 35 )"); 36 37 38 std::ifstream t = std::ifstream(filepath); 39 std::string filecontent = ""; 40 std::string line; 41 while(t){ 42 std::getline(t, line); 43 filecontent += line; 44 } 45 46 int approxTokens = filecontent.size() / 4; 47 48 if (approxTokens > 128000){ 49 filecontent = filecontent.substr(0,128000 * 4); 50 } 51 52 t.close(); 53 54 nlohmann::json summaryJson = summarizer.sendUserMessage(&connection, model, filecontent); 55 std::string summary = summarizer.getMessageFromChat(summaryJson); 56 std::cout << summary << std::endl; 57 return 0; 58 59 }