Skip to content

LeonSilva15/openai-chatbot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

OpenAI Chatbot

This is a chatbot created using the OpenAI API, Flask and MySQL

Prerequisites

Dependency Documentation MacOS Installation
Venv https://docs.python.org/3/library/venv.html https://formulae.brew.sh/formula/virtualenv
Python 3.7 https://docs.python.org/3.7/ https://www.python.org/downloads/release/python-370/
MySQL https://dev.mysql.com/doc/ https://formulae.brew.sh/formula/mysql

Installation

Get python 3.7 using pyenv

brew update
brew isntall pyenv 
pyenv install 3.7
pyenv shell 3.7

Useful links:

Get the virtual environment

pip3 install virtualenv
  • or
brew install virtualenv

Useful link:

Get MySQL

brew install mysql

Useful link:

Setup

  • Create the virtual environment using python 3.7
python -m venv .env

Start the virtual environment

  • On MacOS (Option 1)
source env/bin/activate
  • On Windows
venv\Scripts\activate.bat
  • On MacOS (Option 2), Linux or Windows Git Bash
source venv/Scripts/activate

To get out from the virtual environment

deactivate

Install the requirments

pip install -r requirements.txt

Create the data base

Used for users management and chat recording

Start mysql

brew services start mysql
  • To stop it
brew services stop mysql

Enter mysql

mysql -u root
  • To get out from mysql
quit();

Create the dabase

create database chatbot;

Get in the chatbot database

use chatbot

Create the users table

CREATE TABLE `users` (
    `id` int(11) NOT NULL,
    `name` varchar(100) NOT NULL,
    `password` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

ALTER TABLE `users`
    ADD PRIMARY KEY (`id`);

ALTER TABLE `users`
    MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

Create the chats table

CREATE TABLE `chats` (
  `id` varchar(100) NOT NULL,
  `question` varchar(255) NOT NULL,
  `answer` LONGTEXT NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;

Add the environment variables

DB_HOST=localhost
DB_USER=root
DB_PASSWORD=
DB_DB=chatbot
SECRET_KEY=<Any random string>
API_KEY=<Your OpenAI API for gpt-3.5-turbo key>

Start the program

python3 main.py

Go to your web browser and open your localhost:4000. Enjoy it!

About

Chatbot created using the OpenAI API

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published