Skip to main content

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 created with django-admin startproject <projectname> 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.BBBot' # 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 start 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 django_botbench import BBBot

class EnthusiasticBot(BBBot):
    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 considerations

Notice that we've used a couple of attributes on the EnthusasticBot class which aren't mentioned in the RoboOp Cookbook, because they're not applicable to the CLI-oriented usage context.

  • welcome_message is 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_start is related - when the first message in the conversation is sent by the user, if soft_start is set then the Conversation history will start with the welcome_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.

We're also deriving the EnthusiasticBot not from the base class robo.Bot but rather from django_botbench.BBBot. BBBot (as in "BotBench Bot") adds a method for deriving the bot's field arguments from the Django Websocket's scope object, namely derive_field_args_from_scope. For example:

class GreeterBot(BBBot):
    sysprompt_text = """You are a helpful greeter. If you know the user's first name you 
                        greet them by name at the start of the conversation and then 
                        incorporate their name into each subsequent message. Besides that, 
                        you generally help them with any enquiries they have.
                        The user's first name is "{{USER_FIRST_NAME}}"."""
    
    fields = ['USER_FIRST_NAME']
    
    def derive_field_args_from_scope(self, scope):
        try:
            user_firstname = scope['user'].first_name
        except Exception as exc:
            user_firstname = 'UNKNOWN'
        return {'USER_FIRST_NAME': user_firstname}

This bot will greet the user by name if they're logged in and their first_name field is set.

Metadata

Release files for django-botbench 0.1.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-botbench 0.1.5
File Size Uploaded Provenance Actions
django_botbench-0.1.5.tar.gz 16.9 kB Without provenance Details for django_botbench-0.1.5.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for django-botbench 0.1.5
File Interpreter ABI Platform Actions
django_botbench-0.1.5-py3-none-any.whl Python 3 none any Details for django_botbench-0.1.5-py3-none-any.whl

Total release size: 34.2 kB

Release files / django_botbench-0.1.5.tar.gz

Download URL django_botbench-0.1.5.tar.gz
Size 16.9 kB
Tags Source
SHA-256 checksum
How to use checksums
6cf9e65541d68f4f03885104108c604e748c8b458518636531439dafabc03273
BLAKE2b-256 checksum
How to use checksums
7ffc708ad9b458cca170aa09c07d6211bce8feced10453c19bce36a4d8d03439
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.0

Release files / django_botbench-0.1.5-py3-none-any.whl

Download URL django_botbench-0.1.5-py3-none-any.whl
Size 17.2 kB
Tags Python 3
SHA-256 checksum
How to use checksums
bc96f8b65f8ef37e84df981c1300e47608217d6b8042a2ee2f552e25e7b26664
BLAKE2b-256 checksum
How to use checksums
691534fea15da22a1b663ee953293a72ea60487200013f8ce7cec0477f806878
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.0

Security for django-botbench 0.1.5

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page