Skip to content

This project implements a chatbot interface that enables users to interact with a tabular database via natural language queries. The chatbot processes these queries, formulates appropriate SQL statements, and retrieves information from the database, presenting it in a user-friendly manner.

Notifications You must be signed in to change notification settings

abhinavreddy05/DBot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

DBbot

Intelligent chatbot for database querying.

Deployment: Live Here!

Description

  • This project implements a chatbot interface that enables users to interact with a tabular database via natural language queries. The chatbot processes these queries, formulates appropriate SQL statements, and retrieves information from the database, presenting it in a user-friendly manner.

  • The application uses OpenAI's GPT-3.5-turbo model to convert user queries into SQL commands and execute them against the database.

Documentation

Local Configuration

Frontend

# Install dependencies
cd frontend
npm install

# Run the React application
npm run dev

Backend

  • Configure the openai api key in the backend/app.py at line 28 as OPENAI_API_KEY="sk-......yourkey".
  • At line 31 change the part {"origins": "https://db-bot.vercel.app"} to {"origins": "*"} for you to be able to run it in local.
# Setup virtual environment and install dependencies
cd backend
python -m venv env
source env/bin/activate
pip install -r requirements.txt

# Run the Flask application
flask run --port 8888 --debug

Flow

Flow

Objectives:

  • Simple chat interface. (Similar to ChatGPT)
  • Querying an open-source tabular database with numbers & text.

Requirements:

  • User Friendly Interface
  • Tabular database with sample data
  • Intelligent Query Capability + Training the platform

Additional Features:

  • View executed SQL queries
  • Markdown Support
  • Self correction in case of error
  • Visual representation of data
  • History of conversations
  • Learning through user feedback
  • Multiple LLM/Bots options to choose from

Tech Stack:

  • Frontend:
    • React
    • Tailwind CSS
  • Backend:
    • Flask
  • Database:
    • SQLite

Application Structure:

Backend (Flask)

The Flask application sets up an API endpoint '/chat' that accepts 'GET' requests with a message parameter. The message is processed by the OpenAI model to generate an SQL query, which is then executed against the SQLite database. The response includes both the natural language response and the SQL query.

Frontend (React)

The React application provides a chat interface where users can input their queries. Messages from the user and responses from the bot are displayed in a chat-like format. The frontend communicates with the backend API to fetch responses and display the executed SQL queries.

Libraries Used:

Python (Backend)

  • openai: Library for interacting with OpenAI's GPT-3.5-turbo model.
  • sqlite3: SQLite database adapter for Python.
  • ast: Provides functions to process abstract syntax trees.
  • re: Module for regular expressions in Python.
  • langchain_openai: Interface for using OpenAI's models within LangChain.
  • langchain_community: Community tools for LangChain, including agent toolkits and utilities.
  • langchain_core: Core components for building and running LangChain applications.
  • FAISS: Facebook AI Similarity Search, a library for efficient similarity search and clustering of dense vectors.

React (Frontend)

  • react: JavaScript library for building user interfaces.
  • axios: Promise-based HTTP client for the browser and Node.js.
  • marked: Library for parsing Markdown.

Relevant Resources:

Examples:

Credits

About

This project implements a chatbot interface that enables users to interact with a tabular database via natural language queries. The chatbot processes these queries, formulates appropriate SQL statements, and retrieves information from the database, presenting it in a user-friendly manner.

Topics

Resources

Stars

Watchers

Forks