|
FP Perception 0.1.2
|
#include <rest_base.hpp>


Public Member Functions | |
| RestBase () | |
| Constructor. | |
| virtual | ~RestBase () |
| Destructor. | |
| virtual void | initialize_rest_base (const rclcpp::Node::SharedPtr &node, std::string plugin_name="RestBase", std::string api_key_name="") |
| Initialize the REST base class. | |
| virtual fp_perception::RESTResponse | call (const fp_perception::RESTRequest &req) |
| Request data from the REST API. | |
| virtual fp_perception::RESTResponse | call_audio (const fp_perception::RESTRequest &req) |
| Request audio data from the REST API. | |
| virtual fp_perception::RESTResponse | call_tts (const fp_perception::RESTRequest &req) |
Public Member Functions inherited from fp_perception::DriverBase | |
| virtual | ~DriverBase ()=default |
| virtual void | initialize (const rclcpp::Node::SharedPtr &node) |
| Initialize the driver. | |
| virtual void | deinitialize ()=0 |
| Deinitialize the driver. | |
| virtual std::string | getName () const |
| Get the name of the driver. | |
| virtual void | test () |
| Test the driver. | |
| void | check_directory (std::string folder_name) |
| Check if the test directory exists, create it if not. | |
| const std::filesystem::path | check_file (const std::string &file_name) |
Protected Member Functions | |
| void | apply_timeouts (CURL *curl) |
| void | record_rest_result (bool success, long http_code, const std::string &error) |
| virtual nlohmann::json | toJson (const fp_perception::RESTRequest &request)=0 |
| Convert a prompt request to a JSON object. | |
| virtual fp_perception::RESTResponse | fromJson (const nlohmann::json &object)=0 |
| Convert a JSON object to a fp_perception response. | |
Protected Member Functions inherited from fp_perception::DriverBase | |
| void | initialize_base (const rclcpp::Node::SharedPtr &node) |
| Initializer base driver in place of constructor due to plugin semantics. | |
| bool | diagnostics_enabled () const |
| void | enable_diagnostics (const std::string &hardware_id, const std::string &task_name, std::function< void(diagnostic_updater::DiagnosticStatusWrapper &)> task, std::chrono::milliseconds period=std::chrono::seconds(1)) |
| void | disable_diagnostics () |
Static Protected Member Functions | |
| static std::string | build_http_error_message (long http_code, const std::string &response_data) |
| static size_t | write_callback (void *contents, size_t size, size_t nmemb, std::string *userp) |
Protected Attributes | |
| std::string | plugin_name_ |
| std::string | uri_ |
| std::string | method_ |
| bool | ssl_verify_ |
| std::string | auth_type_ |
| std::string | api_key_ |
| long | timeout_sec_ { 60 } |
| long | connect_timeout_sec_ { 10 } |
| std::atomic< uint64_t > | rest_request_count_ { 0 } |
| std::atomic< uint64_t > | rest_failure_count_ { 0 } |
| std::atomic< bool > | last_rest_success_ { true } |
| std::atomic< long > | last_rest_http_code_ { 0 } |
| std::mutex | rest_status_mutex_ |
| std::string | last_rest_error_ |
Protected Attributes inherited from fp_perception::DriverBase | |
| rclcpp::Node::SharedPtr | node_ |
| ROS node for the driver. | |
| std::string | name_ |
| Name of the driver. | |
| std::mutex | buffer_mutex_ |
| Mutex to protect access to the driver data. | |
| std::condition_variable | buffer_cv_ |
| Condition variable to notify when new data is available. | |
| std::atomic< bool > | is_running_ { false } |
| Flag to indicate if the driver thread is running. | |
| bool | diagnostics_enabled_ { false } |
| Flag to enable standard ROS diagnostics publishing. | |
| std::unique_ptr< diagnostic_updater::Updater > | diagnostics_updater_ |
| rclcpp::TimerBase::SharedPtr | diagnostics_timer_ |
This class implements a base class for RESTful fp_perception plugins. It provides a common interface for sending requests and receiving responses.
|
inline |
Constructor.
Initializes the RestBase with default values.
|
inlinevirtual |
Destructor.
Cleans up resources used by the RestBase.
|
inlineprotected |
|
inlinestaticprotected |
|
inlinevirtual |
Request data from the REST API.
This method sends a RESTRequest to the REST API and returns the response.
| req | The REST request containing the prompt and options. |
| fp_perception_exception | if there is an error during the request. |
|
inlinevirtual |
Request audio data from the REST API.
This method sends an audio file to the REST API and returns the response.
| req | The REST request containing the audio file and options. |
| fp_perception_exception | if there is an error during the request. |
|
inlinevirtual |
|
protectedpure virtual |
Convert a JSON object to a fp_perception response.
This method converts a JSON object received from the fp_perception plugin into a fp_perception response. It extracts the relevant fields from the JSON object and returns a fp_perception response object.
| object | The JSON object to convert |
Implemented in fp_perception::OpenAIImageAnalysisDriver, fp_perception::OpenAISpeechDriver, fp_perception::OpenAIDriver, and fp_perception::SentimentDriver.
|
inlinevirtual |
Initialize the REST base class.
This method initializes the REST base class with parameters from the ROS parameter server.
| node | rclcpp::Node::SharedPtr ROS node |
| fp_perception_exception | if there is an error during initialization |
|
inlineprotected |
|
protectedpure virtual |
Convert a prompt request to a JSON object.
This method converts the fp_perception request to a JSON object that can be sent to the fp_perception plugin. It includes the prompt text and options for the JSON object.
| prompt | The fp_perception request to convert |
Implemented in fp_perception::OpenAIImageAnalysisDriver, fp_perception::OpenAISpeechDriver, fp_perception::OpenAIDriver, and fp_perception::SentimentDriver.
|
inlinestaticprotected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |
|
protected |