Repository navigation
json: Fixed json enum handling - #28518
Conversation
Added common_json_value handling for enum values. Added tests/test-json.cpp to cover testing of some aspects of common_json.
ZitouniNidhal
left a comment
There was a problem hiding this comment.
Reviewed the changes — looks good to me.
The fix addresses the enum serialization issue cleanly by handling enum values explicitly through common_json_value, and the added tests provide good coverage for the reported regression. The scope of the change is focused and the implementation is easy to follow.
|
/bot review |
Automated code reviewReviewing PR #28518 - a fix in The bug diagnosis is correct: Will slow the review (point 1) New test file needs maintainer sign-off. Per (point 2) Duplicated signed/unsigned branch in template <typename T, typename std::enable_if_t<std::is_enum_v<T>, int> = 0>
common_json_value(T val) : common_json_value((std::underlying_type_t<T>) val) {}This picks VAL_INT/VAL_UINT via the integral ctor and removes the copy. (Edge case: an (point 3) Style inconsistency with the adjacent code in Nits (point 4) (point 5) Test coverage is all-zero values ( Everything else checks out: the two templated ctors have disjoint This review was generated automatically by pi coding agent using |
There was a problem hiding this comment.
I don't think it's useful to add such test. server tests should already covered it
There was a problem hiding this comment.
I wasn't a big fan of adding tests of this form, but it was the only sane way I could think to handle the regression test requirement of a bug-fix PR. Server tests do not cover this problem, but they are remarkably lacking in coverage of what shape and form is expected in JSON values returned to clients in general. Also it didn't seem like a good idea to have only the server cover tests for a piece of code that lives in common. Should I go back and add a one-off edge case test for this one field that I found emitted wrong from llama-server? Something like:
assert type(res.body["data"][0]["meta"]["vocab_type"]) is intin test_server_models() of tools/server/tests/unit/test_basic.py
Simplified by delegating enum constructor to the constructor of the underlying type Matched style of surrounding templating code
57faf80 to
f97ccfd
Compare
|
/bot review |
Automated code reviewFollow-up review at commit f97ccfd (previous review covered 9fb8a26). Changes since the last review: the All points from the previous review are resolved:
template <typename T, typename std::enable_if<std::is_enum<T>::value, int>::type = 0>
common_json_value(T val) : common_json_value((typename std::underlying_type<T>::type) val) {}This is correct. An enum's underlying type is always integral,
I re-checked the fix against the reported site: No blocking issues, no new findings. The diff is now a minimal, single-purpose fix and looks good from my side. This review was generated automatically by pi coding agent using |
|
Fixes #29091 |
This comment was marked as low quality.
This comment was marked as low quality.
* Fixed json enum handling Added common_json_value handling for enum values. Added tests/test-json.cpp to cover testing of some aspects of common_json. * Removed tests as requested. * Applied recommended style and simplification Simplified by delegating enum constructor to the constructor of the underlying type Matched style of surrounding templating code
* Fixed json enum handling Added common_json_value handling for enum values. Added tests/test-json.cpp to cover testing of some aspects of common_json. * Removed tests as requested. * Applied recommended style and simplification Simplified by delegating enum constructor to the constructor of the underlying type Matched style of surrounding templating code
* Fixed json enum handling Added common_json_value handling for enum values. Added tests/test-json.cpp to cover testing of some aspects of common_json. * Removed tests as requested. * Applied recommended style and simplification Simplified by delegating enum constructor to the constructor of the underlying type Matched style of surrounding templating code (cherry picked from commit 26394b4)
Added common_json_value handling for enum values.
Overview
enumtype variable to emit as booleans rather than integers as expected. This was noticed in theGET /v1/modelsllama-server endpoint asdata/meta/vocab_typebeing returned to clients as a boolean. In my case I was expecting to get"vocab_type":2but instead I was getting back"vocab_type":true.Requirements