Skip to content

Bot

What is a Bot

In Dandy, we want to make sure all the things you do have a distinct name to isolate them from your project's code. Bots should represent a singular action you want to do within your project.

Create a Basic Bot

To create your own bot, we are going to use the Bot class from the dandy module.

from dandy import Bot, Prompt


class AssistantBot(Bot):
    def process(self, user_prompt: Prompt | str):
        default_intel = self.llm.prompt_to_intel(
            prompt=user_prompt,
        )

        return default_intel


intel = AssistantBot().process('Can you give me an idea for a book?')

print(intel.text)
The Last Library of Babel: In a future where physical books are illegal and all knowledge is stored in a decentralized, mutable blockchain, a young archivist discovers a pre-collapse library containing original, unaltered copies of history. Hunted by the 'Edit Corps,' who enforce the official narrative, she must decide whether to restore the truth to the public or hide it to prevent societal collapse.

Advanced Bot

When you create a bot it uses all the defaults of the dandy_settings.py file.

Below is an example of how you can customize bots to make sure they work the way you want.

from dandy import BaseIntel, Bot, Prompt


class CandyIntel(BaseIntel):
    short_name: str
    long_name: str
    description: str


class CandyDesignBot(Bot):
    llm_config = 'THINKING'
    role = (
        Prompt()
        .text('You are a candy design bot.')
        .line_break()
    )
    task = 'Use the request to make a new type of candy' # Any were you can use a Prompt you can also use a string
    guidelines = (
        Prompt()
        .list([
            'Make sure you response is sugar based not chocolate based.',
            'Do not include any chocolate based words or phrases in the response.',
            'Incorporate the theme of the request into the response.',
        ])
    )
    intel_class = CandyIntel

    def process(self, user_prompt: Prompt | str, candy_theme: str) -> CandyIntel:
        self.llm.options.temperature = 0.1
        self.llm.options.max_completion_tokens=6000

        prompt = (
            Prompt()
            .heading('Request')
            .prompt(user_prompt)
            .line_break()
            .heading('Theme')
            .prompt(candy_theme)
        )

        return self.llm.prompt_to_intel(
            prompt=prompt,
        )


candy_intel = CandyDesignBot().process(
    user_prompt='Strawberries and Cookie Dough',
    candy_theme='Medieval Times'
)

print(candy_intel)
short_name='Royal Strawberry Knight Bites' long_name="The Knight's Royal Strawberry & Castle Cookie Banquet" description="A medieval-inspired dual-flavor candy honoring the noble houses of the strawberry gardens and the castle kitchens. Features a ruby-red strawberry outer shell encasing a golden cookie dough center, fit for a king's feast. Each piece is shaped like a small castle shield, decorated with royal heraldic patterns in white icing. These treats were said to be the favorite of the King's guard during long watch nights at the castle walls. Sweet, fruity, and satisfyingly chewy with a hint of vanilla bean reminiscent of the royal baker's secret recipes passed down through generations of castle kitchens. Suitable for squires, knights, and royalty alike at any medieval banquet or heraldic celebration. Contains real strawberry pieces and vanilla cookie dough flavored candy center. May the sweetness of the realm be with you! 🏰🍓 (Note: No chocolate, only sugar-based candy as requested.)"