Skip to content

Commit

Permalink
yyjson rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
akvlad committed Oct 26, 2024
1 parent e92b975 commit 9cedcf8
Showing 1 changed file with 33 additions and 5 deletions.
38 changes: 33 additions & 5 deletions src/open_prompt_extension.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -190,13 +190,41 @@ static void OpenPromptRequestFunction(DataChunk &args, ExpressionState &state, V
json_schema = args.data[info.json_schema_idx].GetValue(0).ToString();
}

std::string request_body = "{";
request_body += "\"model\":\"" + model_name + "\",";
unique_ptr<duckdb_yyjson::yyjson_mut_doc,
void (*)(duckdb_yyjson::yyjson_mut_doc*)> doc(
new duckdb_yyjson::yyjson_mut_doc(), &duckdb_yyjson::yyjson_mut_doc_free);
auto obj = duckdb_yyjson::yyjson_mut_obj(doc.get());
duckdb_yyjson::yyjson_mut_obj_add(obj,
duckdb_yyjson::yyjson_mut_str(doc.get(), "model"),
duckdb_yyjson::yyjson_mut_str(doc.get(), model_name.c_str())
);
if (!json_schema.empty()) {
request_body += "\"response_format\":{\"type\":\"json_object\", \"schema\":";
request_body += json_schema;
request_body += "},";
auto response_format = duckdb_yyjson::yyjson_mut_obj(doc.get());
duckdb_yyjson::yyjson_mut_obj_add(response_format,
duckdb_yyjson::yyjson_mut_str(doc.get(), "type"),
duckdb_yyjson::yyjson_mut_str(doc.get(), "json_object"));
auto yyschema = duckdb_yyjson::yyjson_mut_raw(doc.get(), json_schema.c_str());
duckdb_yyjson::yyjson_mut_obj_add(response_format,
duckdb_yyjson::yyjson_mut_str(doc.get(), "schema"),
yyschema);
duckdb_yyjson::yyjson_mut_obj_add(obj,
duckdb_yyjson::yyjson_mut_str(doc.get(),"response_format"),
response_format);
}
auto messages = duckdb_yyjson::yyjson_mut_arr(doc.get());
string str_messages[2][2] = {
{"system", "You are a helpful assistant."},
{"user", user_prompt.GetString()}
};
for (auto message : str_messages) {
if (message[1].empty()) {
continue;
}
auto yymessage = duckdb_yyjson::yyjson_mut_obj(doc.get());

}
duckdb_yyjson::yyjson_mut_obj_add(obj, duckdb_yyjson::yyjson_mut_str(doc.get(), "messages"),
)

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_arm64, arm64, arm64-osx)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_arm64, arm64, arm64-osx)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_amd64, x86_64, x64-osx)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_amd64, x86_64, x64-osx)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_mvp, wasm32-emscripten)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_mvp, wasm32-emscripten)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

expected expression

Check failure on line 227 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

expected expression
request_body += "\"messages\":[";
request_body += "{\"role\":\"system\",\"content\":\"You are a helpful assistant.\"},";

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_arm64, arm64, arm64-osx)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_arm64, arm64, arm64-osx)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_amd64, x86_64, x64-osx)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_amd64, x86_64, x64-osx)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_mvp, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_mvp, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 229 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

use of undeclared identifier 'request_body'
request_body += "{\"role\":\"user\",\"content\":\"" + user_prompt.GetString() + "\"}";

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_arm64, arm64, arm64-osx)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_arm64, arm64, arm64-osx)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_amd64, x86_64, x64-osx)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / MacOS (osx_amd64, x86_64, x64-osx)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_mvp, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_mvp, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_threads, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

use of undeclared identifier 'request_body'

Check failure on line 230 in src/open_prompt_extension.cpp

View workflow job for this annotation

GitHub Actions / Build extension binaries / DuckDB-Wasm (wasm_eh, wasm32-emscripten)

use of undeclared identifier 'request_body'
Expand Down

0 comments on commit 9cedcf8

Please sign in to comment.