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

Add support for null and union types #30

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open

Conversation

posionus
Copy link

@posionus posionus commented Jun 10, 2023

resolves #29, resolves #26

Example:

from jsonformer.format import highlight_values
from jsonformer.main import Jsonformer
from transformers import AutoModelForCausalLM, AutoTokenizer
import torch

print("Loading model and tokenizer...")
model_name = "databricks/dolly-v2-3b"
model = AutoModelForCausalLM.from_pretrained(model_name, use_cache=True, device_map="auto", offload_folder='offload', torch_dtype=torch.float32)
tokenizer = AutoTokenizer.from_pretrained(model_name, use_fast=True, use_cache=True)
print("Loaded model and tokenizer")

car = {
    "type": "object",
    "properties": {
        "make": {"type": "string"},
        "model": {"type": "string"},
        "year": {"type": "number"},
        "trim": {"type": ["string", "null"]},
    },
}

builder = Jsonformer(
    model=model,
    tokenizer=tokenizer,
    json_schema=car,
    debug=True,
    prompt='Make an example car json for Dodge Charger ',
)

print("Generating...")
output = builder()

highlight_values(output)

output:

{
  make: "Dodge",
  model: "Charger",
  year: 1991.0,
  trim: None
}

@ivsanro1
Copy link

This contribution looks great! Is there any news on this? Why wasn't it merged?

@wassname
Copy link

Works for me when I merged it in this branch, where I added probabilities too https://github.com/wassname/prob_jsonformer

@kaiguy23
Copy link

I'd like if this was merged into main as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add Optional and Union types Return empty values
4 participants