]> git.djapps.eu Git - pkg/ggml/sources/llama.cpp/commitdiff
server: accept null sampling params (#25538)
authorPascal <redacted>
Fri, 10 Jul 2026 20:07:29 +0000 (22:07 +0200)
committerGitHub <redacted>
Fri, 10 Jul 2026 20:07:29 +0000 (22:07 +0200)
* server: accept null sampling params

Extend the schema validation to treat a null value as absent, so
clients can send null on nullable params (temperature, top_p, ...)
to request the server default. This matches the OpenAI spec and the
json_value convention used elsewhere.

Add has_field() to skip null in the field eval guards.

* has_field -> has_value​

tools/server/server-schema.cpp

index 5713cc8318da51457cd8d7c5c9fd0926d022d21c..89026eb4e3f0be0de9c5b2d69d027050d269525b 100644 (file)
@@ -568,10 +568,16 @@ static void handle_with_catch(const char * name, std::function<void()> func) {
     }
 }
 
+// treat a null value as absent so clients can send null to request the server default
+static bool has_value(const json & data, const char * n) {
+    auto it = data.find(n);
+    return it != data.end() && !it->is_null();
+}
+
 template <typename T>
 void field_num<T>::eval(field_eval_context & ctx, const json & data) {
     for (const auto & n : name) {
-        if (data.contains(n)) {
+        if (has_value(data, n)) {
             handle_with_catch(n, [&]() {
                 if (custom_handler) {
                 custom_handler(ctx, data);
@@ -593,7 +599,7 @@ void field_num<T>::eval(field_eval_context & ctx, const json & data) {
 void field_str::eval(field_eval_context & ctx, const json & data) {
     GGML_ASSERT(custom_handler);
     for (const auto & n : name) {
-        if (data.contains(n)) {
+        if (has_value(data, n)) {
             handle_with_catch(n, [&]() {
                 custom_handler(ctx, data);
             });
@@ -604,7 +610,7 @@ void field_str::eval(field_eval_context & ctx, const json & data) {
 
 void field_bool::eval(field_eval_context & ctx, const json & data) {
     for (const auto & n : name) {
-        if (data.contains(n)) {
+        if (has_value(data, n)) {
             handle_with_catch(n, [&]() {
                 if (custom_handler) {
                     custom_handler(ctx, data);
@@ -620,7 +626,7 @@ void field_bool::eval(field_eval_context & ctx, const json & data) {
 void field_json::eval(field_eval_context & ctx, const json & data) {
     GGML_ASSERT(custom_handler);
     for (const auto & n : name) {
-        if (data.contains(n)) {
+        if (has_value(data, n)) {
             handle_with_catch(n, [&]() {
                 custom_handler(ctx, data);
             });