Package: coco-puppet
PuppetPuppet is a high-level toolkit for building chatbots using conversational components.
Try puppet if you want to make your chatbot modular using composable components.InstallationGetting StartedChannelsNLUInstallation# optional: create a virtual environmentpython3-mvenvmyvenvsourcemyvenv/bin/activate# install puppetpip3installcoco-puppetAdditional dependeciesYou may want to install dependencies to connect to channels such as telegram and discord or share components on cocohub.Available dependeciesdiscord - to connect your bot/component to discordtelegram - to connect your bot/component to telegrammsbf - to connect your bot/component to microsoft bot frameworkvendor - publish component on cocohubdsl - Hy DSL for nicer syntax when building components/nluExamples:pipinstallcoco-puppet[telegram]# or for multiple dependeciespipinstallcoco-puppet[telegram,dsl]Getting StartedCreate your first botPuppet components are python coroutines (note theasync def)We takestateas the first parameter - which is an object that allow us to interact with the environment the component/bot is running onasyncdefmybot(state):# state.user_input() waits for the next user inputuser_input=awaitstate.user_input()# state.say sends a responseawaitstate.say(user_input)Paste this code in a file called example.pyTry it in the terminalpython3-mpuppetexample.mybotChannelsConnecting to channels is easy and just requires using regular puppet componentsTelegramMake 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-botfatherexportTELEGRAM_TOKEN=<Yourtelegrambottoken>
python3-mpuppet.channels.telegramexample.mybotDiscordMake 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.htmlexportDISCORD_KEY=<Yourdiscordbottoken>
python3-mpuppet.channels.discordexample.mybotMicrosoft bot frameworkMake sure to install puppet with microsoft bot framework support -pip install coco-puppet[msbf]exportMicrosoftAppId=<YourbotMicrosftAppId>exportMicrosoftAppPassword=<YourbotMicrosoftAppPassword>
python3-mpuppet.channels.msbfexample.mybotBasic Language UnderstandingInside puppet.nlu we have simple patterns to regex compiler to perform basic understanding tasksCompile simple word patterns to regexSome Examples:intent=Intent(Pattern("the","boy","ate","an","apple"))assertintent("the boy ate an apple")==Trueassertintent("the boy ate an orange")==Falseintent=Intent(Pattern("the","boy","ate","an",AnyWords(min=1,max=1)))assertintent("the boy ate an apple")==Trueassertintent("the boy ate an orange")==Trueintent=Intent(Pattern("the",Words("boy","girl"),"ate","an",AnyWords(min=1,max=1)))assertintent("the boy ate an apple")==Trueassertintent("the boy ate an orange")==Trueassertintent("the girl ate an orange")==Trueassertintent("the girl ate a banana")==Falseintent=Intent(Pattern("the",("boy","girl"),"ate",WordsRegex(r"an?"),AnyWords(min=1,max=1)))assertintent("the boy ate an apple")==Trueassertintent("the boy ate an orange")==Trueassertintent("the girl ate an orange")==Trueassertintent("the girl ate a banana")==Trueassertintent("a nice boy ate an apple")==Falseintent=Intent(Pattern(WILDCARD,Words("boy","girl"),"ate",WordsRegex(r"an?"),AnyWords(min=1,max=1)))assertintent("a nice boy ate an apple")==TruePatterntakes sentence elements and translate each one to optmized regular expression.Intentgroups multiple patterns so if any of the patterns match the intent evals toTrue