9void ConversationModel::setRemoteRpc(
const std::string& remoteRpc)
11 m_prop.
put(
"remote", remoteRpc);
14bool ConversationModel::setRemoteStreamingPort(
const std::string& remote_streaming_port_name)
21 if (!m_conversation_port.
open(m_conversation_port_name)) {
22 yWarning() <<
"Cannot open local streaming port " + m_conversation_port_name;
31bool ConversationModel::setInterface()
33 if (!m_poly.
open(m_prop)) {
34 yWarning() <<
"Cannot open LLM_nwc_yarp";
38 if (!m_poly.
view(m_iLlm)) {
39 yWarning() <<
"Cannot open interface from driver";
50 if (!remote_rpc.empty()) {
51 setRemoteRpc(remote_rpc);
55 if (!streaming_port_name.empty()) {
56 if (!m_conversation_port.
isClosed()) {
57 m_conversation_port.
close();
59 ret = setRemoteStreamingPort(streaming_port_name);
73 configure(remote_rpc.toStdString(), streaming_port_name.toStdString());
78 if (index.row() < 0 || index.row() >= m_conversation.count()) {
82 const Message& message = m_conversation[index.row()];
84 return message.
type();
96 return m_conversation.count();
101 QHash<int, QByteArray> roles;
107void ConversationModel::eraseConversation()
109 beginRemoveRows(QModelIndex(), 0,
rowCount());
110 m_conversation.clear();
117 yError() << m_no_device_message;
128 this->eraseConversation();
131 yError() << m_no_device_message;
135 std::vector<yarp::dev::LLM_Message> conversation;
138 yError() <<
"Unable to get conversation";
142 for (
const auto& message : conversation) {
143 addMessage(
Message(QString::fromStdString(message.type), QString::fromStdString(message.content)));
147void ConversationModel::addMessage(
const Message& message)
150 m_conversation << message;
160 yError() << m_no_device_message;
161 addMessage(
Message(QString::fromStdString(
"User"), QString::fromStdString(m_no_device_message)));
162 addMessage(
Message(QString::fromStdString(
"User"), QString::fromStdString(
"Please use the menu from the gui to add a valid connection to an existing LLM_nws")));
167 m_iLlm->
setPrompt(message.toStdString());
169 m_iLlm->
ask(message.toStdString(), answer);
177 beginRemoveRows(QModelIndex(), index, index);
178 m_conversation.removeAt(index);
void conversationChanged()
Q_INVOKABLE void sendMessage(const QString &message)
Sends a message.
void refreshConversation()
Deletes and reuploads the conversation.
QVariant data(const QModelIndex &index, int role) const override
Q_INVOKABLE void eraseMessage(const int &index)
int rowCount(const QModelIndex &parent=QModelIndex()) const override
bool configure(const std::string &remote_rpc, const std::string &streaming_port_name)
Configures the remote rpc and streaming port.
Q_INVOKABLE void deleteConversation()
Deletes the conversation.
QHash< int, QByteArray > roleNames() const override
Inner class for message representation in ConversationModel.
bool view(T *&x)
Get an interface to the device driver.
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 ask(const std::string &question, yarp::dev::LLM_Message &answer)=0
Performs a question.
bool open(const std::string &txt)
Construct and configure a device by its common name.
void close() override
Stop port activity.
bool open(const std::string &name) override
Start port operation, with a specific name, with automatically-chosen network parameters.
bool isClosed() override
Returns whether the port associated with this reader has been closed.
void useCallback(TypedReaderCallback< T > &callback) override
Set an object whose onRead method will be called when data is available.
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.
void put(const std::string &key, const std::string &value)
Associate the given key with the given string.