GitHunt
BC

bcornick/collaborative-ai-chat-rooms

Live multi-user chat rooms with AI agents centered around specific subjects.

Venture Science Doctorate Subject-Specific Collaborative AI Chatrooms

This is a PartyKit project using Next.js bootstrapped with partykit-nextjs-chat-template.

PartyKit is an open source platform for developing multiplayer, real-time applications.

Getting Started

First, copy the .env.example file to .env in the project root.

cp .env.example .env

Then, open the created .env file and fill in the missing environment variables.

Then, run the development server:

npm install
npm run dev

This will start the PartyKit development server at port 1999, and a Next.js development server at port 3000.

Open http://localhost:3000 with your browser to see the result.

What's included

This template application demonstrates various use cases of PartyKit.

The /party directory contains partykit servers with the following examples:

  • โ„น๏ธ main.ts โ€” Simplest possible HTTP and WebSocket server.
  • ๐Ÿ’ฌ chatRoom.ts โ€” Real-time chat room with persistence
  • ๐Ÿ‘ฉโ€๐Ÿ‘ฉโ€๐Ÿ‘ฆโ€๐Ÿ‘ฆ chatRooms.ts โ€” Presence and room-to-room communication
  • ๐Ÿ™‹โ€โ™€๏ธ user.ts โ€” User session management and authentication with NextAuth.js
  • ๐Ÿค– ai.ts โ€” AI NPC chatroom participant using LLMs
  • ๐Ÿญ cursors.ts โ€” Shared cursors

The /app directory contains a Next.js 13 application, demonstrating client-side usage of PartyKit, including:

  • ๐Ÿ“ก chat/page.tsx โ€” Server Rendering in React Server Components
  • ๐Ÿ“ฑ RoomList.tsx โ€” Client Rendering with live WebSockets
  • ๐Ÿ‘ฎโ€โ™€๏ธ Room.tsx โ€” A real-time chatroom with authentication
  • ๐ŸŒŸ NewRoom.tsx - Form for creating new subject-specific chatrooms
  • ๐Ÿ–ฑ๏ธ Cursors.tsx โ€” Live cursors
  • ๐Ÿšฅ ConnectionStatus.tsx โ€” Connection status indicator

Deploy

Deploy the PartyKit Server on PartyKit

When you're ready to deploy your application to the internet, run the following command to deploy the PartyKit Server:

npx partykit deploy

This will deploy the code to your PartyKit account โ€” and if you don't have an account yet, we'll create one as part of the deployment.

Configure environment variables

In development mode, PartyKit uses your .env file to read configuration values.

For production, you'll need to set the production environment variables:

# Set the production URL of your Next.js application for authentication
npx partykit env add NEXT_APP_URL

# (Optional) Set your OpenAI API key to enable the AI chat participant in production
npx partykit env add OPENAI_API_KEY

# Redeploy with new variables
npx partykit deploy

Deploy the website on Vercel

The easiest way to deploy the Next.js frontend for your PartyKit app is to use the Vercel Platform from the creators of Next.js.

Remember to configure the environment variables for your website hosting provider!

Learn More

To learn more about PartyKit, take a look at PartyKit documentation.

Languages

TypeScript99.1%JavaScript0.8%CSS0.1%HTML0.0%

Contributors

MIT License
Created September 19, 2023
Updated September 29, 2023
bcornick/collaborative-ai-chat-rooms | GitHunt