haiku-dumber/Conversation.h

88 lines
2.2 KiB
C
Raw Permalink Normal View History

2025-05-07 06:31:50 -03:00
// Conversation.h
#pragma once
#include <Handler.h>
#include <String.h>
#include <memory.h>
#include <iostream>
#include <ranges>
2025-05-07 06:31:50 -03:00
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <regex>
2025-05-07 06:31:50 -03:00
//NEED THIS IN MAKE FILE TO USE PRIVATE HEADERS
//CXXFLAGS = -std=c++17 -Wall -I/boot/system/develop/headers/private
//Build works but Genio doesn't see class definitions unless I use full path ?
#include "/boot/system/develop/headers/private/netservices2/NetServicesDefs.h"
#include "/boot/system/develop/headers/private/netservices2/HttpSession.h"
#include "/boot/system/develop/headers/private/netservices2/HttpRequest.h"
#include "/boot/system/develop/headers/private/netservices2/HttpResult.h"
#include "/boot/system/develop/headers/private/netservices2/HttpFields.h"
#include "/boot/system/develop/headers/private/netservices2/ErrorsExt.h"
//From private headers !
//#include <NetServicesDefs.h>
//#include <HttpSession.h>
//#include <HttpSession.h>
//#include <HttpRequest.h>
//#include <HttpResult.h>
//#include <ErrorsExt.h>
static const uint32 kSendReply = 'krpl';
2025-05-08 01:11:46 -03:00
static const uint32 kModelsReceived = 'mdls';
static const uint32 kClearHistory = 'clrh';
2025-05-07 06:31:50 -03:00
#include "include/json.hpp"
using json = nlohmann::json;
using namespace BPrivate::Network;
using namespace BPrivate::Network;
class Conversation : public BHandler {
public:
2025-05-07 19:26:56 -03:00
bool validKey = false;
2025-05-07 06:31:50 -03:00
Conversation(BHandler* replyTo);
virtual ~Conversation() ;
virtual void MessageReceived(BMessage *msg);
std::vector<std::string> FilterTextModels(const json& modelsJson);
void ask(const std::string& prompt);
2025-05-08 01:11:46 -03:00
void setModel(const std::string& prompt);
void loadModels();
void PrintAsJsonArray(const std::vector<std::string>& models) ;
2025-05-08 01:11:46 -03:00
void ClearHistory();
std::string buildHistoryInfoLine();
2025-05-08 01:11:46 -03:00
private:
2025-05-07 19:26:56 -03:00
2025-05-08 01:11:46 -03:00
std::string buildBearerKey();
std::vector<json> _messageHistory;
2025-05-07 06:56:46 -03:00
void sendReply(BMessage message);
2025-05-07 06:31:50 -03:00
BHandler* replyTarget;
BString ReadOpenAIKey();
BString _apiKey;
BHttpSession _sharedSession = BHttpSession ();
std::optional<BHttpResult> _lastResult;
2025-05-08 01:11:46 -03:00
std::string _activeModel = "gpt-4o";
2025-05-07 06:31:50 -03:00
};