You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
## 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 -->
Fixesjargonsdev/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
- 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
66
77
67
78
#### `lib/model.js`
68
79
@@ -98,6 +109,19 @@ React component that powers the AI-driven word definition feature. Includes:
98
109
- Error handling and loading states
99
110
- Integration with the `/api/jai/search` endpoint
100
111
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
+
101
125
## Environment Variables
102
126
103
127
✨jAI requires the following environment variables:
@@ -146,17 +170,28 @@ Dedicated endpoint for AI-powered word definitions that:
146
170
- Provides fallback definitions for terms not yet in the dictionary
147
171
- Powers the `/browse/with-jai` page and word search components
148
172
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:
150
176
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
152
182
153
183
### Integration Flow
154
184
155
185
1.**Data Preparation**: `seed-vector-store.js` populates the vector database with dictionary content
156
186
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
0 commit comments