YARP
Yet Another Robot Platform
 
Loading...
Searching...
No Matches
LLM_nwc_yarp.cpp
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2023-2023 Istituto Italiano di Tecnologia (IIT)
3 * SPDX-License-Identifier: BSD-3-Clause
4 */
5
6#include "LLM_nwc_yarp.h"
7#include <yarp/os/Log.h>
9#include <yarp/os/LogStream.h>
10
11namespace
12{
13 YARP_LOG_COMPONENT(LLM_NWC_YARP, "yarp.device.LLM_nwc_yarp")
14}
15
16using namespace yarp::dev;
17
19{
20 if (!parseParams(config)) { return false; }
21
23 {
24 yCError(LLM_NWC_YARP, "Cannot open rpc port, check network");
25 }
26
27 bool ok = false;
28
30
31 if (!ok)
32 {
33 yCError(LLM_NWC_YARP, "open() error could not connect to %s", m_remote.c_str());
34 return false;
35 }
36
38 {
39 yCError(LLM_NWC_YARP, "Cannot attach the m_rpc_port_to_LLM_server port as client");
40 }
41
42 //Check the protocol version
43 if (!m_LLM_RPC.checkProtocolVersion()) { return false; }
44
45 yCInfo(LLM_NWC_YARP) << "Opening of NWC successful";
46 return true;
47}
48
50{
52 return true;
53}
54
55ReturnValue LLM_nwc_yarp::setPrompt(const std::string &prompt)
56{
57 return m_LLM_RPC.setPrompt(prompt);
58}
59
61{
62 auto ret = m_LLM_RPC.readPrompt();
63
64 oPrompt = ret.prompt;
65 return ret.ret;
66}
67
68ReturnValue LLM_nwc_yarp::ask(const std::string &question, yarp::dev::LLM_Message &oAnswer)
69{
70 auto ret = m_LLM_RPC.ask(question);
71
72 oAnswer = ret.answer;
73 return ret.ret;
74}
75
76ReturnValue LLM_nwc_yarp::getConversation(std::vector<yarp::dev::LLM_Message> &oConversation)
77{
79 for (const auto &message : ret.conversation)
80 {
81 oConversation.push_back(message);
82 }
83
84 return ReturnValue_ok;
85}
86
91
bool ret
#define ReturnValue_ok
Definition ReturnValue.h:80
bool parseParams(const yarp::os::Searchable &config) override
Parse the DeviceDriver parameters.
yarp::dev::ReturnValue ask(const std::string &question, yarp::dev::LLM_Message &oAnswer) override
Performs a question.
bool close() override
Close the DeviceDriver.
yarp::dev::ReturnValue refreshConversation() override
Refresh the conversation.
bool open(yarp::os::Searchable &config) override
Open the DeviceDriver.
yarp::os::Port m_rpc_port_to_LLM_server
yarp::dev::ReturnValue readPrompt(std::string &oPrompt) override
Retrieves the provided prompt.
yarp::dev::ReturnValue getConversation(std::vector< yarp::dev::LLM_Message > &oConversation) override
Retrieves the whole conversation.
yarp::dev::llm::ILLMMsgs m_LLM_RPC
yarp::dev::ReturnValue deleteConversation() override
Delete the conversation and clear the system context from any internally stored context.
yarp::dev::ReturnValue setPrompt(const std::string &prompt) override
Performs a question.
virtual yarp::dev::ReturnValue refreshConversation()
virtual yarp::dev::ReturnValue deleteConversation()
virtual bool checkProtocolVersion()
Definition ILLMMsgs.cpp:82
virtual return_ask ask(const std::string &question)
virtual yarp::dev::ReturnValue setPrompt(const std::string &prompt)
virtual return_readPrompt readPrompt()
virtual return_getConversation getConversation()
static bool connect(const std::string &src, const std::string &dest, const std::string &carrier="", bool quiet=true)
Request that an output port connect to an input port.
Definition Network.cpp:682
void close() override
Stop port activity.
Definition Port.cpp:330
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
Definition Port.cpp:79
A base class for nested structures that can be searched.
Definition Searchable.h:31
yarp::os::WireLink & yarp()
Get YARP state associated with this object.
Definition Wire.h:28
#define yCInfo(component,...)
#define yCError(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.