Python chatbot AI that helps in creating a python based chatbot with minimal coding. This provides both bots AI and chat handler and also allows easy integration of REST API's and python function calls which makes it unique and more powerful in functionality. This AI provides numerous features like learn, memory, conditional switch, topic-based conversation handling, etc.
Install from PyPI:
pip install chatbotAI
install from github:
git clone https://github.com/MohanSha/py-Chatbot.git
cd Chatbot
python setup.py install
>>> from chatbot import demo
>>> demo()
Hi, how are you?
> i'm fine
Nice to know that you are fine
> quit
Thank you for talking with me.
>>>
from chatbot import Chat,reflections,multiFunctionCall
import wikipedia
def whoIs(query,sessionID="general"):
try:
return wikipedia.summary(query)
except:
for newquery in wikipedia.search(query):
try:
return wikipedia.summary(newquery)
except:
pass
return "I don't know about "+query
call = multiFunctionCall({"whoIs":whoIs})
firstQuestion="Hi, how are you?"
Chat("examples/Example.template", reflections,call=call).converse(firstQuestion)
- Memory
- Get matched group
- Recursion
- Condition
- Change Topic
- Interact with python function
- REST API integration
- Topic based group
- Learn
- To upper case
- To lower case
- Capitalize
- Previous
{ variable : value }
In think mode
{! variable : value }
{ variable }
%N
Example to get first matched
%1
%!N
Example to get first matched
%!1
Get response as if client said this new statement
{% chat statement %}
It will do a pattern match for statement
{% if condition %} do this first {% elif condition %} do this next {% else %} do otherwise {% endif %}
{% topic TopicName %}
{% call functionName: value %}
{
"APIName":{
"auth" : {
"url":"https://your_rest_api_url/login.json",
"method":"POST",
"data":{
"user":"Your_Username",
"password":"Your_Password"
}
},
"MethodName" : {
"url":"https://your_rest_api_url/GET_method_Example.json",
"method":"GET",
"params":{
"key1":"value1",
"key2":"value2",
...
},
"value_getter":[order in which data has to be picked from json response]
},
"MethodName1" : {
"url":"https://your_rest_api_url/GET_method_Example.json",
"method":"POST",
"data":{
"key1":"value1",
"key2":"value2",
...
},
"value_getter":[order in which data has to be picked from json response]
},
"MethodName2" : {
...
},
...
},
"APIName2":{
...
},
...
}
If authentication is required only then auth
method is needed.The data
and params
defined in pi.json file acts as defult values and all key value pair defined in template file overrides the default value.value_getter
consistes of list of keys in order using which info from json will be collected.
[ APIName:MethodName,Key1:value1 (,Key*:value*) ]
you can have any number of key value pair and all key value pair will override data or params depending on method
, if method
is POST
then it overrides data and if method is GET
then it overrides params
.
{% group topicName %}
{% block %}
{% client %}client says {% endclient %}
{% response %}response text{% endresponse %}
{% endblock %}
...
{% endgroup %}
{% learn %}
{% group topicName %}
{% block %}
{% client %}client says {% endclient %}
{% response %}response text{% endresponse %}
{% endblock %}
...
{% endgroup %}
...
{% endlearn %}
{% up string %}
{% low string %}
{% cap string %}
{% block %}
{% client %}client's statement pattern{% endclient %}
{% prev %}previous bot's statement pattern{% endprev %}
{% response %}response string{% endresponse %}
{% endblock %}