49 lines
1.4 KiB
C
49 lines
1.4 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.";
|
|||
|
|
|||
|
// 类型映射表,用于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 = {"response"};
|
|||
|
|
|||
|
CreateChatCompletion(const std::string& response_type) : BaseTool(name_, description_, json::object()), response_type(response_type) {
|
|||
|
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
|