FP Perception 0.1.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
fp_perception::OpenAIDriver Class Reference

#include <openai_driver.hpp>

Inheritance diagram for fp_perception::OpenAIDriver:
Inheritance graph
[legend]
Collaboration diagram for fp_perception::OpenAIDriver:
Collaboration graph
[legend]

Public Member Functions

 OpenAIDriver ()
 Construct a new Prompt Tools Transcribe Driver object.
 
 ~OpenAIDriver () override
 Destroy the Prompt Tools Transcribe Driver object.
 
void initialize (const rclcpp::Node::SharedPtr &node) override
 Initialize the driver.
 
void deinitialize () override
 Deinitialize the driver.
 
transcription_result transcribe (const transcription_request &request_data) override
 Set data to the driver.
 
void test () override
 Test method for the driver.
 
- Public Member Functions inherited from fp_perception::RestBase
 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 std::string getName () const
 Get the name of 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

virtual nlohmann::json toJson (const fp_perception::RESTRequest &request)
 Convert a prompt request to a JSON object.
 
virtual fp_perception::RESTResponse fromJson (const nlohmann::json &object)
 Convert a JSON object to a fp_perception response.
 
void produce_diagnostics (diagnostic_updater::DiagnosticStatusWrapper &status)
 
- Protected Member Functions inherited from fp_perception::RestBase
void apply_timeouts (CURL *curl)
 
void record_rest_result (bool success, long http_code, const std::string &error)
 
- 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 ()
 

Protected Attributes

fp_perception::RESTResponse response_
 
transcription_result last_result_
 
std::string model_name_
 
std::string test_file_path_
 
- Protected Attributes inherited from fp_perception::RestBase
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_
 

Additional Inherited Members

- Static Protected Member Functions inherited from fp_perception::RestBase
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)
 

Constructor & Destructor Documentation

◆ OpenAIDriver()

fp_perception::OpenAIDriver::OpenAIDriver ( )
inline

Construct a new Prompt Tools Transcribe Driver object.

◆ ~OpenAIDriver()

fp_perception::OpenAIDriver::~OpenAIDriver ( )
inlineoverride

Destroy the Prompt Tools Transcribe Driver object.

Member Function Documentation

◆ deinitialize()

void fp_perception::OpenAIDriver::deinitialize ( )
inlineoverridevirtual

Deinitialize the driver.

This is required by DriverBase. For this driver, deinitialization primarily means releasing references to the ROS node and clearing cached response state.

Implements fp_perception::DriverBase.

◆ fromJson()

virtual fp_perception::RESTResponse fp_perception::OpenAIDriver::fromJson ( const nlohmann::json &  object)
inlineprotectedvirtual

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.

Parameters
objectThe JSON object to convert
Returns
A fp_perception response object containing the response data

Implements fp_perception::RestBase.

◆ initialize()

void fp_perception::OpenAIDriver::initialize ( const rclcpp::Node::SharedPtr &  node)
inlineoverridevirtual

Initialize the driver.

This function should be overridden in derived classes to provide specific initialization.

Parameters
nodeShared pointer to the ROS node

Reimplemented from fp_perception::DriverBase.

◆ produce_diagnostics()

void fp_perception::OpenAIDriver::produce_diagnostics ( diagnostic_updater::DiagnosticStatusWrapper &  status)
inlineprotected

◆ test()

void fp_perception::OpenAIDriver::test ( )
inlineoverridevirtual

Test method for the driver.

This function can be overridden in derived classes to implement specific test logic.

Reimplemented from fp_perception::DriverBase.

◆ toJson()

virtual nlohmann::json fp_perception::OpenAIDriver::toJson ( const fp_perception::RESTRequest request)
inlineprotectedvirtual

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.

Parameters
promptThe fp_perception request to convert
Returns
A JSON object representing the prompt request

Implements fp_perception::RestBase.

◆ transcribe()

transcription_result fp_perception::OpenAIDriver::transcribe ( const transcription_request request_data)
inlineoverridevirtual

Set data to the driver.

This function sends the latest audio data to the transcription service. It expects the input to be a vector of audio chunks in the form of fp_perception::audio_data.

Parameters
inputThe latest data from the driver.

Implements fp_perception::TranscriptionDriver.

Member Data Documentation

◆ last_result_

transcription_result fp_perception::OpenAIDriver::last_result_
protected

◆ model_name_

std::string fp_perception::OpenAIDriver::model_name_
protected

◆ response_

fp_perception::RESTResponse fp_perception::OpenAIDriver::response_
protected

◆ test_file_path_

std::string fp_perception::OpenAIDriver::test_file_path_
protected

The documentation for this class was generated from the following file: