Skip to content

Commit

Permalink
Merge pull request #3121 from fbrand-new/feat/llm_refresh_conv
Browse files Browse the repository at this point in the history
[yarpDeviceLLM] Added refresh conversation rpc
  • Loading branch information
randaz81 authored Aug 5, 2024
2 parents bde9cd2 + a5b5d36 commit dfe6d31
Show file tree
Hide file tree
Showing 12 changed files with 291 additions and 1 deletion.
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;
}
1 change: 1 addition & 0 deletions src/devices/networkWrappers/LLM_nws_yarp/ILLMServerImpl.h
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

0 comments on commit dfe6d31

Please sign in to comment.