Skip to content

Commit

Permalink
add response format
Browse files Browse the repository at this point in the history
  • Loading branch information
pkusunjy committed Aug 17, 2024
1 parent f5e548f commit a68dec5
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
.vscode
build
TestApp
13 changes: 13 additions & 0 deletions liboai/components/chat.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,11 @@ bool liboai::Conversation::PopUserData() & noexcept(false) {
return false; // conversation is empty
}

bool liboai::Conversation::AddResponseFormat(nlohmann::json j) & noexcept(false) {
this->_conversation["response_format"] = j;
return true;
}

std::string liboai::Conversation::GetLastResponse() const & noexcept {
// if conversation is not empty
if (!this->_conversation["messages"].empty()) {
Expand Down Expand Up @@ -638,6 +643,10 @@ liboai::Response liboai::ChatCompletion::create(const std::string& model, Conver
if (conversation.HasFunctions()) {
jcon.push_back("functions", conversation.GetFunctionsJSON()["functions"]);
}

if (conversation.GetJSON().contains("response_format")) {
jcon.push_back("response_format", conversation.GetJSON()["response_format"]);
}

Response res;
res = this->Request(
Expand Down Expand Up @@ -702,6 +711,10 @@ liboai::FutureResponse liboai::ChatCompletion::create_async(const std::string& m
jcon.push_back("functions", conversation.GetFunctionsJSON()["functions"]);
}

if (conversation.GetJSON().contains("response_format")) {
jcon.push_back("response_format", conversation.GetJSON()["response_format"]);
}

auto _fn = [this](
liboai::JsonConstructor&& jcon,
StrippedStreamCallback&& sscb
Expand Down
6 changes: 6 additions & 0 deletions liboai/include/components/chat.h
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,12 @@ namespace liboai {
[[nodiscard]]
LIBOAI_EXPORT bool PopUserData() & noexcept(false);

/*
@brief Adds response format
*/
[[nodiscard]]
LIBOAI_EXPORT bool AddResponseFormat(nlohmann::json j) & noexcept(false);

/*
@brief Gets the last response from the assistant.
This method gets the last response from the assistant.
Expand Down

0 comments on commit a68dec5

Please sign in to comment.