Giter Site home page Giter Site logo

alexmhack / django-rasa-sockets Goto Github PK

View Code? Open in Web Editor NEW
12.0 4.0 4.0 2.86 MB

Rasa Chatbot using Django backend and Sockets for communication

Python 2.48% CSS 3.55% JavaScript 93.32% HTML 0.66%
django2 rasa socket-io chatbot socket django-backend django-rasa-sockets browserify rasa-chatbot

django-rasa-sockets's Introduction

NOTE: Currently not working. This repo is currently under development, open issue for any question.

Django-Rasa-Sockets

Rasa Chatbot using Django backend and Sockets for communication

Assuming you have a starter django project with static and templates folder configured with django and a root index view rendering index.html file from templates folder

A basic rasa core and rasa nlu made chatbot with socket.io setup is inside rasachat folder of the repo

Steps to setup socket.io

  1. Install NodeJS from official site.

  2. Inside root folder run command

    npm init
    

    You will be asked to enter details for the project, you can enter whatever you want. This command will create a package.json file.

  3. Install socket.io using npm

    npm install --save socket.io
    
  4. Install browserify using npm globally

    npm install -g browserify
    
  5. Now in static/js folder, create two files, one for backend javascript code and another for frontend which will be created by browserify

    chat.js 	-> backend written by us
    bundle.js 	-> frontend compiled by browserify
    
  6. When you have your backend javascript code ready with socket.io setup run browserify command to compile file for frontend

    cd static/js
    browserify chat.js -o bundle.js
    
  7. In templates/index.html file load static and add script tag for browserify compiled bundle.js file

    <script src="{% static 'js/bundle.js' %}" type="text/javascript" charset="utf-8"></script>
    

    You can reuse the javascript code from the repo

  8. Run the django server from root folder

    python manage.py runserver
    

    Run the rasa core server from rasachat folder

    cd rasachat
    python bot.py 	-> python script for rasa socket server
    # or you can run using run script
    python -m rasa_core.run -d models/dialogue -u models/current/nlu --port 5500 --credentials credentials.yml 		-> Using run script
    

    interact with chatbot using sockets and django.

Usage

git clone https://github.com/Alexmhack/Django-Rasa-Sockets

Replace the rasachat folder with your rasa core chatbot and follow the ** 8th step**

Locate to 127.0.0.1:8000/ and click on button at bottom right and enter hey in the input.

django-rasa-sockets's People

Contributors

alexmhack avatar dependabot[bot] avatar

Stargazers

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

Watchers

 avatar  avatar  avatar  avatar

django-rasa-sockets's Issues

Run actions with socket.io

I successfully run your instructions on setting up the chat. However I am not sure how I can run my custom actions and where to put the action folder in the directory. Right now my bot can respond only to simple text message but not to action message (see image below). I put the action folder in rasachat like this: rasachat/actions/tell_time.py with tell_time.py:

from rasa_core_sdk import Action
from rasa_core_sdk.events import SlotSet
from datetime import datetime
import time


class Inform(Action):

    def name(self):
        return "tell_time"

    def run(self, dispatcher, tracker, domain):
        infoname = tracker.get_slot('info_name')
        response = "The time is " + str(datetime.strftime(datetime.now(), '%H:%M:%S'))

        dispatcher.utter_message(response)
        return [SlotSet("tell_time", tell_time)]

I trained the bot intent and story to respond to the time question with calling tell_time.py. Not sure what I am missing right now. I tried adding an action endpoint to my bot.py but it did't work either:


from rasa_core.agent import Agent
from rasa_core.channels.socketio import SocketIOInput
from rasa_core.interpreter import RasaNLUInterpreter
from rasa_core.utils import EndpointConfig

# load your trained agent
interpreter = RasaNLUInterpreter("models/nlu/default/bot/")
MODEL_PATH = "models/dialogue"
action_endpoint = EndpointConfig(url="http://127.0.0.1:5500/webhook")
agent = Agent.load(MODEL_PATH, interpreter=interpreter,
                   action_endpoint=action_endpoint)

input_channel = SocketIOInput(
	# event name for messages sent from the user
	user_message_evt="user_uttered",
	# event name for messages sent from the bot
	bot_message_evt="bot_uttered",
	# socket.io namespace to use for the messages
	namespace=None
)

# set serve_forever=False if you want to keep the server running
s = agent.handle_channels([input_channel], 5500, serve_forever=True)

Any help appreciated and nice project by the way. Thanks in advance.

grafik

the chatbot didn't respond

thank you for the code it's very helpful
but my bot didn't respond
rasa =1.1.4

from rasa.core.agent import Agent
from rasa.core.channels.socketio import SocketIOInput
from rasa.core.agent import Agent
from rasa.utils.endpoints import EndpointConfig
interpreter ="models/20190809-043054/nlu"
MODEL_PATH = "models/20190809-043054/core"
action_endpoint = EndpointConfig(url="http://127.0.0.1:5055/webhook")
agent = Agent.load(MODEL_PATH, interpreter=interpreter,
action_endpoint=action_endpoint)
input_channel = SocketIOInput(
user_message_evt="user_uttered",
bot_message_evt="bot_uttered",
namespace=None
)
s = agent.handle_channels([input_channel], http_port=5500,route='/webhooks/',cors="*")

i run : rasa run actions // python bot.py // python manage.py runserver
i can tape a message but i didn't get a response can you help me to fix it thank you

SystemError: unknown opcode (Bot not responding..)

Hi , when i send the message to bot, it will not respond. It will show an error like

Traceback (most recent call last):
File "bot.py", line 17, in
s = agent.handle_channels([input_channel], 5500, serve_forever=True)
File "C:\Users\Pulivarthi\AppData\Local\Programs\Python\Python36\lib\site-packages\rasa_core\agent.py", line 566, in handle_channels
http_server.serve_forever()
File "C:\Users\Pulivarthi\AppData\Local\Programs\Python\Python36\lib\site-packages\gevent\baseserver.py", line 369, in serve_forever
self._stop_event.wait()
File "src\gevent\event.py", line 127, in gevent._event.Event.wait
File "src\gevent_abstract_linkable.py", line 192, in gevent.__abstract_linkable.AbstractLinkable._wait
File "src\gevent_abstract_linkable.py", line 165, in gevent.__abstract_linkable.AbstractLinkable._wait_core
File "src\gevent_abstract_linkable.py", line 169, in gevent.__abstract_linkable.AbstractLinkable._wait_core
File "src\gevent_greenlet_primitives.py", line 60, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src\gevent_greenlet_primitives.py", line 60, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src\gevent_greenlet_primitives.py", line 64, in gevent.__greenlet_primitives.SwitchOutGreenletWithLoop.switch
File "src\gevent__greenlet_primitives.pxd", line 35, in gevent.__greenlet_primitives._greenlet_switch
SystemError: unknown opcode

How to find this please help me

Getting Error: rasa.nlu.model.UnsupportedModelError

when i am run the py bot.py it showing error like this

rasa.nlu.model.UnsupportedModelError: The model version is to old to be loaded by this Rasa NLU instance. Either retrain the model, or run withan older version. Model version: 0.0.0 Instance version: 1.0.9

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.