Skip to content

Commit 4f37f51

Browse files
server: accept null sampling params (ggml-org#25538)
* 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​
1 parent c749cb0 commit 4f37f51

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

tools/server/server-schema.cpp

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -568,10 +568,16 @@ static void handle_with_catch(const char * name, std::function<void()> func) {
568568
}
569569
}
570570

571+
// treat a null value as absent so clients can send null to request the server default
572+
static bool has_value(const json & data, const char * n) {
573+
auto it = data.find(n);
574+
return it != data.end() && !it->is_null();
575+
}
576+
571577
template <typename T>
572578
void field_num<T>::eval(field_eval_context & ctx, const json & data) {
573579
for (const auto & n : name) {
574-
if (data.contains(n)) {
580+
if (has_value(data, n)) {
575581
handle_with_catch(n, [&]() {
576582
if (custom_handler) {
577583
custom_handler(ctx, data);
@@ -593,7 +599,7 @@ void field_num<T>::eval(field_eval_context & ctx, const json & data) {
593599
void field_str::eval(field_eval_context & ctx, const json & data) {
594600
GGML_ASSERT(custom_handler);
595601
for (const auto & n : name) {
596-
if (data.contains(n)) {
602+
if (has_value(data, n)) {
597603
handle_with_catch(n, [&]() {
598604
custom_handler(ctx, data);
599605
});
@@ -604,7 +610,7 @@ void field_str::eval(field_eval_context & ctx, const json & data) {
604610

605611
void field_bool::eval(field_eval_context & ctx, const json & data) {
606612
for (const auto & n : name) {
607-
if (data.contains(n)) {
613+
if (has_value(data, n)) {
608614
handle_with_catch(n, [&]() {
609615
if (custom_handler) {
610616
custom_handler(ctx, data);
@@ -620,7 +626,7 @@ void field_bool::eval(field_eval_context & ctx, const json & data) {
620626
void field_json::eval(field_eval_context & ctx, const json & data) {
621627
GGML_ASSERT(custom_handler);
622628
for (const auto & n : name) {
623-
if (data.contains(n)) {
629+
if (has_value(data, n)) {
624630
handle_with_catch(n, [&]() {
625631
custom_handler(ctx, data);
626632
});

0 commit comments

Comments
 (0)