Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[yarpDeviceLLM] Added refresh conversation rpc #3121

Merged
merged 3 commits into from
Aug 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion doc/release/master.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ New Features

* Added new command line tool `yarpDeviceParamParserGenerator`. See official yarp documentation (cmd_yarpDeviceParamParserGenerator.dox)

* Added LLM_Message data type to propagate LLM answers

#### Docker
* Added two parameters to yarp `Dockerfile`:
Expand All @@ -55,3 +54,9 @@ New Features

* Added new device `deviceBundler` which can be useful to open two devices and attach them while using a single yarpdev command line.
See https://github.com/robotology/yarp/discussions/3078

#### llmDevice

* Added LLM_Message data type to propagate LLM answers

* Added refreshConversation feature in the interface to allow users to restart the conversation mantaining the same prompt.
21 changes: 21 additions & 0 deletions src/devices/fake/fakeLLMDevice/FakeLLMDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,27 @@ bool FakeLLMDevice::deleteConversation() noexcept
return true;
}

bool FakeLLMDevice::refreshConversation() noexcept
{
std::string current_prompt;

if(!this->readPrompt(current_prompt))
{
yError() << "No prompt found in the conversation. Cannot refresh.";
return false;
}

this->deleteConversation();

if(!this->setPrompt(current_prompt))
{
yError() << "Failed to refresh the conversation.";
return false;
}

return true;
}

bool FakeLLMDevice::open(yarp::os::Searchable& config)
{
if (!this->parseParams(config)) {return false;}
Expand Down
1 change: 1 addition & 0 deletions src/devices/fake/fakeLLMDevice/FakeLLMDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ class FakeLLMDevice : public yarp::dev::ILLM,
bool ask(const std::string &question, yarp::dev::LLM_Message &oAnswer) override;
bool getConversation(std::vector<yarp::dev::LLM_Message> &oConversation) override;
bool deleteConversation() noexcept override;
bool refreshConversation() noexcept override;

bool open(yarp::os::Searchable& config) override;
bool close() override;
Expand Down
1 change: 1 addition & 0 deletions src/devices/messages/ILLMMsgs/ILLMMsgs.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,5 @@ service ILLMMsgs {
return_ask ask(1: string question);
return_getConversation getConversation();
bool deleteConversation();
bool refreshConversation();
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,3 +83,8 @@ bool LLM_nwc_yarp::deleteConversation()
{
return m_LLM_RPC.deleteConversation();
}

bool LLM_nwc_yarp::refreshConversation()
{
return m_LLM_RPC.refreshConversation();
}
1 change: 1 addition & 0 deletions src/devices/networkWrappers/LLM_nwc_yarp/LLM_nwc_yarp.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,5 @@ class LLM_nwc_yarp : public yarp::dev::DeviceDriver,
bool ask(const std::string& question, yarp::dev::LLM_Message& oAnswer) override;
bool getConversation(std::vector<yarp::dev::LLM_Message>& oConversation) override;
bool deleteConversation() override;
bool refreshConversation() override;
};
18 changes: 18 additions & 0 deletions src/devices/networkWrappers/LLM_nws_yarp/ILLMServerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ void ILLMRPCd::m_stream_conversation()
}

auto& bot = m_streaming_port.prepare();
bot.clear();
auto& list = bot.addList();
for (const auto& message : conversation) {
auto& message_bot = list.addList();
Expand Down Expand Up @@ -128,3 +129,20 @@ bool ILLMRPCd::deleteConversation()

return ret;
}

bool ILLMRPCd::refreshConversation()
{
bool ret = false;
if (m_iLlm == nullptr) {
yCError(LLMSERVER, "Invalid interface");
return false;
}

ret = m_iLlm->refreshConversation();

if (ret) {
m_stream_conversation();
}

return ret;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ class ILLMRPCd : public yarp::dev::llm::ILLMMsgs
yarp::dev::llm::return_ask ask(const std::string& question) override;
yarp::dev::llm::return_getConversation getConversation() override;
bool deleteConversation() override;
bool refreshConversation() override;
};
6 changes: 6 additions & 0 deletions src/libYARP_dev/src/yarp/dev/ILLM.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,12 @@ class YARP_dev_API yarp::dev::ILLM
* @return true/false
*/
virtual bool deleteConversation() = 0;

/**
* Refresh the conversation
* @return true/false
*/
virtual bool refreshConversation() = 0;
};

#endif
Loading
Loading