Code Monkey home page Code Monkey logo

symptom-checker-chatbot-example's Introduction

Health Check-up Chatbot Example

This here is a simple example of how a symptom-checking chatbot may be built using Infermedica API and 300 lines of Python code.

The project is merely a tutorial. It's not intended to be a production-ready solution. The entire interaction takes place in console. No intent recognition is performed and the bot is pretty ignorant when it comes to understanding user's actions other than blindly following the instructions.

If you intend on writing your chatbot in Python, we strongly recommed using our offical Python API client.

How to run the example

You'll need an Infermedica account. If you don't have one, please register at https://developer.infermedica.com.

The code is written in Python 3. First, install the requirements (preferably within a dedicated virtualenv):

pip install -r requirements.txt

To run the demo:

python chat.py APP_ID:APP_KEY

Please use the APP_ID and APP_KEY values from your Infermedica account.

The demo starts by asking for patient's age and sex. Then you're expected to provide complaints. You can provide complaints in one or multiple messages. You need to reply with an empty string to let the bot know you're finished with the complaints. A real-life bot should understand replies such as I don't know, that's it, etc.

The complaints are analysed by using the /parse endpoint of the Infermedica API.

The bot will start asking diagnostic questions obtained from the /diagnosis endpoint of the Infermedica API. At this stage, answers of yes (or y), no (n) or dont know (or skip) are expected. The interview will finish when the diagnostic API responds with a should_stop flag. This flag is raised when the engine reaches conclusion that enough is known or there have already been too many questions to bother the user further.

See an example session.

What is not covered here

  1. Multiple users and event-driven logic. A proper chatbot (such as https://symptomate.com/chatbot/) needs to handle multiple users. You need to have a database where you'd keep the state of conversation with each user and have it updated each time an interaction takes place. Also, a real chatbot will need to handle events coming from external components (e.g. your own chatbot front-end or third-party platform such as Google Assistant). So, the bot back-end should probably be a REST app (e.g. made with Flask or UWSGI). In such a setting, this would be an event-driven program. The application would expose a handle message endpoint that would be called with user id, user message text and possibly some settings. The endpoint would be responsible for retrieving the state of conversation with the requesting user, handling the user's message, altering the state, storing the altered state back in the database and returning response messages.

  2. Intent recognition. The users don't always do what they're told. Also, language is flexible. Some basic intent recognition will be useful to know when the user wants to proceed to next stage, to quit the conversation, perhaps restart or request for help. In the most crude form this could be handled by a list of most likely answers or regular expressions; but in the long run you should consider using open-source tools such as Snips NLU or RASA NLU. This would also allow you to understand parameters such as age and sex (via slots of intents).

  3. Custom flow. The Infermedica engine requires that you must learn the user's age and sex first, then the chief complaints and then you can proceed to the diagnostic questions. Still, you can decide what happens before that and after that. Also, not all pieces of available information must be presented. Also, you can consider an option to allow the user to add complaints later on during the interview (if the user explicitly wants to add something instead of responding to the last question).

  4. Group questions. If you're developing a voice app or simple text-based chat, it's hard to handle medical questions other than the simple ones (yes, no, don't-know). For such scenarios the disable_groups mode is intended (see apiaccess.py). If your chatbot is more of a rich conversational UI, then you may as well support all of the question types and not need this mode.

symptom-checker-chatbot-example's People

Contributors

adam-ra avatar akszydelko avatar

Watchers

James Cloos avatar

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.