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 yCDebug(LLM_NWC_YARP) << "Opening of nwc successful";
43 return true;
44}
45
47{
49 return true;
50}
51
52ReturnValue LLM_nwc_yarp::setPrompt(const std::string &prompt)
53{
54 return m_LLM_RPC.setPrompt(prompt);
55}
56
58{
59 auto ret = m_LLM_RPC.readPrompt();
60
61 oPrompt = ret.prompt;
62 return ret.ret;
63}
64
65ReturnValue LLM_nwc_yarp::ask(const std::string &question, yarp::dev::LLM_Message &oAnswer)
66{
67 auto ret = m_LLM_RPC.ask(question);
68
69 oAnswer = ret.answer;
70 return ret.ret;
71}
72
73ReturnValue LLM_nwc_yarp::getConversation(std::vector<yarp::dev::LLM_Message> &oConversation)
74{
76 for (const auto &message : ret.conversation)
77 {
78 oConversation.push_back(message);
79 }
80
81 return ReturnValue_ok;
82}
83
88
bool ret
#define ReturnValue_ok
Definition ReturnValue.h:77
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 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:363
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 yCError(component,...)
#define yCDebug(component,...)
#define YARP_LOG_COMPONENT(name,...)
For streams capable of holding different kinds of content, check what they actually have.