React AI Chatbot: Conversational AI Made Easy

React AI ChatBot

Simple React AI Chatbot based on GPT-3 or GPT-4 OpenAI models to chat with your data. This component provides hooks for chatbot interaction - sending and receiving messages. UI Styling is completely up to you! is used to set discussion context and settings!

It's recommended to have your own Open AI Api Key to use React AI ChatBot! You can get your key here.


npm install react-ai-chatbot


yarn add react-ai-chatbot

Usage instructions:

Register or login at OpenAI platform and set your API Key here.

Singup at and add your OpenAI Key.

Start discussion either from documents or webpages.

Enable discussion sharing (at right top side). Copy discussion endpoint.

Example implementation (update <your_discussion_endpoint> accordingly):

import { ReactNode, useState, ChangeEvent } from 'react';
import { ChatBotProvider, useChatBot, usePending } from 'react-ai-chatbot';

const ChatBot = ({ children } : { children: ReactNode }) => {

  const [ message, setMessage ] = useState<string>('');

  const { messages, sendMessage, isLoading, isError, error } = useChatBot();

  const messageChangeHandler = (e:ChangeEvent<HTMLInputElement>) => setMessage(;

  const sendMessageHandler = () => {


  return <div>
    {isLoading ? <div>loading...</div> : ''}
    {isError ? <div>{error}</div> : ''}
      {, i)=><div key={i}>{m.type}: {m.message}</div>)}
      <input type="text" value={message} onChange={messageChangeHandler} />
    <button onClick={sendMessageHandler}>Send</button>

const PendingMessage = () => {

  const { pending } = usePending();

  return <>{ pending }</>;

const App = () => {

  return <ChatBotProvider endpoint='<your_discussion_endpoint>'>
      <PendingMessage />



  • messages: <[{type: 'bot' | 'user', message: string}]> - Discussion message are stored in this array
  • sendMessage: <(message: string)> - function used to send message
  • isLoading: boolean - true while ai generates the message
  • isError: boolean - when error occurs
  • error: string - error message
  • clearMessages() - clear all chat messages
  • setEndpoint(endpoint:string) - set chat endpoint. Can be used to switch to a different chat


  • pending: string - use to get message on-the-fly while it's being generated, chatgpt style.

Download Details:

Author: rarar89
Source Code: 
License: ISC

#ai #react #chatbot 

React AI Chatbot: Conversational AI Made Easy
1.50 GEEK