Giter VIP home page Giter VIP logo

chatbot's Introduction

Downloads PyPI version Upload Python Package CodeQL

ChatBotAI

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.

Demo GUI

Demo Clothing assistance Remainder

Installation

Install from PyPI:

pip install chatbotAI

install from github:

git clone https://github.com/ahmadfaizalbh/Chatbot.git
cd Chatbot
python setup.py install

Demo

>>> 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.
>>> 

Sample Code (with wikipedia search API integration)

from chatbot import Chat, register_call
import wikipedia


@register_call("whoIs")
def who_is(session, query):
    try:
        return wikipedia.summary(query)
    except Exception:
        for new_query in wikipedia.search(query):
            try:
                return wikipedia.summary(new_query)
            except Exception:
                pass
    return "I don't know about "+query

first_question="Hi, how are you?"
Chat("examples/Example.template").converse(first_question)

For Detail on how to build Facebook messenger bot checkout Facebook Integration.ipynb

For Jupyter notebook Chatbot checkout Infobot built using NLTK-Chatbot

Sample Apps

  1. A sample facebook messenger bot built using messengerbot, Django and NLTK-Chatbot is available here Facebook messenger bot
  2. A sample microsoft bot built using Microsoft Bot Connector Rest API - v3.0, Django and NLTK-Chatbot is available here Micosoft Chatbot

List of feature supported in bot template

  1. Memory
  2. Get matched group
  3. Recursion
  4. Condition
  5. Change Topic
  6. Interact with python function
  7. REST API integration
  8. Topic based group
  9. Learn
  10. To upper case
  11. To lower case
  12. Capitalize
  13. Previous

Memory

Set Memory

{ variable : value }

In think mode

{! variable : value }

Get Memory

{ variable }

Get matched group

for grouping in regex refer Python regular expression docs

Get Nth matched group of client pattern

%N

Example to get first matched

%1

Get matching named group of client pattern

%Client_pattern_group_name

Example to get matching named group person

%person

Get Nth matched group of bots message pattern

%!N

Example to get first matched

%!1

Get matching named group of bots message pattern

%!Bot_pattern_group_name

Example to get matching named group region

%!region

Recursion

Get response as if client said this new statement

{% chat statement %}

It will do a pattern match for statement

Condition

{% if condition %} do this first {% elif condition %} do this next {% else %} do otherwise {% endif %}

Change Topic

{% topic TopicName %}

Interact with python function

In python
@register_call("functionName")
def function_name(session, query):
    return "response string"
In template
{% call functionName: value %}

REST API integration

In API.json file

{
   "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.

In Template file

[ 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.

Topic based group

{% group topicName %}
  {% block %}
      {% client %}client says {% endclient %}
      {% response %}response text{% endresponse %}
  {% endblock %}
  ...
{% endgroup %}

Learn

{% learn %}
  {% group topicName %}
    {% block %}
        {% client %}client says {% endclient %}
        {% response %}response text{% endresponse %}
    {% endblock %}
    ...
  {% endgroup %}
  ...
{% endlearn %}

To upper case

{% up string %}

To lower case

{% low string %}

Capitalize

{% cap string %}

Previous

{% block %}
    {% client %}client's statement pattern{% endclient %}
    {% prev %}previous bot's statement pattern{% endprev %}
    {% response %}response string{% endresponse %}
{% endblock %}

Chatbot AI flow Diagram

chatbot's People

Contributors

ahmadfaizalbh avatar arunkumarp93 avatar bhava08 avatar faiz-anjum avatar padmalcom avatar realpacific avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

chatbot's Issues

HI

I try to open the chatbot project in vs code but it is not opening can I get the step, please

ASCII codec can't decode bye

While importing
from chatbot import Chat, reflections, multiFunctionCall
following error coming.
Stacktrace for the error:
File "/home/jsahil/chat_app/alpha/views.py", line 3, in
from chatbot import Chat, reflections, multiFunctionCall
File "/home/jsahil/anaconda3/envs/fastai-cpu/lib/python3.6/site-packages/chatbot/init.py", line 4, in
from .spellcheck import correction,WORDS
File "/home/jsahil/anaconda3/envs/fastai-cpu/lib/python3.6/site-packages/chatbot/spellcheck/init.py", line 15, in
WORDS = Counter(words(open(path.join(path.dirname(path.abspath(file)),'words.txt')).read()))
File "/home/jsahil/anaconda3/envs/fastai-cpu/lib/python3.6/encodings/ascii.py", line 26, in decode
return codecs.ascii_decode(input, self.errors)[0]
UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position 6490626: ordinal not in range(128)

Please suggest

Add examples for features in template files

I use chatbotai successfully, but in a very simple way (mostly, the client says something and the bot respondes).

Nevertheless, I'm very curious regarding all the features listed in "List of feature supported in bot template" and I'd like to use them but I'm missing some clear examples. Could you provide some?

Get confidence score for selected answer

Hi, I'm running chatbotai in combination with snips-nlu whereas chatbotai is the first choice and whenever an answer cannot be parsed, snips-nlu should be used and try to parse the user input. The problem is that I do not know when no pattern from chatbot ai matches. Is there a way to get such a score/boolean? Otherwise, I'd like to open a feature request.

Learning by chatting

Hey dude!

I looove your project, and want to integrate this amazing module into my discord bot.. Is there a way to train it by chatting with it? And also, I have read some issues here, and would say that some docs would be really really really appreciated... And also would be better if u can tell how can I use the learning things so that it remembers different things of each person....

Sorry for all these requests, but also, thanks in advance!

AttributeError: 'dict' object has no attribute '__dict__'

Describe the bug
After importing demo from chatbot as shown in demo. When I run the function demo(). I get this:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "C:\Users\Babban\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\chatbot\__init__.py", line 827, in demo
    Chat().converse(firstQuestion)
  File "C:\Users\Babban\AppData\Local\conda\conda\envs\tensorflow\lib\site-packages\chatbot\__init__.py", line 103, in __init__
    elif 'unicode' in __builtins__.__dict__ and type(pairs) == __builtins__.__dict__['unicode']:
AttributeError: 'dict' object has no attribute '__dict__'

screenshot_49

A more detailed explanation of Topic based group,Learn

Thanks so much for the bot it is very helpful to me
There are a number of functions that I do not understand how and for what their use and you may be able to add a brief explanation

  • Topic based group
  • Learn
  • To upper case
  • To lower case
  • Capitalize

conditional Chatbot response

Hi ! I'm trying to work with your Chatbot and I was wondering if there is a posibility to only make the Bot answering under a certain condition. I tried it with following template but it didn't work:

{% block %}
{% client %}(?P.*){% endclient %}
{% if {% call Myfuncion:%query%} %}
{% response %}My answer.{% endresponse %}
{% endif %}
{% endblock %}

The funcion Myfuncion returns True / False depending on the client's query.
Thank you in advance for your help!

Chat not found

Describe the bug
When I do, from chatbot import Chat, it raises an error

To Reproduce
Steps to reproduce the behavior:

  1. Make a new Python file
  2. Do, from chatbot import Chat

Expected behavior
It should import without any error

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows
  • Browser Chrome

Smartphone (please complete the following information):

  • Device: [e.g. iPhone6]
  • OS: [e.g. iOS8.1]
  • Browser [e.g. stock browser, safari]
  • Version [e.g. 22]

Additional context
Traceback (most recent call last):
File "main.py", line 2, in
from chatbot import Chat, register_call
ImportError: cannot import name 'Chat' from 'chatbot' (/opt/virtualenvs/python3/lib/python3.8/site-packages/chatbot/init.py)

This is the error

Plugin System

Are you considering making a plugin system with a marketplace? It would go well with your UI, and us users could change the program to our will.

Load all templates from a folder

Hi, I wrote an extensible chatbot for which developers can add dialogs including the corresponding python modules. So far, I can create a Chat instance using one main template and a default template. It would be nice if I could optionally specify a main folder so that your fantastic library loads all template files from this folder.

Functions registered via register_call can not access variables

Hi, first of all thank you for your great library. I have several variables managed in my python script and I try to access those variables in functions that I register using register_call. But it seems that they are never updated within the function.

An example:

current_speaker = None

@register_call("iam")
def iam(name, session_id = "general"):
	if current_speaker == None:
		return "Nice to meet you " + name
	else:
		return "I already know you " + name

Here, current_speaker is always None, no matter if I set it or not.

What are my options to get a global variable into such a function?

Access variables from python code

Hi, is it possible to access and set a memory variable from outside the template in the python code? It would be nice to have this feature.

Where is Chat, register_call functions?

Describe the bug
After cloning the code, installing the setup file when I run the demo code for wiki search, I am getting ImportError: cannot import name 'register_call' from 'chatbot' error

To Reproduce
Steps to reproduce the behavior:

  1. run Example.py

Expected behavior
code should run

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: windows 10
  • Python 3.7
  • Browser Chrome

Additional context
from chatbot import Chat, register_call ImportError: cannot import name 'register_call' from 'chatbot'

Execution

Hi,

I would like to execute chatbot program without linux cmd. I'm using windows 10.
I cloned and installed it but I tried to execute setup.py like this way:
C:\Windows\System32\Chatbot>py setup.py
but the response was:
C:\Windows\System32\Chatbot>chatbot import demo
"chatbot" no se reconoce como un comando interno o externo,
programa o archivo por lotes ejecutable.

Thanks!

Can not call function without parameters

It seems that I cannot call a function without parameter. I have a very simple dialog ("what time is it?", "it is 12 o'clock") that does not require a parameter. When I create a block like:

{% block %}
    {% client %}(what time is it){% endclient %}
    {% response %}{% call time %}{% endresponse %}
{% endblock %}

The response is simply "time" instead of the result of calling time. When I add a dummy variable and use {% call time:0 %} it works well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.