claude-thinking-chatbot.mp4
This project is a full-stack chat application that uses the following:
- A Next.js app for the chat interface
- Trigger.dev Realtime to stream AI responses and thinking/reasoning process to the frontend
- Claude 3.7 Sonnet for generating AI responses
- AI SDK for working with the Claude model
- After cloning the repo, run
npm install
to install the dependencies. - Copy the
.env.example
file to.env
and fill in the required environment variables: - Copy the project ref from the Trigger.dev dashboard and add it to the
trigger.config.ts
file. - Run the Next.js server with
npm run dev
. - In a separate terminal, run the Trigger.dev dev CLI command with
npx trigger dev
(it may ask you to authorize the CLI if you haven't already).
Now you should be able to visit http://localhost:3000
and see the chat application running. Enter a message and click "Send" to start chatting with Claude.
- Claude Stream Task: View the Trigger.dev task code in the src/trigger/claude-stream.ts file, which sets up the streaming connection with Claude.
- Chat Component: The main chat interface is in app/components/claude-chat.tsx, which handles:
- Message state management
- User input handling
- Rendering of message bubbles
- Integration with Trigger.dev for streaming
- Stream Response: The
StreamResponse
component within the chat component handles:- Displaying streaming text from Claude
- Showing/hiding the thinking process with an animated toggle
- Auto-scrolling as new content arrives
- Real-time Streaming: Uses
useRealtimeRunWithStreams
to subscribe to Claude's responses as they're generated. - Thinking Process: Leverages Claude's "thinking" capability to show the AI's reasoning process.
To learn more about the technologies used in this project, check out the following resources:
- Trigger.dev Documentation - learn about Trigger.dev and its features
- Trigger.dev Realtime docs - learn about the Realtime feature of Trigger.dev
- Trigger.dev Realtime streams - learn about the different types of streams available in Trigger.dev
- React hooks for Trigger.dev - learn about the React hooks provided by Trigger.dev
- Anthropic Claude Documentation - learn about Claude's capabilities and API
- AI SDK Documentation - learn about the AI SDK for working with LLMs