Code Monkey home page Code Monkey logo

react-langchain-chatbot's Introduction

React-Langchain-Chatbot

Basic ChatGPT clone using OpenAI GPT-3.5-Turbo or GPT-4 via Langchain. Good playground for Langchain AI chatbots.

Boostrapping with React-Chatbot-Kit and LangchainJS.

Setup and Run the Project

Prerequisites

Steps

  1. Clone the Repository:

    git clone https://github.com/ilsilfverskiold/react-langchain-chatbot.git
    cd react-langchain-chatbot
    
  2. Install Dependencies:

    npm install
    
  3. Set Up OpenAI API Key:

  • Obtain your OpenAI API key.

  • Create a .env file in the root directory and add your OpenAI key.

    REACT_APP_OPEN_AI_API_KEY=your_openai_api_key
    
  1. Start the Server:

    npm start
    

Options

  1. ChatGPT Clone: The script has already been set in src/components/LangchainProcessor.js so you can run it as is. If you want to change the prompt template you can do so directly in this file.

    // The default prompt template is
     const promptTemplate = `
       You are an ironic and nihilistic chatbot so always answer like so. Don't answer in a "response: answer" format.
       Question: {question}
     `;
  2. A Simple Chain: Go to /langchain_options and find SimpleChain.js rename it LangchainProcessor.js and replace it with the LangchainProcessor.js in the components folder. You can build on top of this yourself but at the moment it is only using the question and not allowing for past answers. Make sure you tweak the prompt template in there.

  3. Q/A with URL: Here you will first need to set up your Workers route correctly. See this repository that will go through it step by step. When you have a working endpoint, go to /langchain_options in this directory and find CloudflateWorkersRoute.js rename it LangchainProcessor.js and replace it with the LangchainProcessor.js in the components folder.

  • Make sure you set REACT_APP_CLOUDFLARE_WORKERS_AUTH in your .env file that you have set up with your Worker
  • Make sure you set the URL for the POST request to the endpoint that you'll receive with the deployment of your worker
  • If you are experiencing CORS errors Make sure you allow your IP to access the endpoint (this you set up via your worker)
  1. Q/A with Text file: Here you will first need to set up your AWS application correctly. See this repository or this tutorial that will go through it step by step. When you have a working endpoint, go to /langchain_options in this directory and find AWSRoute.js rename it LangchainProcessor.js and replace it with the LangchainProcessor.js in the components folder. Or just replace the code directly in the LangchainProcessor.js component.
  • Make sure you set all your process.env keys in a .env file

    REACT_APP_OPEN_AI_API_KEY=
    REACT_APP_AWS_POST_URL=https://xxxx.execute-api.eu-central-1.amazonaws.com/dev/question
    REACT_APP_AWS_API_KEY=
    REACT_APP_AWS_BUCKET_NAME=my-langchain-bucket
    
  • To set your system and prompt template look into the code in AWSRoute.js

     // Define the request body
     const requestBody = {
       ...
       promptTemplate: "Use the following pieces of context to answer the question at the end. \n {context}\n Question: {question}\nHelpful Answer:",
       systemTemplate: "I want you to act as a customer service bot called Socky the Happy bot that I am having a conversation with.\nYou are a bot that will provide funny answers to the customer. \n If you can't answer the question say I don't know."
     };
  • If you are experiencing CORS errors Make sure you allow your IP to access the endpoint (look at your AWS lambda scripts)

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.