Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions examples/quick_start_guide.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
"""Quick Start Guide with Practical Examples"""

from jsonformer import Jsonformer
from transformers import AutoModelForCausalLM, AutoTokenizer

# Load small model for quick testing
print("Loading model (this may take a minute first time)...")
model = AutoModelForCausalLM.from_pretrained("microsoft/DialoGPT-small")
tokenizer = AutoTokenizer.from_pretrained("microsoft/DialoGPT-small")
if tokenizer.pad_token is None:
tokenizer.pad_token = tokenizer.eos_token

# Example 1: Simple User Profile
print("\n=== Example 1: User Profile ===")
user_schema = {
"type": "object",
"properties": {
"username": {"type": "string"},
"age": {"type": "number"},
"is_premium": {"type": "boolean"},
"interests": {"type": "array", "items": {"type": "string"}},
},
}
jsonformer = Jsonformer(model, tokenizer, user_schema, "Generate a user profile:")
print(jsonformer())

# Example 2: Product Information
print("\n=== Example 2: Product Info ===")
product_schema = {
"type": "object",
"properties": {
"name": {"type": "string"},
"price": {"type": "number"},
"in_stock": {"type": "boolean"},
"tags": {"type": "array", "items": {"type": "string"}},
},
}
jsonformer = Jsonformer(
model, tokenizer, product_schema, "Generate product information:"
)
print(jsonformer())

print("\nAll examples completed!")