Skip to content

LLM 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 projects code. Bots should represent a distinct and singular thing you want to do within your project.

Create a Basic LLM Bot

To create your own bot we are going to use the BaseLlmBot class from the dandy.llm 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.content)
Here's an idea for a book: 'The Memory Thief's Daughter' - A mystery thriller about a young woman who discovers her father was a professional memory thief, stealing secrets from people's minds to solve crimes. When she finds a hidden notebook containing his final job - stealing the memories of a serial killer - she realizes that the killer is still out there and might be targeting her. The story would blend elements of psychological thriller, family mystery, and supernatural fiction as she learns to navigate her own developing memory abilities while racing against time to stop the killer before he can steal her identity too.

Advanced LLM 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 = 'LLAMA_3_2_3B'
    # llm_config_options = LlmConfigOptions(
    #     temperature=0.1,
    #     max_input_tokens=2000,
    #     max_output_tokens=2000,
    #     prompt_retry_count=3,
    #     randomize_seed=True
    # )
    instructions_prompt = (
        Prompt()
        .text('You are a candy design bot and will be given a request to make a new type of candy.')
        .line_break()
        .heading('Rules')
        .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:
        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)
content="In the realm of medieval times, where knights in shining armor rode through cobblestone streets and castles loomed against the sky, there lived a peculiar baker whose specialty was strawberries and cookie dough. The villagers would gather at the market square each morning, drawn not only by the aroma of fresh-baked bread but also by the sweet temptation of this unique dessert. The baker's secret ingredient was a special blend of strawberries that grew wild in the castle gardens, their red juice staining the cookie dough into beautiful swirls. Children would watch in wonder as the baker shaped each cookie with his weathered hands, creating intricate patterns that told stories of knights and dragons. The dessert became so famous that travelers from distant lands would stop at the village just to taste the strawberries and cookie dough, a delightful fusion of simple ingredients transformed by medieval magic."