Awesome
AI group chat with:
- a GraphQL federated subscription for getting messages to the client
- a durable function for easily maintaining chat state and reliably coordinating with OpenAI
Built for GraphQL Summit 2024. See Summit talk and slides, and more info in this post and this talk.
Contents:
<!-- START doctoc generated TOC please keep comment here to allow auto update --> <!-- DON'T EDIT THIS SECTION, INSTEAD RE-RUN doctoc TO UPDATE --> <!-- END doctoc generated TOC please keep comment here to allow auto update -->Code structure
Turborepo monorepo.
Apps
apps/web
- Next.js client (subscription code:components/group-chat.tsx
)apps/router
- Apollo routerapps/users-service
- subgraph that resolves the User entity (seeindex.ts
)apps/messages-service
- subgraph that handles Subscriptions and proxies Queries and Mutations to the durable function (index.ts
)apps/worker
- runs the durable functions
Packages
packages/common
- types generated from messages schema and supergraph schemapackages/durable-functions
- thegroupChat
durable function (index.ts
)packages/activities
- normal functions called by the durable function, including AI SDK code that talks to OpenAI (index.ts
)packages/ui
- UI componentspackages/eslint-config
packages/typescript-config
Set up
brew install temporal
curl -sSL https://rover.apollo.dev/nix/latest | sh
git clone https://github.com/lorensr/ai-group-chat.git
cd ai-group-chat
npm i
Create a .env
file at the project root with these values filled in:
APOLLO_KEY=
APOLLO_GRAPH_REF=
OPENAI_API_KEY=
The Apollo info must be from a free trial Enterprise account (until Apollo releases federated subscriptions to GraphOS Cloud).
Run
temporal server start-dev
npm run dev