humanus.cpp/tool/create_chat_completion.h

49 lines
1.5 KiB
C++

#ifndef HUMANUS_TOOL_CREATE_CHAT_COMPLETION_H
#define HUMANUS_TOOL_CREATE_CHAT_COMPLETION_H
#include "base.h"
#include <unordered_map>
#include <stdexcept>
#include <any>
#include <variant>
#include <type_traits>
namespace humanus {
struct CreateChatCompletion : BaseTool {
inline static const std::string name_ = "create_chat_completion";
inline static const std::string description_ = "Creates a structured completion with specified output formatting.";
// Type mapping table, used for JSON schema
inline static std::unordered_map<std::string, std::string> type_mapping = {
{"string", "string"},
{"int", "integer"},
{"float", "number"},
{"double", "number"},
{"bool", "boolean"},
{"object", "object"},
{"array", "array"}
};
std::string response_type;
std::vector<std::string> required;
CreateChatCompletion(const std::string& response_type = "string", const std::vector<std::string>& required = {"response"}) : BaseTool(name_, description_, json::object()), response_type(response_type), required(required) {
parameters = _build_parameters();
}
json _build_parameters() const;
json _create_type_schema(const std::string& type_hint) const;
json _get_type_info(const std::string& type_hint) const;
json _create_union_schema(const std::vector<std::string>& types) const;
ToolResult execute(const json& args) override;
};
}
#endif // HUMANUS_TOOL_CREATE_CHAT_COMPLETION_H