Prompt Tools 0.3.2
Loading...
Searching...
No Matches
Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
prompt::PromptBaseClass Class Referenceabstract

PromptBaseClass. More...

#include <prompt_base_class.hpp>

Inheritance diagram for prompt::PromptBaseClass:
Inheritance graph
[legend]
Collaboration diagram for prompt::PromptBaseClass:
Collaboration graph
[legend]

Public Member Functions

 PromptBaseClass ()
 Constructor.
 
virtual ~PromptBaseClass ()=default
 Destructor.
 
virtual void initialize_prompt_base (rclcpp::Node::SharedPtr node, std::string plugin_name="PromptBaseClass", std::string api_key_name="")
 Initialize the REST base class.
 
virtual prompt::PromptResponse sendPrompt (prompt::PromptRequest &req)
 sendPrompt send a prompt to a prompt provider using REST
 
virtual prompt::PromptResponse sendConversation (prompt::PromptRequest &latest_request, std::vector< PromptDialogue > &conversation)
 sendConversation send a prompt with conversation history to a prompt provider using REST
 
- Public Member Functions inherited from prompt::RestBaseClass
 RestBaseClass ()
 Constructor.
 
virtual ~RestBaseClass ()=default
 Destructor.
 
virtual void initialize_rest_base (rclcpp::Node::SharedPtr node, std::string plugin_name="RestBaseClass", std::string api_key_name="")
 Initialize the REST base class.
 
- Public Member Functions inherited from prompt::BaseClass
 BaseClass ()=default
 
virtual ~BaseClass ()=default
 
virtual void initialize (rclcpp::Node::SharedPtr node)=0
 Initialize the prompt pligin.
 
virtual prompt::EmbedResponse get_embeddings (prompt::EmbedRequest &req)
 get_embeddings sends a text to an embedding provider using REST
 
virtual prompt::TokenResponse get_tokens (prompt::TokenRequest &req)
 get_tokens sends a text to a token provider
 

Protected Member Functions

virtual Poco::JSON::Object toJson (prompt::PromptRequest &prompt)=0
 Convert a prompt request to a JSON object.
 
virtual Poco::JSON::Object toJsonConversation (prompt::PromptRequest &latest_request, std::vector< PromptDialogue > &conversation)=0
 Convert a prompt request with conversation history to a JSON object.
 
virtual prompt::PromptResponse fromJson (const Poco::JSON::Object::Ptr object)=0
 Convert a JSON object to a prompt response.
 
virtual prompt::PromptResponse fromJsonConversation (const Poco::JSON::Object::Ptr object)=0
 Convert a JSON object to a prompt response with conversation history.
 
- Protected Member Functions inherited from prompt::RestBaseClass
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.
 
virtual const Poco::JSON::Object handle_options (std::vector< prompt::PromptOption > &options)
 Process options from the prompt request.
 
- Protected Member Functions inherited from prompt::BaseClass
virtual void initialize_base (rclcpp::Node::SharedPtr node, std::string plugin_name="BaseClass")
 Initialize the prompt base class.
 

Protected Attributes

std::string uri_
 URI for single prompt requests.
 
std::string chat_uri_
 URI for chat/conversation requests.
 
- Protected Attributes inherited from prompt::RestBaseClass
std::string method_
 
bool ssl_verify_
 
std::string auth_type_
 
std::string api_key_
 API key.
 
std::vector< prompt::PromptOptionrequired_options_
 Model options.
 
- Protected Attributes inherited from prompt::BaseClass
rclcpp::Node::SharedPtr node_
 Node shared pointer.
 
std::string plugin_name_
 Plugin name.
 

Additional Inherited Members

- Static Protected Member Functions inherited from prompt::RestBaseClass
static std::string extract_error_description (const std::string &response_body)
 

Detailed Description

PromptBaseClass.

This class implements a base class for RESTful prompt plugins. It provides a common interface for sending prompts and receiving responses

Constructor & Destructor Documentation

◆ PromptBaseClass()

prompt::PromptBaseClass::PromptBaseClass ( )
inline

Constructor.

Initializes the RestBaseClass with default values.

◆ ~PromptBaseClass()

virtual prompt::PromptBaseClass::~PromptBaseClass ( )
virtualdefault

Destructor.

Cleans up resources used by the RestBaseClass.

Member Function Documentation

◆ fromJson()

virtual prompt::PromptResponse prompt::PromptBaseClass::fromJson ( const Poco::JSON::Object::Ptr  object)
protectedpure virtual

Convert a JSON object to a prompt response.

This method converts a JSON object received from the prompt plugin into a prompt response. It extracts the relevant fields from the JSON object and returns a PromptResponse object.

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

Implemented in prompt::OllamaProvider, and prompt::OpenAIProvider.

◆ fromJsonConversation()

virtual prompt::PromptResponse prompt::PromptBaseClass::fromJsonConversation ( const Poco::JSON::Object::Ptr  object)
protectedpure virtual

Convert a JSON object to a prompt response with conversation history.

This method converts a JSON object received from the prompt plugin into a prompt response, taking into account the conversation history. It extracts the relevant fields from the JSON object and returns a PromptResponse object.

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

Implemented in prompt::OllamaProvider, and prompt::OpenAIProvider.

◆ initialize_prompt_base()

virtual void prompt::PromptBaseClass::initialize_prompt_base ( rclcpp::Node::SharedPtr  node,
std::string  plugin_name = "PromptBaseClass",
std::string  api_key_name = "" 
)
inlinevirtual

Initialize the REST base class.

This method initializes the REST base class with parameters from the ROS parameter server.

Parameters
noderclcpp::Node::SharedPtr ROS node
plugin_namestd::string Name of the plugin, used for parameter names
api_key_namestd::string Name of the API key parameter, if different from the default
Exceptions
prompt::PromptExceptionif there is an error during initialization

◆ sendConversation()

virtual prompt::PromptResponse prompt::PromptBaseClass::sendConversation ( prompt::PromptRequest latest_request,
std::vector< PromptDialogue > &  conversation 
)
inlinevirtual

sendConversation send a prompt with conversation history to a prompt provider using REST

Typical providers offer stream based responses which is also supported

Parameters
latest_requestThe prompt request containing the prompt and options.
conversationThe conversation history for context.
Returns
const PromptResponse

Reimplemented from prompt::BaseClass.

◆ sendPrompt()

virtual prompt::PromptResponse prompt::PromptBaseClass::sendPrompt ( prompt::PromptRequest req)
inlinevirtual

sendPrompt send a prompt to a prompt provider using REST

Typical providers offer stream based responses which is also supported

Parameters
reqThe prompt request containing the prompt and options.
Returns
const PromptResponse

Reimplemented from prompt::BaseClass.

◆ toJson()

virtual Poco::JSON::Object prompt::PromptBaseClass::toJson ( prompt::PromptRequest prompt)
protectedpure virtual

Convert a prompt request to a JSON object.

This method converts the prompt request to a JSON object that can be sent to the prompt plugin. It includes the prompt text and options in the JSON object.

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

Implemented in prompt::OllamaProvider, and prompt::OpenAIProvider.

◆ toJsonConversation()

virtual Poco::JSON::Object prompt::PromptBaseClass::toJsonConversation ( prompt::PromptRequest latest_request,
std::vector< PromptDialogue > &  conversation 
)
protectedpure virtual

Convert a prompt request with conversation history to a JSON object.

This method converts the prompt request and conversation history to a JSON object that can be sent to the prompt plugin. It includes the prompt text, options, and conversation history in the JSON object.

Parameters
latest_requestThe latest prompt request to convert
conversationThe conversation history to include
Returns
A JSON object representing the prompt request with conversation history

Implemented in prompt::OllamaProvider, and prompt::OpenAIProvider.

Member Data Documentation

◆ chat_uri_

std::string prompt::PromptBaseClass::chat_uri_
protected

URI for chat/conversation requests.

◆ uri_

std::string prompt::PromptBaseClass::uri_
protected

URI for single prompt requests.


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