tahreemrasul / math_app_langchain

A math application/chatbot to answer a user's arithmetic or reasoning based questions. Utilizes LangChain agents and tools. Frontend with Chainlit.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Math App using LangChain Agents, OpenAI and Chainlit

You can read further here in this medium article.

Overview

This repo contains the code for a math app, Math Wiz, a custom chatbot that answers a user's arithmetic and reasoning questions. Chainlit is used for the web application portion. LLMs can be quite bad at general math questions, even the simplistic ones. This can be due to a variety of reasons, such as not having been trained on sufficient mathematical data, difficulty in carrying out numeric operations, as well as the fact that LLMs are text generators, and can struggle to come up with logic-based formulations. Having said that, they do contain a large corpus of trained dataset, and can offer superior text understanding and generation qualities. In this tutorial, we will demonstrate how the use of LangChain agents can significantly increase an LLM's performance when working with numerical or reasoning-based questions.

Application Process Diagram

LangChain Agents are comprised of one or more tools that can be used by the agent to get to the final decision. These tools can be online search, or chains carrying out modular tasks in an application flow. Below is the process diagram for the app designed in this tutorial: alt text for screen readers

For each user query, the agent uses the LLM to decide which tool to use. The flow of the agent can be visualized with this flow diagram: alt text for screen readers

Getting Started

Prerequisites

  • Python 3.8 or later
  • An OpenAI API key

Installation

  1. Clone the Repository
    git clone git@github.com:tahreemrasul/simple_chatbot_langchain.git
    cd ./simple_chatbot_langchain
    
  2. Set Up a Conda Environment (Recommended)
  • If you don't have Conda, install it first.
  • Create a new Conda environment:
    conda create -n math_assistant python=3.11
  • Activate the environment:
    conda activate math_assistant
    
  1. Install Dependencies
  • Install the required packages using the requirements.txt file:
    pip install -r requirements.txt
    
  1. Set Up Your OpenAI API Key
  • Create a .env file in the root directory of the project.
  • Add your OpenAI API key to the .env file:
    OPENAI_API_KEY='Your-OpenAI-API-Key-Here'
    

Usage

To run the Math Wiz app, simply execute the chatbot.py script using:

chainlit run chatbot.py -w --port 8000

This will run the application at http://localhost:8000

About

A math application/chatbot to answer a user's arithmetic or reasoning based questions. Utilizes LangChain agents and tools. Frontend with Chainlit.


Languages

Language:Python 100.0%