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.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 late father was a specialist in extracting memories from people's minds, but he disappeared years ago under mysterious circumstances. When she finds his old research notes and a half-finished memory extraction device, she begins to uncover not only his secrets but also the truth about her own identity - including whether she inherited his abilities or if someone else is using her as a target. The story would blend elements of psychological thriller, family mystery, and sci-fi concepts while exploring themes of identity, legacy, and what we choose to remember versus forget.
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, LlmConfigOptions
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
)
llm_role = (
Prompt()
.text('You are a candy design bot.')
.line_break()
)
llm_task = (
Prompt('Use the request to make a new type of candy')
)
llm_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:
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="Strawberries and Cookie Dough\n\nIn the medieval realm, where knights rode through cobblestone streets and lords feasted in grand halls, a peculiar delicacy emerged from the kitchens of the nobility. The royal baker, Master Aldric, had discovered a most unusual recipe that would soon become the talk of the castle.\n\nIt began with the finest strawberries, plucked at dawn when the morning dew still clung to their crimson skin. These precious fruits were brought to the kitchen by the gardeners, who had tended them with care throughout the summer months. The strawberries were then carefully prepared, their tops removed and their flesh cut into delicate slices.\n\nBut it was the cookie dough that truly set this dish apart. Master Aldric had perfected a recipe using the finest flour from the local mill, sweetened with honey from the royal beehives. The dough was rolled thin and baked until golden brown, then cooled before being shaped into small, round cookies.\n\nThe magic came when these two elements were combined. The strawberries were layered with the cookie dough, creating a beautiful contrast of textures and flavors. The sweetness of the berries mingled perfectly with the buttery richness of the cookie, creating a dessert that was both simple and extraordinary.\n\nThis creation quickly became known as 'Strawberries and Cookie Dough' throughout the kingdom, served at royal banquets and enjoyed by common folk alike. It was said that those who tasted it would remember the taste of summer in every bite, a reminder of the simple pleasures that made life worth living in the medieval world."