Chatbot with OpenAI and Open Library APIs This project implements a chatbot that interacts with users through a command-line interface. It utilizes the OpenAI API for generating responses and the Open Library API for retrieving book-related data.
This project is designed to create a chatbot interface that communicates with users and a backend system responsible for managing responses. The goal is to integrate the chatbot with a backend that handles the uploading and processing of custom documents, utilizing a language model to generate customized responses.
Setting Up:
Environment Setup: Begin by setting up the environment using the provided commands. This involves installing necessary packages and setting up a virtual environment.
Installing Requirements: Use pip to install the required packages listed in the requirements.txt file. These packages include Flask, Flask-CORS, langchain, OpenAI, and others.
Understanding the User Interface: The front-end of the application is built using HTML, CSS, and JavaScript, with libraries such as Bootstrap and Font Awesome for styling and interactivity. The provided code helps understand the interaction between the front-end and back-end.
Worker Script: The worker.py script is crucial for the chatbot application. It initializes the language model, processes PDF documents, and manages conversation retrieval. Instructions are provided within the script to fill in necessary code sections.
Server Setup: The Flask server handles communication between the front-end interface and the backend services. It defines routes for processing documents and messages, utilizing the worker script for core logic.
Running the Application: To run the chatbot application, execute the server.py file. This starts the Flask server, allowing users to interact with the chatbot interface through a web browser.
Docker Containerization: Docker is used to containerize the application, ensuring consistency across different environments. The provided Dockerfile facilitates building and running the application within a Docker container.
Understanding the Code:
worker.py: This script initializes the language model, processes PDF documents, and manages conversation retrieval. server.py: Defines Flask routes for processing documents and messages, and starts the Flask server. Front-end files (index.html, style.css, script.js): Responsible for the layout, styling, and interactivity of the chatbot interface. Running the Application:
Execute server.py to start the Flask server. Access the application through a web browser, typically at http://localhost:8000. Interact with the chatbot interface by uploading documents, sending messages, and receiving responses. Note: Ensure to replace placeholder API keys with your actual API keys where necessary for proper functionality.