Skip to content

GetStream/chat-ai-samples

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

1 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Integrating Stream Chat with AI

Quick Links ๐Ÿ”—

Repo Overview ๐Ÿ˜Ž

This repo contains Stream's official sample projects demonstrating how Generative AI can be used in our Chat products. It includes sample backend servers for ChatGPT and Gemini, which can be used as a reference guide when using Gen AI with Stream.

Sample integrations in ReactJS, Android, and Flutter are located in the "frontends" directory, which also demonstrates working with and rendering real-time message chunks as they are sent from AI providers.

Projects/Packages ๐Ÿš€

  • Backend
    • ChatGPT Server: Node server that connects to both OpenAI and Stream chat to intercept and respond to messages in real time.
    • Gemini Server: Node server that connects Stream Chat with Gemini, allowing for sending, receiving, and replying to messages.
  • Frontend
    • React/NextJS: NextJs app, which interacts with ChatGPT and implements streaming responses.
    • Android: Jetpack Compose app written in Kotlin which integrates Googleโ€™s Gemini and our Jetpack Compose SDK. Please see the sub-directory for detailed getting started instructions.

How to Run ๐Ÿƒ

Setup environment variables

cp .env.example .env

Add following credentials to .env file:

  1. Stream Chat app api key and secret
  2. User ID and token
  3. OpenAI API key
  4. Or Gemini API key

Backend

To start the backend server, you can choose between ChatGPT and Gemini. The server will listen for messages and respond with AI-generated responses. You need to configure this server url as a webhook for your Stream Chat app.

cd server
yarn;

# Start ChatGPT server
yarn start:openai

# Or start Gemini server
yarn start:gemini

Configure Ngrok webhook

To expose the local server to the internet, you can use ngrok. Follow the instructions here to set up ngrok and configure the webhook URL for your Stream Chat app:

https://getstream.io/chat/docs/react/debugging_with_ngrok/

Frontend

cd react-chat
yarn; yarn start

AI Guides ๐Ÿ“š

These guides explore more of how AI can be used across our SDKs and products.

Contributing ๐Ÿค”

  • How can I submit a sample app?
    • Apps submissions are always welcomed! ๐Ÿฅณ Open a pr with a proper description and we'll review it as soon as possible
  • Spot a bug ๐Ÿ•ท ?
    • We welcome code changes that improve the apps or fix a problem. Please make sure to follow all best practices and add tests if applicable before submitting a Pull Request on Github.