Skip to content

Cookie Recipe

This example shows how to create a cookie recipe llm bot using dandy.

Intel

We need to create some intel for our bot to use to properly structure the recipe.

cookie/intelligence/intel/cookie_intel.py
from typing_extensions import List

from dandy.intel import BaseIntel


class CookieRecipeIngredientIntel(BaseIntel):
    name: str
    unit_type: str
    quantity: float


class CookieRecipeIntel(BaseIntel):
    name: str
    description: str
    ingredients: List[CookieRecipeIngredientIntel]
    instructions: str

Bot

The cookie recipe bot is built on the BaseLlmBot class and uses class methods as we expect this bot to always be the same.

cookie/intelligence/bots/cookie_recipe_llm_bot.py
from dandy.llm import Prompt, BaseLlmBot
from example.cookie.intelligence.intel.cookie_recipe_intel import CookieRecipeIntel


class CookieRecipeLlmBot(BaseLlmBot):
    # If you do not set a config, the "DEFAULT" config from your "dandy_settings.py" will be used

    # config = 'LLAMA_3_1_8B'
    config = 'DEEPSEEK_R1_14B'

    # You can also override settings per bot.

    seed = 25
    max_output_tokens = 1000

    # This is the instructions used by the system message when the llm is prompted

    instructions_prompt = (
        Prompt()
        .title('You are a cookie recipe bot.')
        .text('Your job is to follow the instructions provided below.')
        .unordered_random_list([
            'Create a cookie based on the users input',
            'Make sure the instructions are easy to follow',
            'Names of recipe should be as short as possible',
        ])
    )

    # the process function is required for all dandy handlers (bots and workflows) for debug and exception handling

    @classmethod
    def process(cls, prompt: Prompt) -> CookieRecipeIntel:
        return cls.process_prompt_to_intel(
            prompt=prompt,
            intel_class=CookieRecipeIntel,
        )

Main

Simply import your cookie recipe bot and feed the process function a Prompt object.

main.py
from dandy.llm import Prompt

from cookie.intelligence.bots.cookie_recipe_llm_bot import CookieRecipeLlmBot

cookie_recipe_intel = CookieRecipeLlmBot.process(
    prompt=Prompt().text('I love broccoli and oatmeal!'),
)

print(cookie_recipe_intel.model_dump_json(indent=4))

Output

After the bot process the llm response you will be given back a cookie recipe intel object.

{
  "name": "Broccoli Oatmeal Cookies",
  "description": "A delicious cookie recipe featuring the flavors of broccoli and oatmeal.",
  "ingredients": [
    {
      "name": "All-purpose flour",
      "unit_type": "cups",
      "quantity": 2.5
    },
    {
      "name": "Rolled oats",
      "unit_type": "cups",
      "quantity": 1.0
    },
    {
      "name": "Brown sugar",
      "unit_type": "cups",
      "quantity": 0.5
    },
    {
      "name": "Granulated sugar",
      "unit_type": "cups",
      "quantity": 0.25
    },
    {
      "name": "Large eggs",
      "unit_type": "pieces",
      "quantity": 1.0
    },
    {
      "name": "Melted butter",
      "unit_type": "tablespoons",
      "quantity": 1.0
    },
    {
      "name": "Steamed broccoli florets",
      "unit_type": "cups",
      "quantity": 0.5
    },
    {
      "name": "Vanilla extract",
      "unit_type": "teaspoons",
      "quantity": 1.0
    }
  ],
  "instructions": "Preheat oven to 375°F (190°C). Line a baking sheet with parchment paper. In a medium bowl, whisk together flour, oats, brown sugar, and granulated sugar. In a large bowl, whisk together eggs, melted butter, steamed broccoli florets, and vanilla extract. Add the dry ingredients to the wet ingredients and stir until combined. Scoop tablespoon-sized balls of dough onto the prepared baking sheet, leaving 2 inches of space between each cookie. Bake for 10-12 minutes or until lightly golden brown."
}