A Django app for integrating RoboOp-powered chat sessions.
Project description
BotBench
BotBench is a sister project to RoboOp - a microframework for rapid development of Claude-powered agents, applications and assistants. If you haven't had a look at RoboOp yet, go do that now to get a sense of what's possible, and be sure and check out the Cookbook! :)
BotBench offers handy boilerplate to plug RoboOp bots into the web via a Django app that can embed iframe-based chat sessions in webpages. Or you can just use it as a web-based frontend to RoboOp. Note that it's currently fairly experimental - it's not considered production-ready and may not yet play nicely with other websocket-based Django applications.
Setting up
To set up a development environment with Botbench, start by installing into your Django project's virtualenv (or that of a fresh Django project if you just want to use the frontend without adding it to an existing project):
pip install django-botbench
In the settings.py:
INSTALLED_APPS = [
'daphne',
'django_botbench',
# ... existing installed apps here
]
...
ASGI_APPLICATION = '<your-project-name>.asgi.application'
CHANNEL_LAYERS = {
"default": {
"BACKEND": "channels_redis.core.RedisChannelLayer",
"CONFIG": {
"hosts": [("127.0.0.1", 6379)]
},
},
}
BOTBENCH_BOT = 'django_botbench.bots.Bot' # a default Bot with no system prompt for quick start
BOTBENCH_CHATLOGS_DIR = BASE_DIR / 'chatlogs' # for conversation persistence
Make sure the path you nominated for BOTBENCH_CHATLOGS_DIR is a writable directory.
Then, in urls.py:
# ... existing imports
from django.urls import path, include
from django_botbench import views as bb_views
...
urlpatterns = [
# ... existing URL patterns
path('chat/', include('django_botbench.urls')),
path('example/', bb_views.embed_example, name='embed_example'), # optional, see explanation below
]
The embed_example view gives an example of embedding an iframe-based chat box in a webpage. You can adapt this for pages on an existing site or just use it as-is for a quick way to get interacting with your bots.
Next, edit asgi.py:
# ... add the following lines to the end of asgi.py
from django_botbench.asgi import configure_asgi
application = configure_asgi(application)
Finally, you'll need a Redis (as alluded to in the CHANNEL_LAYERS config above). Easiest is to spin one up with Docker:
docker run --rm -p 6379:6379 redis:7
Now you should be good to launch the dev server -
# in your Django dir
./manage.py runserver
If you've used the above setup (and obtained and configured an Anthropic API key as per the RoboOp docs) then you should be able to navigate to http://localhost:8000/example/ and see a chatbox waiting for your input.
Using custom bots
You can pretty much set your custom bots up wherever you like as long as it's on the PYTHONPATH. Let's say you decide to add a bots.py to the top level of your Django project, like so:
# bots.py
from robo import Bot
class EnthusiasticBot(Bot):
sysprompt_text = """You are an enthusiastic chatbot who is excited about everything and really
enjoys using emojis in your chats with users."""
welcome_message = """Hi there! What's cookin'?"""
soft_start = True
You can then specify this chatbot from settings.py:
BOTBENCH_BOT = 'bots.EnthusiasticBot'
Or in the command environment when launching the development server:
BOTBENCH_BOT='bots.EnthusiasticBot' ./manage.py runserver
Frontend-specific Bot attributes
Notice that we've used a couple of attributes on the EnthusasticBot class which aren't mentioned in the Cookbook.
welcome_messageis used to show a starting message in the chatbox. Note that this is not generated by the model (even though for UX reasons it comes in as chunks as if it were) - the model isn't engaged until a message is sent by the user.soft_startis related - when the first message in the conversation is sent by the user, ifsoft_startis set then the conversation history will start with thewelcome_message, which in effect "tricks" the model into thinking that it started the conversation by saying what's in the welcome message. This can help to set the tone (but your mileage may vary - tone should principally be the domain of the system prompt).
If you don't set a welcome message, then a default one will be displayed in the chatbox.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_botbench-0.1.1.tar.gz.
File metadata
- Download URL: django_botbench-0.1.1.tar.gz
- Upload date:
- Size: 15.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a89163c648c355dd5d3788ea75700c82a646b347231c1418fbb3ac3a9df18579
|
|
| MD5 |
4bf421220a4bb2423a8e1c391d8b94ad
|
|
| BLAKE2b-256 |
083da81bb691e867e00da6c92569ec069963c8a86f210793304a6d9154d41f45
|
File details
Details for the file django_botbench-0.1.1-py3-none-any.whl.
File metadata
- Download URL: django_botbench-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7989d93819fa8da350c2cfdbbf584386c27b9ab44e030b10e9c6f340a577f5b6
|
|
| MD5 |
afd080d78a58b1026d41f75060be6e67
|
|
| BLAKE2b-256 |
2a08e27466c149cf8c9c37af7a630e5d3524bec4204ebb1eba308b2375139814
|