Skip to content

Commit ee27c9f

Browse files
committed
debug
1 parent 1b855b3 commit ee27c9f

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/open_prompt_extension.cpp

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,6 @@ static void HandleHttpError(const duckdb_httplib_openssl::Result &res, const std
197197
static void OpenPromptRequestFunction(DataChunk &args, ExpressionState &state, Vector &result) {
198198
UnaryExecutor::Execute<string_t, string_t>(args.data[0], result, args.size(),
199199
[&](string_t user_prompt) {
200-
duckdb_yyjson::yyjson_doc *doc = nullptr;
201200
auto &conf = ClientConfig::GetConfig(state.GetContext());
202201
Value api_url;
203202
Value api_token;
@@ -232,9 +231,13 @@ static void OpenPromptRequestFunction(DataChunk &args, ExpressionState &state, V
232231
if (res && res->status == 200) {
233232
// Extract the first choice's message content from the response
234233
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()));
238241
auto choices = assert_null(duckdb_yyjson::yyjson_obj_get(root, "choices"));
239242
auto choices_0 = assert_null(duckdb_yyjson::yyjson_arr_get_first(choices));
240243
auto message = assert_null(duckdb_yyjson::yyjson_obj_get(choices_0, "message"));

0 commit comments

Comments
 (0)