← index
libmx2/cmd/ollama_gen/mx2-ollama.hpp
Source: libmx2/cmd/ollama_gen/mx2-ollama.hpp
#ifndef __MX2_OLLAMA_HPP__
#define __MX2_OLLAMA_HPP__

#include <algorithm>
#include <cctype>
#include <curl/curl.h>
#include <fstream>
#include <iostream>
#include <regex>
#include <sstream>
#include <string>

namespace mx {

    struct ResponseData {
        std::string response;
        std::ostringstream shader_stream;
    };

    class ObjectRequestException : public std::exception {
      public:
        explicit ObjectRequestException(const std::string &message) : msg(message) {}
        virtual const char *what() const noexcept override {
            return msg.c_str();
        }

      private:
        std::string msg;
    };

    class ObjectRequest {
      public:
        explicit ObjectRequest(const std::string &host_ = "localhost", const std::string &model_ = "codellama:7b") : host(host_), model(model_) {}
        void setHost(const std::string &host_) {
            host = host_;
        }
        void setModel(const std::string &model_) {
            model = model_;
        }
        void setPrompt(const std::string &prompt_) {
            prompt = prompt_;
        }
        static std::string unescape(const std::string &input);
        std::string generateCode();
        static size_t WriteCallback(void *contents, size_t size, size_t nmemb, ResponseData *data);

      private:
        std::string host;
        std::string model;
        std::string filename;
        std::string prompt;
    };

} // namespace mx

#endif