From cc6611647a2326d3b9cb71edf5c23d1f6ec26adf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bar=C4=B1=C5=9F=20=C3=96zmen?= Date: Fri, 1 Nov 2024 18:41:40 +0300 Subject: [PATCH] Recipe example from readme added to examples, with a new pretty string formatting --- examples/cooking_recipe_example.py | 40 ++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 examples/cooking_recipe_example.py diff --git a/examples/cooking_recipe_example.py b/examples/cooking_recipe_example.py new file mode 100644 index 0000000..e54494b --- /dev/null +++ b/examples/cooking_recipe_example.py @@ -0,0 +1,40 @@ +from pydantic import BaseModel +import simplemind as sm + + +class InstructionStep(BaseModel): + step_number: int + instruction: str + +class RecipeIngredient(BaseModel): + name: str + quantity: float + unit: str + +class Recipe(BaseModel): + name: str + ingredients: list[RecipeIngredient] + instructions: list[InstructionStep] + + def __str__(self) -> str: + output = f"\n=== {self.name.upper()} ===\n\n" + + output += "INGREDIENTS:\n" + for ing in self.ingredients: + output += f"• {ing.quantity} {ing.unit} {ing.name}\n" + + output += "\nINSTRUCTIONS:\n" + for step in self.instructions: + output += f"{step.step_number}. {step.instruction}\n" + + return output + + +recipe = sm.generate_data( + "Write a recipe for chocolate chip cookies", + llm_model="gpt-4o-mini", + llm_provider="openai", + response_model=Recipe, +) + +print(recipe) \ No newline at end of file