humanus.cpp/tool/create_chat_completion.h

49 lines
1.5 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

#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.";
// 类型映射表用于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