From 925c365c2ad8e7ce181d9ac188d7819cdd87afed Mon Sep 17 00:00:00 2001 From: olebol Date: Tue, 10 Dec 2024 17:23:45 +0000 Subject: [PATCH 1/2] change include statement to quotes to specify where the compiler should search first --- include/openai/openai.hpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/openai/openai.hpp b/include/openai/openai.hpp index 16a65c9..d2e2631 100644 --- a/include/openai/openai.hpp +++ b/include/openai/openai.hpp @@ -43,7 +43,7 @@ #include "curl/curl.h" #endif -#include // nlohmann/json +#include "nlohmann/json.hpp" namespace openai { From 8fb6de3df2354d7354921ef38ba5a79906130805 Mon Sep 17 00:00:00 2001 From: olebol Date: Tue, 10 Dec 2024 17:26:08 +0000 Subject: [PATCH 2/2] free the header list after last use --- include/openai/openai.hpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/include/openai/openai.hpp b/include/openai/openai.hpp index d2e2631..14eeb6a 100644 --- a/include/openai/openai.hpp +++ b/include/openai/openai.hpp @@ -192,7 +192,7 @@ inline Response Session::deletePrepare() { inline Response Session::makeRequest(const std::string& contentType) { std::lock_guard lock(mutex_request_); - + struct curl_slist* headers = NULL; if (!contentType.empty()) { headers = curl_slist_append(headers, std::string{"Content-Type: " + contentType}.c_str()); @@ -209,7 +209,7 @@ inline Response Session::makeRequest(const std::string& contentType) { } curl_easy_setopt(curl_, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl_, CURLOPT_URL, url_.c_str()); - + std::string response_string; std::string header_string; curl_easy_setopt(curl_, CURLOPT_WRITEFUNCTION, writeFunction); @@ -218,9 +218,14 @@ inline Response Session::makeRequest(const std::string& contentType) { res_ = curl_easy_perform(curl_); + if (headers != NULL) { + curl_slist_free_all(headers); + headers = NULL; + } + bool is_error = false; std::string error_msg{}; - if(res_ != CURLE_OK) { + if (res_ != CURLE_OK) { is_error = true; error_msg = "OpenAI curl_easy_perform() failed: " + std::string{curl_easy_strerror(res_)}; if (throw_exception_) {