information-retrieval

Exploration of information retrieval topics
git clone git://git.laack.co/information-retrieval.git
Log | Files | Refs

main.cpp (2623B)


      1 #include "../include/openai.hpp"
      2 #include <iostream>
      3 #include "../include/nlohmann/json.hpp"
      4 #include "../include/researcher.hpp"
      5 
      6 int main(int argc, char* argv[]) {
      7 
      8 
      9     openai::start();
     10     openai::OpenAI connection = openai::OpenAI();
     11 
     12     std::string envVariable = "GROQ_API_KEY";
     13     std::string model = "moonshotai/kimi-k2-instruct-0905";
     14     std::string baseURL = "https://api.groq.com/openai/v1/";
     15     std::string priorRuns = "";
     16     int linkNum = 1;
     17 
     18     connection.setToken(getenv(envVariable.c_str()));
     19     connection.setBaseUrl(baseURL);
     20 
     21     std::string chatMessage;
     22     if(argc == 2){
     23         chatMessage = argv[1];
     24     }
     25     else{
     26         std::getline(std::cin, chatMessage);
     27     }
     28 
     29     Researcher summarizer = Researcher();
     30     summarizer.setSystemPrompt(
     31 R"(
     32 You are a highly capable AI assistant. Your mission is to consider the authoratative information below and answer the user's question.
     33 
     34 )");
     35 
     36 
     37     Researcher researcher = Researcher();
     38     researcher.setSystemPrompt(
     39 R"(
     40 You are a research assistant that ONLY calls tools. You MUST NEVER generate summaries or explanations yourself.
     41 
     42 1. **Web Search:** When information is needed, output Search_web("query"). Prioritize reliable sources. If initial results are irrelevant, refine the query (Search_web("refined query")). Only refine a maximum of three times.
     43 
     44 2. **Webpage Download:** If a search result snippet is promising, but is cut off or otherwise suggests that the full page might contain the answer, output Download_webpage("URL"). Extract relevant information from the downloaded page.
     45 
     46 3. **Summary Generation:** After gathering enough information for the lead researcher to generate a summary, output Done().
     47 
     48 Remember: Search_web("query"), Download_webpage("URL"), Done(""). Use tools judiciously.
     49     )");
     50 
     51     std::string current = chatMessage;
     52     for(int i = 0 ; i < 10; ++i){
     53 
     54         nlohmann::json response = researcher.sendUserMessage(&connection, model, current);
     55         current = "";
     56 
     57         std::string message = researcher.getMessageFromChat(response);
     58         std::cout << message << std::endl;
     59 
     60         current = researcher.executeTool(message);
     61 
     62         if (current == "DONE"){
     63             break;
     64         }
     65     }
     66 
     67     std::string docs = researcher.getDocs(); 
     68     nlohmann::json summaryJson = summarizer.sendUserMessage(&connection, model, docs + "\n User Question:" + chatMessage);
     69     std::string summary = summarizer.getMessageFromChat(summaryJson);
     70 
     71     std::cout << "\nQUESTION:" << chatMessage << std::endl;
     72 
     73     std::cout << "\nANSWER:\n" << std::endl;
     74 
     75     std::cout << summary << std::endl;
     76     return 0;
     77 
     78 }