A Node.js AI chatbot with unlimited context and chat history.

Overview

Memory Bot

Memory Bot is an AI chatbot built with Node.js to demonstrate unlimited context and chat history for more cost-efficient context-aware conversations. This project was originally featured on my blog ByteSizedBrainwaves - Building a GPT-4 Powered Chatbot with Node.js: Unlimited Context and Chat History in Under 100 Lines of Code .

Features

  • Unlimited context and chat history using HNSWLib vector stores
  • An additional rolling memory window for refining the last outputs
  • Logs all chats in daily logfiles in the chat_logs directory
  • Built using Langchain and HNSWLib

Prerequisites

You will need an OpenAI Account and API key:

  • Sign up for an OpenAI account here if you don't already have one: OpenAI signup page
  • After registering and logging in, create an API key here: API keys

Installation

  1. Clone the repository or download the source code:

    git clone [email protected]:gmickel/memorybot.git
    
  2. Navigate to the project directory:

    cd memorybot
    
  3. Install the required dependencies:

    npm install
    

    Please note: On Windows, you might need to install Visual Studio first in order to properly build the hnswlib-node package. Alternatively you can use Windows Subsystem for Linux.

  4. Set up environment variables by creating a .env file in the project root directory with the necessary API keys and configuration options. You can use the provided .env.example file as a template.

    • Important: If you do not have access to GPT-4 yet, set the MODEL env variable to gpt-3.5-turbo. You can request access to GPT-4 here.
  5. Add some context to the chatbot:

    • Replace example.md in the docs folder with the context you want to add before starting the bot. The bot currently accepts .md, .txt and .json files. You can add multiple files and nest them if required.
    • Make sure you understand that this content will be sent to the OpenAI API - see Considerations
  6. Run the chatbot:

    npm start
    

Usage

Changing the prompt

  • Change the system prompt to whatever you need and restart the bot.

Resetting the chat history/context

Both the context and chat history are currently persisted and reused on every run. To reset either the context or chat history, simply the contents of either the memory folder memory to reset the chat history or the contents of the db and docs folders to change the context provided to the bot.

Alternatively, change the variables in .env to point to different folders.

Restart the bot after these steps.

Running

After starting the chatbot, simply type your questions or messages and press Enter. The chatbot will respond with context-aware answers based on the conversation history and any provided context.

Documentation

For a detailed guide on building and customizing the Bot, please refer to the blog post on ByteSizedBrainwaves.

Considerations

Consider the implications of sharing any sensitive content with third parties. Any context or history that is generated is sent to OpenAI to create the necessary embeddings. Always ensure that you're adhering to your organization's security policies and best practices to protect your valuable assets.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Acknowledgements

  • OpenAI for their powerful language models
  • Langchain for seamless integration with language models
  • HNSWLib for efficient vector search and storage
  • Node.js and the open-source community for providing useful libraries and tools
You might also like...

Replaces Youtube Chat with Destiny.gg chat.

Replaces Youtube Chat with Destiny.gg chat.

A lightweight extension that replaces the native Youtube Live chat with an embeded destiny.gg chat. Note: This is in no way affiliated with Destiny.gg

Jul 27, 2022

O Web-Chat é um projeto com o intuito de criar um chat de ajuda, que contém uma experiência dinâmica e salva as informações preenchidas pelo usuário usando um formulário.

O Web-Chat é um projeto com o intuito de criar um chat de ajuda, que contém uma experiência dinâmica e salva as informações preenchidas pelo usuário usando um formulário.

Web-Chat Introdução O Web-Chat é um projeto com o intuito de criar um chat de ajuda, que contém uma experiência dinâmica e salva as informações preenc

Oct 5, 2022

A card for Home Assistant Lovelace for exploring the history of your entities interactively and in real time.

A card for Home Assistant Lovelace for exploring the history of your entities interactively and in real time.

History explorer card This is a custom history card for Home Assistant. This card offers a highly interactive and configurable way to view the history

Dec 31, 2022

Get a diff view of your Obsidian Sync, File Recovery and Git version history

Get a diff view of your Obsidian Sync, File Recovery and Git version history

Version History Diff (for Sync and File Recovery Core plugins and Git) Note This plugin uses private APIs, so it may break at any time. Use at your ow

Dec 26, 2022

An enchanced useState hook which keeps track of the states history, allowing you to undo and redo states.

useTimeline An enchanced useState hook which keeps track of the states history, allowing you to undo and redo states. useTimeline is a simple hook bas

Apr 22, 2022

A pokemon card battle app that can evolve them and see their battle history.

A pokemon card battle app that can evolve them and see their battle history.

BattlePoke 🔗 About An application of an Pokemon card battle game where each player initially receives 3 cards and can start to battle and gain evolut

Jun 17, 2022

To understand the history of SACCOs, a Savings and Credit cooperative otherwise known as a Sacco is a type of corporation that aims at pooling money together.

To understand the history of SACCOs, a Savings and Credit cooperative otherwise known as a Sacco is a type of corporation that aims at pooling money together. Depending on the Saccos, there are different types of supplies of merchandise. These include and are not limited to recognition servers, sedimentation, and call home eggs installation. More to these items include check glades, bankers, checks standing orders and safe detentions, and salary progress.

Oct 19, 2022

A powerful and simple JavaScript library provides a history for undo/redo functionality. Just like a time machine! 🕐

UndoRedo.js A powerful and simple Javascript library provides a history for undo/redo functionality. Just like a time machine! 🕐 Installation: Node.j

Dec 14, 2022

⌨️ Visualize keyboard history for osu! in bar form

⌨️ Visualize keyboard history for osu! in bar form

bar-overlay-for-osu Visualize keyboard history for osu! Example Vertical Horizontal Features Customizable: keys, colors, speed, spacing, etc. Receives

Oct 27, 2022
Owner
Gordon Mickel
Founder of Contract Vault and creator of the DocIQ Platform.
Gordon Mickel
A simple Node.js code to get unlimited instagram public pictures by every user without api, without credentials.

Instagram Without APIs Instagram Scraping in August 2022, no credentials required This is a Node.js library, are you looking for the same in PHP? go t

Francesco Orsi 28 Dec 29, 2022
A chat logs online saver for discord bots to save messages history & cleared messages online

Chat Logs NPM package that saves messages online to view it later Useful for bots where users can save messages history & cleared messages online Supp

TARIQ 8 Dec 28, 2022
Uniform, Unlimited, Universal and Unbelievable Annotation Toolbox

特性 ?? 本项目包含@label-u/annotation、@label-u/components、@label-u/utils及@label-u/web等4个工程。 ?? 采用rollup esbuild插件及vite编译,让开发者上高速,开发效率更高 ?? 采用lerna进行多工程管理。 ??

OpenDataLab 16 Dec 23, 2022
The Chat'Inn is a simple and minimal realtime chat application whose database is powered by firebase and firestore.

The Chat-in The Chat'Inn is a simple and minimal realtime chat application whose database is powered by firebase and firestore. The frontend part is c

Aswin Asok 11 Aug 8, 2022
Chat View let's you quickly and easily create elegant Chat UIs in your Markdown Files.

Obsidian Chat View Plugin Chat View let's you quickly and easily create elegant Chat UIs in your Markdown Files. Usage Every chat message must be pref

Adifyr 96 Dec 27, 2022
A chatbot for the Deloitte CBO #under30s channel.

Harold Harold A chatbot for our favourite Slack channel at Deloitte. Explore the docs » View Demo · Report Bug · Request Feature Table of Contents Abo

Jim Kelly 6 Nov 3, 2022
DialogFlow Machine Learning Chatbot

DialogFlow Machine Learning Chatbot Project Overview This repository contains a backend service for an intelligent chatbot that onboards clients, answ

ddayto 10 Jul 21, 2022
An open source, friendly human-like chatbot to be with you, forever

Chatbot A Friendly human-like chatbot to be with you, forever Made by Rahuletto#0243 This template powers our system at Simply API Instructions This b

Rahul Marban 6 Sep 18, 2022
This repository contains a fullstack chatbot project based on the ChatGPT `gpt-3.5-turbo` model.

This is a fullstack chatbot created with React, Nodejs, OpenAi, and ChatGPT while developing the following tutorial: How To Build A Chat Bot Applicati

NJOKU SAMSON EBERE 6 May 10, 2023
Omnichannel Live Chat Widget UI Components offers a re-usable component-based library to help create a custom chat widget that can be connected to the Dynamics 365 Customer Service experience.

Omnichannel Live Chat Widget UI Components @microsoft/omnichannel-chat-widget is a React-based UI component library which allows you to build your own

Microsoft 14 Dec 15, 2022