Prompt Tools 0.3.2
Loading...
Searching...
No Matches
embed_base_class.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <string>
6
7namespace prompt
8{
9
17{
18public:
27
33 virtual ~EmbedBaseClass() = default;
34
45 virtual void initialize_embed_base(rclcpp::Node::SharedPtr node, std::string plugin_name = "EmbedBaseClass",
46 std::string api_key_name = "")
47 {
48 // initialize base class
49 initialize_rest_base(node, plugin_name, api_key_name);
50
51 // declare parameters only if not already declared (idempotent init)
52 if (!node_->has_parameter(plugin_name_ + ".rest.embedding_uri"))
53 {
54 node_->declare_parameter(plugin_name_ + ".rest.embedding_uri", "");
55 }
56
57 // get parameters from the parameter server
58 embed_uri_ = node_->get_parameter(plugin_name_ + ".rest.embedding_uri").as_string();
59
60 // log the parameters
61 RCLCPP_INFO(node_->get_logger(), "%s Embedding URI: %s", plugin_name_.c_str(), embed_uri_.c_str());
62 }
63
71 {
72 // verify and add required model options
74
75 // prepare request body
76 Poco::JSON::Object body_json = toJson(req);
77
78 // process the prompt
79 Poco::JSON::Object::Ptr object = process(body_json, embed_uri_);
80
81 // create prompt provider response container
82 prompt::EmbedResponse res = fromJson(object);
83
84 return res;
85 }
86
87protected:
97 virtual Poco::JSON::Object toJson(prompt::EmbedRequest& input) = 0;
98
108 virtual prompt::EmbedResponse fromJson(const Poco::JSON::Object::Ptr object) = 0;
109
113 std::string embed_uri_;
114};
115
116} // namespace prompt
rclcpp::Node::SharedPtr node_
Node shared pointer.
Definition base_class.hpp:105
std::string plugin_name_
Plugin name.
Definition base_class.hpp:112
EmbedBaseClass.
Definition embed_base_class.hpp:17
virtual Poco::JSON::Object toJson(prompt::EmbedRequest &input)=0
Convert a embed request to a JSON object.
virtual void initialize_embed_base(rclcpp::Node::SharedPtr node, std::string plugin_name="EmbedBaseClass", std::string api_key_name="")
Initialize the REST base class.
Definition embed_base_class.hpp:45
virtual ~EmbedBaseClass()=default
Destructor.
EmbedBaseClass()
Constructor.
Definition embed_base_class.hpp:24
virtual prompt::EmbedResponse fromJson(const Poco::JSON::Object::Ptr object)=0
Convert a JSON object to a embed response.
virtual prompt::EmbedResponse get_embeddings(prompt::EmbedRequest &req) override
get_embeddings sends a text to an embedding provider using REST
Definition embed_base_class.hpp:70
std::string embed_uri_
URI for embedding requests.
Definition embed_base_class.hpp:113
RestBaseClass.
Definition rest_base_class.hpp:31
Poco::JSON::Object::Ptr process(Poco::JSON::Object &body_json, std::string &uri)
Process the HTTP request and return the response as a JSON object.
Definition rest_base_class.hpp:170
std::vector< prompt::PromptOption > required_options_
Model options.
Definition rest_base_class.hpp:371
virtual void initialize_rest_base(rclcpp::Node::SharedPtr node, std::string plugin_name="RestBaseClass", std::string api_key_name="")
Initialize the REST base class.
Definition rest_base_class.hpp:59
Definition base_class.hpp:8
void ensure_model_options(rclcpp::Node::SharedPtr node, std::vector< prompt::PromptOption > &options, std::vector< prompt::PromptOption > &required_options)
Check and add required model options to the prompt options.
Definition prompt_options.hpp:149
Definition structs.hpp:46
std::vector< PromptOption > options
Definition structs.hpp:49
Definition structs.hpp:61