19 if (m_iLlm ==
nullptr) {
20 yCError(LLMSERVER,
"Invalid interface");
21 return ReturnValue::return_code::return_value_error_not_ready;
26 yCError(LLMSERVER,
"setPrompt failed");
30 m_stream_conversation();
40 if (m_iLlm ==
nullptr) {
41 yCError(LLMSERVER,
"Invalid interface");
42 ret.ret = ReturnValue::return_code::return_value_error_not_ready;
55 if (m_iLlm ==
nullptr) {
56 yCError(LLMSERVER,
"Invalid interface");
57 ret.ret = ReturnValue::return_code::return_value_error_not_ready;
61 ret.ret = m_iLlm->
ask(question,
ret.answer);
64 m_stream_conversation();
70void ILLMRPCd::m_stream_conversation()
72 std::vector<yarp::dev::LLM_Message> conversation;
74 yCError(LLMSERVER,
"Unable to retrieve the conversation");
78 auto& bot = m_streaming_port.
prepare();
80 auto& list = bot.addList();
81 for (
const auto& message : conversation) {
82 auto& message_bot = list.addList();
83 message_bot.addString(message.type);
84 message_bot.addString(message.content);
85 auto& params_bot = message_bot.addList();
86 for(
const auto& params: message.parameters)
88 params_bot.addString(params);
91 auto& args_bot = message_bot.addList();
92 for(
const auto& args: message.arguments)
94 args_bot.addString(args);
98 m_streaming_port.
write();
106 if (m_iLlm ==
nullptr) {
107 yCError(LLMSERVER,
"Invalid interface");
108 ret.ret = ReturnValue::return_code::return_value_error_not_ready;
112 std::vector<yarp::dev::LLM_Message> conversation;
114 ret.conversation = conversation;
121 if (m_iLlm ==
nullptr) {
122 yCError(LLMSERVER,
"Invalid interface");
123 return ReturnValue::return_code::return_value_error_not_ready;
129 m_stream_conversation();
137 if (m_iLlm ==
nullptr) {
138 yCError(LLMSERVER,
"Invalid interface");
139 return ReturnValue::return_code::return_value_error_not_ready;
145 m_stream_conversation();
yarp::dev::ReturnValue setPrompt(const std::string &prompt) override
yarp::dev::llm::return_ask ask(const std::string &question) override
yarp::dev::ReturnValue refreshConversation() override
yarp::dev::llm::return_getConversation getConversation() override
yarp::dev::ReturnValue deleteConversation() override
yarp::dev::llm::return_readPrompt readPrompt() override
virtual yarp::dev::ReturnValue deleteConversation()=0
Delete the conversation and clear the system context from any internally stored context.
virtual yarp::dev::ReturnValue setPrompt(const std::string &prompt)=0
Performs a question.
virtual yarp::dev::ReturnValue getConversation(std::vector< yarp::dev::LLM_Message > &conversation)=0
Retrieves the whole conversation.
virtual yarp::dev::ReturnValue refreshConversation()=0
Refresh the conversation.
virtual yarp::dev::ReturnValue readPrompt(std::string &oPrompt)=0
Retrieves the provided prompt.
virtual yarp::dev::ReturnValue ask(const std::string &question, yarp::dev::LLM_Message &answer)=0
Performs a question.
void clear()
Empties the bottle of any objects it contains.
void write(bool forceStrict=false)
Write the current object being returned by BufferedPort::prepare.
T & prepare()
Access the object which will be transmitted by the next call to yarp::os::BufferedPort::write.
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.