31 virtual void initialize(rclcpp::Node::SharedPtr node)
override
53 std::string model_name;
55 for (
const auto& option : input.
options)
57 if (option.key ==
"model")
59 model_name = option.value;
64 if (model_name==
"O200K_BASE")
66 encoder_ = GptEncoding::get_encoding(LanguageModel::O200K_BASE);
68 else if ((model_name==
"CL100K_BASE"))
70 encoder_ = GptEncoding::get_encoding(LanguageModel::CL100K_BASE);
72 else if (model_name==
"R50K_BASE")
74 encoder_ = GptEncoding::get_encoding(LanguageModel::R50K_BASE);
76 else if (model_name==
"P50K_BASE")
78 encoder_ = GptEncoding::get_encoding(LanguageModel::P50K_BASE);
80 else if (model_name==
"P50K_EDIT")
82 encoder_ = GptEncoding::get_encoding(LanguageModel::P50K_EDIT);
88 res.
error =
"OpenAITokenize: Unsupported model for tokenization: " + model_name;
90 RCLCPP_ERROR(
node_->get_logger(), res.
error.c_str());
91 throw std::runtime_error(res.
error);
rclcpp::Node::SharedPtr node_
Node shared pointer.
Definition base_class.hpp:105
OpenAITokenize.
Definition openai_tokenize.hpp:15
virtual prompt::TokenResponse process(prompt::TokenRequest &input) override
Convert a tokenize request to a JSON object.
Definition openai_tokenize.hpp:47
OpenAITokenize()
Construct a new OpenAI Tokenize Provider object.
Definition openai_tokenize.hpp:20
virtual void initialize(rclcpp::Node::SharedPtr node) override
Initialize the OpenAITokenize.
Definition openai_tokenize.hpp:31
std::shared_ptr< GptEncoding > encoder_
Definition openai_tokenize.hpp:110
TokenizeBaseClass.
Definition tokenize_base_class.hpp:16
virtual void initialize_tokenize_base(rclcpp::Node::SharedPtr node, std::string plugin_name="TokenizeBaseClass")
Initialize the REST base class.
Definition tokenize_base_class.hpp:44
Definition base_class.hpp:8
Definition structs.hpp:71
std::string text
Definition structs.hpp:72
std::vector< PromptOption > options
Definition structs.hpp:76
bool encode
Definition structs.hpp:74
std::vector< int > tokens
Definition structs.hpp:73
Definition structs.hpp:80
std::vector< int > tokens
Definition structs.hpp:81
bool success
Definition structs.hpp:83
std::string error
Definition structs.hpp:84
std::string text
Definition structs.hpp:82