GithubHelp home page GithubHelp logo

ai_chat_demo's Introduction

AI Chat POC

This is a proof of concept for creating a chat bot for stored character bios that will maintain a "memory" through vector storage of previous chat messages.

Installation

You'll need an OpenAI API account. You'll also need to set up a Supabase account and create the following tables:

User

create table
  public.user (
    id uuid not null default gen_random_uuid (),
    created_at timestamp with time zone not null default now(),
    last_login timestamp without time zone not null default now(),
    gamertag character varying not null,
    constraint User_pkey primary key (id)
  ) tablespace pg_default;

Message

create table
  public.message (
    id uuid not null default gen_random_uuid (),
    received timestamp with time zone null,
    user_id uuid null,
    ai_id bigint null,
    message text null,
    sent_by_user boolean null,
    embedding uuid null,
    constraint message_pkey primary key (id),
    constraint message_ai_id_fkey foreign key (ai_id) references ai_character (id),
    constraint message_embedding_fkey foreign key (embedding) references embeddings (id) on delete set null,
    constraint message_user_id_fkey foreign key (user_id) references "user" (id)
  ) tablespace pg_default;

AI character

create table
  public.ai_character (
    id bigint generated always as identity,
    name character varying null,
    bio text null,
    constraint ai_character_pkey primary key (id)
  ) tablespace pg_default;

Embeddings

create table
  public.embeddings (
    id uuid not null default gen_random_uuid (),
    vector extensions.vector not null,
    ai_character_id bigint not null,
    message_id uuid not null,
    constraint embeddings_pkey primary key (id),
    constraint embeddings_ai_character_id_fkey foreign key (ai_character_id) references ai_character (id),
    constraint embeddings_message_id_fkey foreign key (message_id) references message (id) on delete cascade
  ) tablespace pg_default;

Run Locally

Clone the project

Add an .env file with the variables listed below.

  git clone [email protected]:cjohansen11/ai_chat_demo.git

Go to the project directory

  cd ai_chat_demo

Install dependencies

  yarn install

Start the server

    yarn dev

Environment Variables

To run this project, you will need to add the following environment variables to your .env file

SUPABASE_URL

SUPABASE_KEY

OPENAI_API_KEY

OPENAI_ORG_ID

OPENAI_EMBEDDING_MODEL=text-embedding-ada-002

Usage

  • Log into your Supabase account and create x number of ai_characters as well as atleast 1 user
  • Copy your new Users id
  • Make an http request to localhost:3000/${ai_character_id}
  • Add a body to the request that includes the following:
{
  "message": "Any string you want",
  "uid": "userId"
}
  • Send request

ai_chat_demo's People

Contributors

cjohansen11 avatar

Watchers

 avatar

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.