@@ -197,7 +197,6 @@ static void HandleHttpError(const duckdb_httplib_openssl::Result &res, const std
197
197
static void OpenPromptRequestFunction (DataChunk &args, ExpressionState &state, Vector &result) {
198
198
UnaryExecutor::Execute<string_t , string_t >(args.data [0 ], result, args.size (),
199
199
[&](string_t user_prompt) {
200
- duckdb_yyjson::yyjson_doc *doc = nullptr ;
201
200
auto &conf = ClientConfig::GetConfig (state.GetContext ());
202
201
Value api_url;
203
202
Value api_token;
@@ -232,9 +231,13 @@ static void OpenPromptRequestFunction(DataChunk &args, ExpressionState &state, V
232
231
if (res && res->status == 200 ) {
233
232
// Extract the first choice's message content from the response
234
233
std::string response_body = res->body ;
235
- doc = duckdb_yyjson::yyjson_read (
236
- response_body.c_str (), response_body.length (), 0 );
237
- auto root = assert_null (duckdb_yyjson::yyjson_doc_get_root (doc));
234
+ unique_ptr<duckdb_yyjson::yyjson_doc, void (*)(struct duckdb_yyjson ::yyjson_doc *)> doc (
235
+ nullptr , &duckdb_yyjson::yyjson_doc_free
236
+ );
237
+ doc.reset (assert_null (
238
+ duckdb_yyjson::yyjson_read (response_body.c_str (), response_body.length (), 0 )
239
+ ));
240
+ auto root = assert_null (duckdb_yyjson::yyjson_doc_get_root (doc.get ()));
238
241
auto choices = assert_null (duckdb_yyjson::yyjson_obj_get (root, " choices" ));
239
242
auto choices_0 = assert_null (duckdb_yyjson::yyjson_arr_get_first (choices));
240
243
auto message = assert_null (duckdb_yyjson::yyjson_obj_get (choices_0, " message" ));
0 commit comments