2025-03-16 17:17:01 +08:00
|
|
|
|
#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;
|
2025-03-16 22:56:03 +08:00
|
|
|
|
std::vector<std::string> required;
|
2025-03-16 17:17:01 +08:00
|
|
|
|
|
2025-03-16 22:56:03 +08:00
|
|
|
|
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) {
|
2025-03-16 17:17:01 +08:00
|
|
|
|
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
|