nikhilno1 / NikBot

Personal Chatbot for Nikhil Utane

Home Page:https://nik-bot.vercel.app/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

NikBot: Personal Chatbot for Nikhil Utane

You can see a demo at https://nik-bot.vercel.app/.

Medium Post

The stack is Nextjs and Langchain. It is hosted on Vercel and Supabase for the database.

Here is a screenshot of the homepage:

Homepage of the blog

Installation

Install the packages: npm install

Create the table that will store the documents

Run this SQL query in your postgresql database to create the table that will store the documents. ⚠️ Your postgresql database must have the pgvector extension installed. It is installed on your Supabase instances. You can also use the provided docker-compose example that use the official docker image.

CREATE EXTENSION IF NOT EXISTS vector;

create table documents (
id text NOT NULL primary key,
"pageContent" text, -- corresponds to Document.pageContent
"sourceType" text, -- corresponds to the type of the source
"sourceName" text,
hash text, -- corresponds to Document.hash
metadata jsonb, -- corresponds to Document.metadata
embedding vector(1536) -- 1536 works for OpenAI embeddings, change if needed
);

create table users (
 id text not null,
 name text null,
 email text null,
 created_at timestamp without time zone not null default current_timestamp,
 updated_at timestamp without time zone not null,
 constraint users_pkey primary key (id)
);

create unique index users_email_key on users using btree (email) tablespace pg_default;

create table question (
    id text not null,
    content text null,
    answer text null,
    "successFromLLM" boolean not null default false,
    created_at timestamp without time zone not null default current_timestamp,
    published boolean not null default false,
    "authorId" text null,
    constraint Question_pkey primary key (id),
    constraint Question_authorId_fkey foreign key ("authorId") references users (id) on update cascade on delete set null
);

Update the environment variables

Copy the .env.local.example file to .env.local and update the variables with your own values.

Customize the personal assistant

Change the prompt

Modify the `gloria.config.ts file to make the personal assistant answer the question as you want.

Create the private data needed for the personal assistant to answer the questions

Fill the knowledge-base folder with text files that contains your personal information.

You can also use any LangChain's documents loader to create the knowledge base.

All your articles in the data folder will also be used to create the knowledge base.

Whenever you want to make new information available you can just run the npm run update:kb command. This command will populate the table documents in your database with the new information.

Run the development server

Run npm run dev to start the development server.

Deploy on Vercel

You can deploy this project on Vercel. You will need to set the environment variables in the Vercel dashboard.

Credits

Code from - MaximeThoonsen/gloria

It was started from the Tailwind Nextjs Starter Blog. Original README here.

About

Personal Chatbot for Nikhil Utane

https://nik-bot.vercel.app/

License:MIT License


Languages

Language:TypeScript 80.5%Language:JavaScript 16.3%Language:CSS 2.2%Language:MDX 0.9%Language:Shell 0.1%