YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
GPTDevice_ParamsParser.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: LGPL-2.1-or-later
4 */
5
6
7// Generated by yarpDeviceParamParserGenerator (2.0)
8// This is an automatically generated file. Please do not edit it.
9// It will be re-generated if the cmake flag ALLOW_DEVICE_PARAM_PARSER_GERNERATION is ON.
10
11// Generated on: Tue Sep 2 16:54:08 2025
12
13
15#include <yarp/os/LogStream.h>
16#include <yarp/os/Value.h>
17
18namespace {
19 YARP_LOG_COMPONENT(GPTDeviceParamsCOMPONENT, "yarp.device.GPTDevice")
20}
21
22
26
27
28std::vector<std::string> GPTDevice_ParamsParser::getListOfParams() const
29{
30 std::vector<std::string> params;
31 params.push_back("api_version");
32 params.push_back("prompt_file");
33 params.push_back("prompt_context");
34 params.push_back("function_file");
35 params.push_back("json_context");
36 return params;
37}
38
39
40bool GPTDevice_ParamsParser::getParamValue(const std::string& paramName, std::string& paramValue) const
41{
42 if (paramName =="api_version")
43 {
44 paramValue = m_api_version;
45 return true;
46 }
47 if (paramName =="prompt_file")
48 {
49 paramValue = m_prompt_file;
50 return true;
51 }
52 if (paramName =="prompt_context")
53 {
54 paramValue = m_prompt_context;
55 return true;
56 }
57 if (paramName =="function_file")
58 {
59 paramValue = m_function_file;
60 return true;
61 }
62 if (paramName =="json_context")
63 {
64 paramValue = m_json_context;
65 return true;
66 }
67
68 yError() <<"parameter '" << paramName << "' was not found";
69 return false;
70
71}
72
73
75{
76 //This is a sub-optimal solution.
77 //Ideally getConfiguration() should return all parameters but it is currently
78 //returning only user provided parameters (excluding default values)
79 //This behaviour will be fixed in the near future.
80 std::string s_cfg = m_provided_configuration;
81 return s_cfg;
82}
83
85{
86 //Check for --help option
87 if (config.check("help"))
88 {
89 yCInfo(GPTDeviceParamsCOMPONENT) << getDocumentationOfDeviceParams();
90 }
91
94 //Parser of parameter api_version
95 {
96 if (config.check("api_version"))
97 {
98 m_api_version = config.find("api_version").asString();
99 yCInfo(GPTDeviceParamsCOMPONENT) << "Parameter 'api_version' using value:" << m_api_version;
100 }
101 else
102 {
103 yCInfo(GPTDeviceParamsCOMPONENT) << "Parameter 'api_version' using DEFAULT value:" << m_api_version;
104 }
105 prop_check.unput("api_version");
106 }
107
108 //Parser of parameter prompt_file
109 {
110 if (config.check("prompt_file"))
111 {
112 m_prompt_file = config.find("prompt_file").asString();
113 yCInfo(GPTDeviceParamsCOMPONENT) << "Parameter 'prompt_file' using value:" << m_prompt_file;
114 }
115 else
116 {
117 yCInfo(GPTDeviceParamsCOMPONENT) << "Parameter 'prompt_file' using DEFAULT value:" << m_prompt_file;
118 }
119 prop_check.unput("prompt_file");
120 }
121
122 //Parser of parameter prompt_context
123 {
124 if (config.check("prompt_context"))
125 {
126 m_prompt_context = config.find("prompt_context").asString();
127 yCInfo(GPTDeviceParamsCOMPONENT) << "Parameter 'prompt_context' using value:" << m_prompt_context;
128 }
129 else
130 {
131 yCInfo(GPTDeviceParamsCOMPONENT) << "Parameter 'prompt_context' using DEFAULT value:" << m_prompt_context;
132 }
133 prop_check.unput("prompt_context");
134 }
135
136 //Parser of parameter function_file
137 {
138 if (config.check("function_file"))
139 {
140 m_function_file = config.find("function_file").asString();
141 yCInfo(GPTDeviceParamsCOMPONENT) << "Parameter 'function_file' using value:" << m_function_file;
142 }
143 else
144 {
145 yCInfo(GPTDeviceParamsCOMPONENT) << "Parameter 'function_file' using DEFAULT value:" << m_function_file;
146 }
147 prop_check.unput("function_file");
148 }
149
150 //Parser of parameter json_context
151 {
152 if (config.check("json_context"))
153 {
154 m_json_context = config.find("json_context").asString();
155 yCInfo(GPTDeviceParamsCOMPONENT) << "Parameter 'json_context' using value:" << m_json_context;
156 }
157 else
158 {
159 yCInfo(GPTDeviceParamsCOMPONENT) << "Parameter 'json_context' using DEFAULT value:" << m_json_context;
160 }
161 prop_check.unput("json_context");
162 }
163
164 /*
165 //This code check if the user set some parameter which are not check by the parser
166 //If the parser is set in strict mode, this will generate an error
167 if (prop_check.size() > 0)
168 {
169 bool extra_params_found = false;
170 for (auto it=prop_check.begin(); it!=prop_check.end(); it++)
171 {
172 if (m_parser_is_strict)
173 {
174 yCError(GPTDeviceParamsCOMPONENT) << "User asking for parameter: "<<it->name <<" which is unknown to this parser!";
175 extra_params_found = true;
176 }
177 else
178 {
179 yCWarning(GPTDeviceParamsCOMPONENT) << "User asking for parameter: "<< it->name <<" which is unknown to this parser!";
180 }
181 }
182
183 if (m_parser_is_strict && extra_params_found)
184 {
185 return false;
186 }
187 }
188 */
189 return true;
190}
191
192
194{
195 std::string doc;
196 doc = doc + std::string("\n=============================================\n");
197 doc = doc + std::string("This is the help for device: GPTDevice\n");
198 doc = doc + std::string("\n");
199 doc = doc + std::string("This is the list of the parameters accepted by the device:\n");
200 doc = doc + std::string("'api_version': The openAI APIs version to use\n");
201 doc = doc + std::string("'prompt_file': The file containing the prompt for the LLM\n");
202 doc = doc + std::string("'prompt_context': The yarp context from which the prompt file should be loaded\n");
203 doc = doc + std::string("'function_file': The file containing the definitions of the tools for the LLM\n");
204 doc = doc + std::string("'json_context': The yarp context from which the function file should be loaded\n");
205 doc = doc + std::string("\n");
206 doc = doc + std::string("Here are some examples of invocation command with yarpdev, with all params:\n");
207 doc = doc + " yarpdev --device GPTDevice --api_version 2023-07-01-preview --prompt_file <optional_value> --prompt_context GPTDevice --function_file <optional_value> --json_context GPTDevice\n";
208 doc = doc + std::string("Using only mandatory params:\n");
209 doc = doc + " yarpdev --device GPTDevice\n";
210 doc = doc + std::string("=============================================\n\n"); return doc;
211}
#define yError(...)
Definition Log.h:361
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
std::vector< std::string > getListOfParams() const override
Return a list of all params used by the device.
std::string getDocumentationOfDeviceParams() const override
Get the documentation of the DeviceDriver's parameters.
bool getParamValue(const std::string &paramName, std::string &paramValue) const override
Return the value (represented as a string) of the requested parameter.
std::string getConfiguration() const override
Return the configuration of the device.
A class for storing options and configuration information.
Definition Property.h:33
void unput(const std::string &key)
Remove the association from the given key to a value, if present.
A base class for nested structures that can be searched.
Definition Searchable.h:31
virtual bool check(const std::string &key) const =0
Check if there exists a property of the given name.
virtual std::string toString() const =0
Return a standard text representation of the content of the object.
virtual Value & find(const std::string &key) const =0
Gets a value corresponding to a given keyword.
#define yCInfo(component,...)
#define YARP_LOG_COMPONENT(name,...)