Skip to main content

Gitter chat

Puppet

Puppet is a high-level toolkit for building chatbots using conversational components. Try puppet if you want to make your chatbot modular using composable components.

Installation

# optional: create a virtual environment
python3 -m venv myvenv
source myvenv/bin/activate

# install puppet
pip3 install coco-puppet

Additional dependecies

You may want to install dependencies to connect to channels such as telegram and discord or share components on cocohub.

Available dependecies

  • discord - to connect your bot/component to discord
  • telegram - to connect your bot/component to telegram
  • msbf - to connect your bot/component to microsoft bot framework
  • vendor - publish component on cocohub
  • dsl - Hy DSL for nicer syntax when building components/nlu

Examples:

pip install coco-puppet[telegram]
# or for multiple dependecies
pip install coco-puppet[telegram,dsl]

Getting Started

Create your first bot

Puppet components are python coroutines (note the async def)

We take state as the first parameter - which is an object that allow us to interact with the environment the component/bot is running on

async def mybot(state):
    # state.user_input() waits for the next user input
    user_input = await state.user_input()

    # state.say sends a response
    await state.say(user_input)

Paste this code in a file called example.py

Try it in the terminal

python3 -m puppet example.mybot

Channels

Connecting to channels is easy and just requires using regular puppet components

Telegram

Make sure to install puppet with telegram support - pip install coco-puppet[telegram]

Create a new bot and get telegram token from Telegram botfather using this guide: https://core.telegram.org/bots#6-botfather

export TELEGRAM_TOKEN=<Your telegram bot token>
python3 -m puppet.channels.telegram example.mybot

Discord

Make sure to install puppet with discord support - pip install coco-puppet[discord]

Create a new bot account and get a token using this guide: https://discordpy.readthedocs.io/en/latest/discord.html

export DISCORD_KEY=<Your discord bot token>
python3 -m puppet.channels.discord example.mybot

Microsoft bot framework

Make sure to install puppet with microsoft bot framework support - pip install coco-puppet[msbf]

export MicrosoftAppId=<Your bot Microsft App Id>
export MicrosoftAppPassword=<Your bot Microsoft App Password>
python3 -m puppet.channels.msbf example.mybot

Basic Language Understanding

Inside puppet.nlu we have simple patterns to regex compiler to perform basic understanding tasks

Compile simple word patterns to regex

Some Examples:

intent = Intent(
    Pattern("the", "boy", "ate", "an", "apple")
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == False

intent = Intent(
    Pattern("the", "boy", "ate", "an", AnyWords(min=1, max=1))
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == True

intent = Intent(
    Pattern("the", Words("boy", "girl"), "ate", "an", AnyWords(min=1, max=1))
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == True
assert intent("the girl ate an orange") == True
assert intent("the girl ate a banana") == False

intent = Intent(
    Pattern("the", ("boy", "girl"), "ate", WordsRegex(r"an?"), AnyWords(min=1, max=1))
)
assert intent("the boy ate an apple") == True
assert intent("the boy ate an orange") == True
assert intent("the girl ate an orange") == True
assert intent("the girl ate a banana") == True
assert intent("a nice boy ate an apple") == False

intent = Intent(
    Pattern(WILDCARD, Words("boy", "girl"), "ate", WordsRegex(r"an?"), AnyWords(min=1, max=1))
)
assert intent("a nice boy ate an apple") == True

Pattern takes sentence elements and translate each one to optmized regular expression.

Intent groups multiple patterns so if any of the patterns match the intent evals to True

Metadata

Release files for coco-puppet 0.4.3

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

Source distribution (sdist)

Source distribution for coco-puppet 0.4.3
File Size Uploaded Provenance Actions
coco-puppet-0.4.3.tar.gz 26.3 kB Without provenance Details for coco-puppet-0.4.3.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for coco-puppet 0.4.3
File Interpreter ABI Platform Actions
coco_puppet-0.4.3-py3-none-any.whl Python 3 none any Details for coco_puppet-0.4.3-py3-none-any.whl

Total release size: 55.9 kB

Release files / coco-puppet-0.4.3.tar.gz

Download URL coco-puppet-0.4.3.tar.gz
Size 26.3 kB
Tags Source
SHA-256 checksum
How to use checksums
9b4db7df4847d2667e5d55e3e3d0061dc7dbf6f9c6478a27f857b72ff1d2f549
BLAKE2b-256 checksum
How to use checksums
34e0d56e480dab175a5a1ebd5ea6b306c29e07716bf66164e15073067554a4ff
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Release files / coco_puppet-0.4.3-py3-none-any.whl

Download URL coco_puppet-0.4.3-py3-none-any.whl
Size 29.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5674ab69c5e68016dc7fb97b3b9933a3d9019d26e1b793d3189557aebfa110e9
BLAKE2b-256 checksum
How to use checksums
9b69431046400a118b93b370fb048ec0642108344f7e85513c2eaeacdee56fdc
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.8.5

Security for coco-puppet 0.4.3

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