struct Recipe: Generatable {
let name: String
let ingredients: [String]
let steps: [String]
let cookingTime: Int
static var jsonSchema: String {
"""
{
"type": "object",
"properties": {
"name": { "type": "string" },
"ingredients": { "type": "array", "items": { "type": "string" } },
"steps": { "type": "array", "items": { "type": "string" } },
"cookingTime": { "type": "integer" }
},
"required": ["name", "ingredients", "steps", "cookingTime"]
}
"""
}
}
let recipe: Recipe = try await RunAnywhere.generateStructured(
Recipe.self,
prompt: "Create a simple pasta recipe"
)
print("Recipe: \(recipe.name)")
print("Ingredients: \(recipe.ingredients.joined(separator: ", "))")
print("Cook time: \(recipe.cookingTime) minutes")