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.
Traceback (most recent call last):
File "/app/.heroku/python/lib/python3.11/site-packages/markdown_exec/_internal/formatters/python.py", line 89, in _run_python
exec_python(code, code_block_id, exec_globals)
File "/app/.heroku/python/lib/python3.11/site-packages/markdown_exec/_internal/formatters/_exec_python.py", line 26, in exec_python
exec(compiled, exec_globals) # noqa: S102
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "<code block: session bot; n1>", line 13, in <module>
intel = AssistantBot().process('Can you give me an idea for a book?')
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/dandy/bot/recorder.py", line 57, in wrapper
result = method(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^
File "<code block: session bot; n1>", line 6, in process
default_intel = self.llm.prompt_to_intel(
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/dandy/llm/service.py", line 67, in prompt_to_intel
return self._llm_connector.prompt_to_intel(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/dandy/llm/connector.py", line 136, in prompt_to_intel
response_intel_object = self._request_to_intel()
^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/dandy/llm/connector.py", line 156, in _request_to_intel
self._http_request_to_response_str()
File "/workspace/dandy/llm/connector.py", line 66, in _http_request_to_response_str
self.response_str = http_connector.request_to_response(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/workspace/dandy/http/connector.py", line 37, in request_to_response
raise HttpConnectorRecoverableError(message)
dandy.http.exceptions.HttpConnectorRecoverableError: HttpConnector request failed with status code 400 and the following message "Bad Request" and body text "{"error":{"message":"/chat/completions: Invalid model name passed in model=stratus.smart. Call `/v1/models` to view available models for your key.","type":"None","param":"None","code":"400","provider_specific_fields":{"error":"/chat/completions: Invalid model name passed in model=stratus.smart. Call `/v1/models` to view available models for your key."}}}" after 4 attempts
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='Medieval Strawberry Cookie Dough Sugar Puff' long_name='A sugar-based candy inspired by medieval feasts, with a strawberry sugar shell and a cookie dough sugar center' description='This candy is shaped like a tiny castle and coated in sparkling strawberry sugar. Inside, a soft sugar core is flavored like cookie dough, giving it a sweet, nostalgic taste fit for a royal banquet in Medieval Times. The candy is finished with a small sugar crown and golden sugar swirls to evoke a festive medieval celebration without using any chocolate-based ingredients or flavors. It is made entirely from sugar-based components, including sugar, strawberry flavoring, cookie dough flavoring, and natural colors, and is designed to be a playful, sugar-based treat for fans of strawberries, cookie dough, and medieval themes.'