From 8f9036fa32d212b43d948136918e4816bd5c0466 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:40:08 +0300 Subject: [PATCH 1/3] fix bug. send_hook changed to pre_send_hook --- examples/math_plugin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/math_plugin.py b/examples/math_plugin.py index 436d04f..0ed7da1 100644 --- a/examples/math_plugin.py +++ b/examples/math_plugin.py @@ -2,7 +2,7 @@ from _context import sm class MathPlugin(sm.BasePlugin): - def send_hook(self, conversation: sm.Conversation): + def pre_send_hook(self, conversation: sm.Conversation): last_user_message = conversation.get_last_message(role="user") if last_user_message is None: return 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 2/3] 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 From c6c7f2ac0963f9fd249923e7903b7dd4042ad041 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:42:54 +0300 Subject: [PATCH 3/3] add print result as comments --- examples/cooking_recipe_example.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/examples/cooking_recipe_example.py b/examples/cooking_recipe_example.py index e54494b..1d8990c 100644 --- a/examples/cooking_recipe_example.py +++ b/examples/cooking_recipe_example.py @@ -37,4 +37,30 @@ recipe = sm.generate_data( response_model=Recipe, ) -print(recipe) \ No newline at end of file +print(recipe) +# Expected output is something like this: +# +# === CHOCOLATE CHIP COOKIES === +# +# INGREDIENTS: +# • 2.25 cups all-purpose flour +# • 1.0 teaspoon baking soda +# • 0.5 teaspoon salt +# • 1.0 cup unsalted butter +# • 0.75 cup sugar +# • 0.75 cup brown sugar +# • 1.0 teaspoon vanilla extract +# • 2.0 large eggs +# • 2.0 cups semi-sweet chocolate chips +# +# INSTRUCTIONS: +# 1. Preheat your oven to 350°F (175°C). +# 2. In a small bowl, combine flour, baking soda, and salt; set aside. +# 3. In a large bowl, cream together the butter, sugar, and brown sugar until smooth. +# 4. Beat in the vanilla extract and eggs, one at a time. +# 5. Gradually blend in the flour mixture until just combined. +# 6. Stir in the chocolate chips. +# 7. Drop by rounded tablespoon onto ungreased cookie sheets. +# 8. Bake for 9 to 11 minutes, or until edges are golden. +# 9. Let cool on the cookie sheet for a few minutes before transferring to wire racks to cool completely. +