Skip to content

Preserving the order of the keys in json-schema-to-grammar by using nlohmann::ordered_json #6215

@mgonzs13

Description

@mgonzs13

Prerequisites

Please answer the following questions for yourself before submitting an issue.

  • I am running the latest code. Development is very rapid so there are no tagged versions as of now.
  • I carefully followed the README.md.
  • I searched using keywords relevant to my issue to make sure that I am creating a new issue that is not already open (or closed).
  • I reviewed the Discussions, and have a new bug or useful enhancement to share.

Feature Description

Using ordered JSONs in json-schema-to-grammar so that the llama.cpp follows the order of the JSON schema.

Motivation

I've been trying the new C++ json-schema-to-grammar from #5978 and I've noticed that there is no prop_order, which is present in the python version, to order the keys of the JSON schema. I think this could be interesting since generating text for some specific keys can improve the text generation of the following keys.

Possible Implementation

An easy solution is replacing the base json nlohmann::jsonwith nlohmann::ordered_json in both files json-schema-to-grammar.h and json-schema-to-grammar.cpp. This will result in JSON that preserves the original order of the keys.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions