Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

json: $ref + object overhaul (https & recursive $refs, mix properties & allOf) #8199

Open
wants to merge 15 commits into
base: master
Choose a base branch
from

Conversation

ochafik
Copy link
Collaborator

@ochafik ochafik commented Jun 28, 2024

Update $ref & object handling in JSON Schema -> GBNF converters:

  • Support recursive $refs (fixes Bug: JSON Schema - enum behind a $ref generates an object with unrestricted properties #8073)

  • Resolve https $refs in C++ converter when built w/ LLAMA_CURL=1 (caching result in RAM for now, may want to introduce HTTP caching semantics at some point)

    ./llama-cli \
      -j '{"$ref": "https://json.schemastore.org/tsconfig.json"}' \
      -mu https://huggingface.co/bartowski/Meta-Llama-3-8B-Instruct-GGUF/resolve/main/Meta-Llama-3-8B-Instruct-Q8_0.gguf 
      -p "Write a tsconfig.json: "
  • Allow mixing properties & anyOf (simplified / unified object conversion code)

    Show example
    echo '{
      "properties": {
        "common": {"$ref": "#/$defs/SomeVal"}
      },
      "allOf": [
          {"$ref": "#/$defs/foo"},
          {"$ref": "#/$defs/bar"},
          {
            "anyOf": [
                {"$ref": "#/$defs/baz"},
                {"$ref": "#/$defs/bam"}
            ]
          }
      ],
      "required": ["common"],
      "$defs": {
          "SomeVal": {"type": "number"},
          "foo": {"properties": {"a": {"$ref": "#/$defs/SomeVal"}}},
          "bar": {"properties": {"b": {"$ref": "#/$defs/SomeVal"}}},
          "bam": {"properties": {"c": {"$ref": "#/$defs/SomeVal"}}},
          "baz": {"properties": {"d": {"$ref": "#/$defs/SomeVal"}}}
      }
    }' | node examples/json_schema_to_grammar.mjs -
  • Remove allowFetch options from Python & JS converters (kinda breaking change)

  • Align JavaScript conversion CLI (which was only used for tests) with the Python version (both in examples folder)

    # schema.json arg can be "-" for stdin, a URL or a file.
    node   examples/json_schema_to_grammar.mjs schema.json
    python examples/json_schema_to_grammar.py  schema.json

cc/ @HanClinto more JSON :-)

@ochafik ochafik added breaking change Changes that break ABIs, APIs, file formats, or other forms of backwards compatibility. Review Complexity : Medium Generally require more time to grok but manageable by beginner to medium expertise level labels Jun 28, 2024
@ochafik ochafik marked this pull request as ready for review June 28, 2024 21:34
@github-actions github-actions bot added testing Everything test related examples python python script changes server labels Jun 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking change Changes that break ABIs, APIs, file formats, or other forms of backwards compatibility. examples python python script changes Review Complexity : Medium Generally require more time to grok but manageable by beginner to medium expertise level server testing Everything test related
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bug: JSON Schema - enum behind a $ref generates an object with unrestricted properties
1 participant