3e99b37683
- Added base_url and model fields to HarnessConfig in json_types.hpp - Removed base_url and model from OllamaConfig in ollama_client.hpp - Updated OllamaClient constructor to accept base_url and model as separate parameters - Updated main.cpp to use HarnessConfig for base_url and model - Updated agent_tool.cpp to use new OllamaClient constructor - Added test_harness_config.sh to verify the new config fields - Updated README.md to document the config fields
41 lines
1.4 KiB
C++
41 lines
1.4 KiB
C++
#pragma once
|
|
#include "client.hpp"
|
|
#include <nlohmann/json.hpp>
|
|
#include <string>
|
|
#include <vector>
|
|
#include <iostream>
|
|
#include <optional>
|
|
|
|
using http_req_cb_t = std::function<std::string(std::string const& old, std::string const& new_str)>;
|
|
|
|
struct OllamaConfig {
|
|
std::string auth_token = "";
|
|
int timeout_s = 60*10;
|
|
};
|
|
|
|
class OllamaClient : public Client {
|
|
public:
|
|
explicit OllamaClient(std::string base_url, std::string model, OllamaConfig config = {});
|
|
~OllamaClient() override;
|
|
|
|
std::expected<Message, std::string> chat(const std::vector<Message>& messages,
|
|
const std::vector<Tool>& tools) const override;
|
|
|
|
std::expected<std::vector<std::string>, std::string> list_models() const override;
|
|
|
|
private:
|
|
std::string base_url_;
|
|
std::string model_;
|
|
OllamaConfig config_;
|
|
nlohmann::json build_body(const std::vector<Message>& messages,
|
|
const std::vector<Tool>& tools) const;
|
|
static size_t write_cb(char* ptr, size_t size, size_t nmemb, void* userdata);
|
|
std::expected<std::string, std::string> http_request(const std::string& full_url,
|
|
const std::string& method,
|
|
const std::string& body = "",
|
|
std::optional<http_req_cb_t> cb = std::nullopt) const;
|
|
};
|
|
|
|
|
|
void print_history(std::ostream& out, const nlohmann::json& data, bool colored = true);
|