Skip to content

Commit

Permalink
Merge pull request #3071 from fbrand-new/feat/gpt_functions
Browse files Browse the repository at this point in the history
Added support for GPT "Functions"
  • Loading branch information
randaz81 authored Feb 13, 2024
2 parents 8d2d4a0 + f6a0314 commit 6ca5939
Show file tree
Hide file tree
Showing 24 changed files with 600 additions and 312 deletions.
4 changes: 2 additions & 2 deletions bindings/yarp.i
Original file line number Diff line number Diff line change
Expand Up @@ -1584,8 +1584,8 @@ typedef yarp::os::BufferedPort<ImageRgbFloat> BufferedPortImageRgbFloat;
return self->readPrompt(oPropmt[0]);
}

bool ask(const std::string& question, std::vector<string>& answer) {
return self->ask(question, answer[0]);
bool ask(const std::string& question, yarp::dev::LLM_Message& answer) {
return self->ask(question, answer);
}
}

Expand Down
2 changes: 2 additions & 0 deletions doc/release/master.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ New Features

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

* Added LLM_Message data type to propagate LLM answers

### Devices

#### deviceBundler
Expand Down
30 changes: 21 additions & 9 deletions src/devices/fake/fakeLLMDevice/fakeLLMDevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,35 +15,47 @@ bool fakeLLMDevice::setPrompt(const std::string &prompt)
return false;
}

m_conversation.push_back(std::make_pair("system", prompt));
m_conversation.push_back(yarp::dev::LLM_Message("system", prompt,{},{}));
return true;
}

bool fakeLLMDevice::readPrompt(std::string &oPrompt)
{
for (const auto &[author, content] : m_conversation)
for (const auto &message : m_conversation)
{
if (author == "system")
if (message.type == "system")
{
oPrompt = content;
oPrompt = message.content;
return true;
}
}

return false;
}

bool fakeLLMDevice::ask(const std::string &question, std::string &oAnswer)
bool fakeLLMDevice::ask(const std::string &question, yarp::dev::LLM_Message &oAnswer)
{
// In the fake device we ignore the question
std::string answer = "Fatti non foste per viver come bruti ma per seguir virtute e canoscenza";
m_conversation.push_back(std::make_pair("user", question));
m_conversation.push_back(std::make_pair("assistant", answer));
yarp::dev::LLM_Message answer;
if(question == "function")
{
std::string function_name = "FakeFunction";
std::vector<std::string> function_params = {"arg1","arg2"};
std::vector<std::string> function_args = {"yes","no"};
answer = yarp::dev::LLM_Message("function",function_name,function_params,function_args);
}
else
{
std::string answer_content = "Fatti non foste per viver come bruti ma per seguir virtute e canoscenza";
answer = yarp::dev::LLM_Message("assistant", answer_content,{},{});
}
m_conversation.push_back(yarp::dev::LLM_Message("user", question,{},{}));
m_conversation.push_back(answer);
oAnswer = answer;
return true;
}

bool fakeLLMDevice::getConversation(std::vector<std::pair<Author, Content>>& oConversation)
bool fakeLLMDevice::getConversation(std::vector<yarp::dev::LLM_Message>& oConversation)
{
oConversation = m_conversation;
return true;
Expand Down
6 changes: 3 additions & 3 deletions src/devices/fake/fakeLLMDevice/fakeLLMDevice.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class fakeLLMDevice : public yarp::dev::ILLM,
fakeLLMDevice() : m_conversation{} {}
bool setPrompt(const std::string &prompt) override;
bool readPrompt(std::string &oPromp) override;
bool ask(const std::string &question, std::string &oAnswer) override;
bool getConversation(std::vector<std::pair<Author, Content>> &oConversation) override;
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;

private:
std::vector<std::pair<Author, Content>> m_conversation;
std::vector<yarp::dev::LLM_Message> m_conversation;
};

#endif
13 changes: 7 additions & 6 deletions src/devices/messages/ILLMMsgs/ILLMMsgs.thrift
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@

namespace yarp yarp.dev.llm

struct Message {
string sender;
string content;
}
struct LLM_Message {
} (
yarp.name = "yarp::dev::LLM_Message"
yarp.includefile="yarp/dev/ILLM.h"
)

struct return_readPrompt{
1: bool ret = false;
Expand All @@ -17,12 +18,12 @@ struct return_readPrompt{

struct return_ask{
1: bool ret = false;
2: string answer;
2: LLM_Message answer;
}

struct return_getConversation{
1: bool ret = false;
2: list<Message> conversation;
2: list<LLM_Message> conversation;
}

service ILLMMsgs {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
yarp/dev/llm/Message.h
yarp/dev/llm/Message.cpp
yarp/dev/llm/return_readPrompt.h
yarp/dev/llm/return_readPrompt.cpp
yarp/dev/llm/return_ask.h
Expand Down

This file was deleted.

This file was deleted.

Loading

0 comments on commit 6ca5939

Please sign in to comment.