Skip to content
This repository was archived by the owner on Dec 20, 2025. It is now read-only.
Open
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
14 changes: 12 additions & 2 deletions liboai/components/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ liboai::Conversation::Conversation(std::initializer_list<std::string_view> user_
liboai::Conversation::Conversation(const std::vector<std::string>& user_data) {
this->_conversation["messages"] = nlohmann::json::array();

for (auto& data : user_data) {
auto result = this->AddUserData(data);
for (const std::string& data : user_data) {
auto result = this->AddUserData(static_cast<std::string_view>(data));
}
}

Expand Down Expand Up @@ -151,6 +151,16 @@ bool liboai::Conversation::AddUserData(std::string_view data, std::string_view n
return false; // data is empty
}

bool liboai::Conversation::AddUserData(nlohmann::json data) & noexcept(false) {
// if data provided is non-empty
if (!data.empty()) {
EraseExtra();
this->_conversation["messages"].push_back(data);
return true; // user data added successfully
}
return false; // data is empty
}

bool liboai::Conversation::PopUserData() & noexcept(false) {
// if conversation is not empty
if (!this->_conversation["messages"].empty()) {
Expand Down
20 changes: 20 additions & 0 deletions liboai/include/components/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -603,6 +603,26 @@ namespace liboai {
std::string_view name
) & noexcept(false);

/*
@brief Adds JSON object user input to the conversation.
This method adds JSON user input to the conversation.
The user input is the user's input - such as a question
or a command, with evantually file attachments.

If using a system prompt, the user input should be
provided after the system prompt is set - i.e. after
SetSystemData() is called.

@param *data The user input to add.

@returns True/False denoting whether the user input was
added successfully.
*/
[[nodiscard]]
LIBOAI_EXPORT bool AddUserData(
nlohmann::json data
) & noexcept(false);

/*
@brief Removes the last added user data.

Expand Down