Skip to content

Commit dd0c5fd

Browse files
authored
feat: word follow up chat with jAI✨ (#142)
## Description <!-- Please add PR description (don't leave blank) - example: This PR [adds/removes/fixes/replaces] the [feature/bug/etc] --> This pull request introduces the new jAI Follow-up Chat feature to the jargons.dev ecosystem, enabling users to ask context-aware questions about dictionary terms and receive intelligent, conversational AI responses. The changes span documentation updates, codebase structure, and a major new React component implementing the chat widget. **Feature Addition: Interactive Follow-up Chat** - Adds a complete React implementation for the jAI Follow-up Chat widget, including authentication, streaming AI responses, default question templates, and a trigger button for user interaction. **Documentation and API Updates** - Updates the `README.md` to describe the new follow-up chat feature, its conversational capabilities, and context-aware Q&A, replacing previous generic explanations. - Documents the new `components/follow-up-chat.jsx` file and its main components in the module structure section. - Expands documentation for prompt templates, clarifying the distinction between `FOLLOW_UP_CHAT` (for conversational Q&A) and `SEARCH_WORD` (for dictionary definitions). - Details the new API endpoint `src/pages/api/jai/follow-up-chat.js`, including semantic search, conversation history, streaming responses, and CORS support. - Provides a feature breakdown for the new chat widget, including UI elements, authentication, streaming, and integration points. ## Related Issue <!-- Please prefix the issue number with Fixes/Resolves - example: Fixes #123 or Resolves #123 --> Fixes jargonsdev/roadmap#6 ## Screenshots/Screencasts <!-- Please provide screenshots or video recording that demos your changes (especially if it's a visual change) --> [screen-capture (18).webm](https://github.com/user-attachments/assets/85c342b0-8682-45d4-972c-5db35d59e34e) ## Notes to Reviewer <!-- Please state here if you added a new npm packages, or any extra information that can help reviewer better review you changes --> - Relies on already established `apps/jai` module - Added new node packaages - @ai-sdk/react - js-cookies
1 parent e687851 commit dd0c5fd

File tree

18 files changed

+945
-223
lines changed

18 files changed

+945
-223
lines changed

apps/jai/README.md

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
Unlike standalone AI applications, ✨jAI is deeply integrated into the jargons.dev ecosystem, powering features like:
1414

1515
- **AI-powered word definitions**: Generate instant definitions for technical terms not yet in the dictionary
16-
- Intelligent word explanations and follow-up conversations
16+
- **Interactive follow-up chat**: Ask context-aware questions about any word and get intelligent, conversation-based explanations
1717
- Semantic search across the dictionary
1818
- Context-aware responses based on the curated dictionary content
1919
- Real-time AI assistance for developers exploring technical terms
@@ -34,6 +34,7 @@ The ✨jAI module is organized into focused utility files:
3434
apps/jai/
3535
├── index.js # Main exports and module interface
3636
├── components/ # React components for UI/feature integration
37+
│ ├── follow-up-chat.jsx # jAI Follow-up Chat feature
3738
│ ├── logo.jsx # jAI Logo
3839
│ └── word-search.jsx # jAI Word Search feature
3940
└── lib/
@@ -55,14 +56,24 @@ export { jAIPrompts, formatMessage, model, vectorStore };
5556

5657
#### `lib/jai-prompts.js`
5758

58-
Defines ✨jAI's personality and conversation templates. The AI assistant is designed to:
59+
Defines ✨jAI's personality and conversation templates through two specialized prompts:
5960

60-
- Explain technical jargon clearly and concisely
61-
- Use relatable analogies and developer-friendly examples
62-
- Maintain a friendly, witty personality
63-
- Encourage follow-up questions and deeper exploration
64-
- Generate accurate, SEO-friendly definitions for technical terms
65-
- Provide structured responses optimized for dictionary content
61+
**`FOLLOW_UP_CHAT`**: Powers conversational interactions where jAI:
62+
63+
- Maintains a friendly, slightly witty personality as a knowledgeable coding buddy
64+
- Explains technical concepts using clear analogies and real-world comparisons
65+
- Provides context-aware answers based on the word being viewed
66+
- Encourages curiosity and deeper exploration of topics
67+
- Uses developer-centric examples (primarily JavaScript)
68+
- Maintains conversation history for coherent follow-up discussions
69+
70+
**`SEARCH_WORD`**: Generates structured dictionary definitions that are:
71+
72+
- Formal, clear, and beginner-friendly
73+
- SEO-optimized with natural keyword usage
74+
- Accurate and up-to-date with industry standards
75+
- Structured as: Meaning → Further Explanation → Example (when necessary)
76+
- Focused on software, programming, and technology contexts
6677

6778
#### `lib/model.js`
6879

@@ -98,6 +109,19 @@ React component that powers the AI-driven word definition feature. Includes:
98109
- Error handling and loading states
99110
- Integration with the `/api/jai/search` endpoint
100111

112+
#### `components/follow-up-chat.jsx`
113+
114+
Interactive chat widget component for context-aware Q&A about dictionary terms. Features:
115+
116+
- **JAIFollowUpChatWidget**: Main chat interface with message history and streaming responses
117+
- **JAIWordFollowUpChatWidgetTrigger**: Floating trigger button to open the chat widget
118+
- Default question templates for quick interaction (e.g., "Can you give me a real-world example of {word}?")
119+
- Authentication state management and login prompts for non-authenticated users
120+
- Auto-scrolling chat container for smooth conversation flow
121+
- Real-time streaming of AI responses using the `@ai-sdk/react` useChat hook
122+
- Integration with the `/api/jai/follow-up-chat` endpoint
123+
- User avatar display for personalized conversations
124+
101125
## Environment Variables
102126

103127
✨jAI requires the following environment variables:
@@ -146,17 +170,28 @@ Dedicated endpoint for AI-powered word definitions that:
146170
- Provides fallback definitions for terms not yet in the dictionary
147171
- Powers the `/browse/with-jai` page and word search components
148172

149-
<!-- ### 3. Follow-up Chat API (`src/pages/api/jai/follow-up-chat.js`)
173+
### 3. Follow-up Chat API (`src/pages/api/jai/follow-up-chat.js`)
174+
175+
Interactive chat endpoint that imports all four core utilities (`jAIPrompts`, `model`, `formatMessage`, `vectorStore`) for real-time AI conversations. This powers the follow-up chat feature with:
150176

151-
Imports all four core utilities (`jAIPrompts`, `model`, `formatMessage`, `vectorStore`) for real-time AI interactions. Powers the follow-up chat feature with semantic search for relevant context, conversation history management, and streaming AI response generation. -->
177+
- **Semantic Search**: Retrieves relevant dictionary content using vector similarity search to ground responses in accurate context
178+
- **Conversation History**: Maintains chat history for coherent, context-aware follow-up discussions
179+
- **Streaming Responses**: Uses LangChain's RunnableSequence to stream AI responses in real-time
180+
- **CORS Support**: Configured for production and preview deployments with proper cross-origin access
181+
- The `FOLLOW_UP_CHAT` prompt template for conversational, developer-friendly explanations
152182

153183
### Integration Flow
154184

155185
1. **Data Preparation**: `seed-vector-store.js` populates the vector database with dictionary content
156186
2. **Word Search Flow**: Users can search for undefined terms via `/browse/with-jai`, which uses the search API to generate instant definitions
157-
3. **Runtime Processing**: API endpoints use ✨jAI utilities for semantic search and AI response generation
158-
4. **Real-time Interaction**: Streaming responses provide immediate feedback to users
159-
5. **Context Awareness**: Vector search ensures AI responses are grounded in dictionary content
187+
3. **Follow-up Chat Flow**: Users viewing dictionary words can click "Ask jAI" to open an interactive chat widget that:
188+
- Offers default question templates for quick engagement
189+
- Accepts custom questions about the current word or related concepts
190+
- Retrieves relevant context from the vector store for accurate, grounded responses
191+
- Maintains conversation history for coherent multi-turn discussions
192+
4. **Runtime Processing**: API endpoints use ✨jAI utilities for semantic search and AI response generation
193+
5. **Real-time Interaction**: Streaming responses provide immediate feedback to users
194+
6. **Context Awareness**: Vector search ensures AI responses are grounded in dictionary content
160195

161196
## Development
162197

0 commit comments

Comments
 (0)