|
| 1 | +<div align="center" style="margin-top: 12px"> |
| 2 | + <a href="https://www.jargons.dev"> |
| 3 | + <img width="300" alt="jargons.dev AI" src="https://github.com/user-attachments/assets/5459f7e3-2e23-43bf-b52b-2f198c1dd413"> |
| 4 | + </a> |
| 5 | + <h1><tt>jargons.dev AI (jAI)</tt></h1> |
| 6 | + <h3>The AI-Powered Assistant for jargons.dev</h3> |
| 7 | +</div> |
| 8 | + |
| 9 | +## About |
| 10 | + |
| 11 | +✨jAI is a Retrieval-Augmented Generation (RAG) application that integrates the `jargons.dev` dictionary as its core knowledge base. This module serves as the AI utilities layer for the main jargons.dev application, providing intelligent assistance and semantic search capabilities throughout the platform. |
| 12 | + |
| 13 | +Unlike standalone AI applications, ✨jAI is deeply integrated into the jargons.dev ecosystem, powering features like: |
| 14 | + |
| 15 | +- Intelligent word explanations and follow-up conversations |
| 16 | +- Semantic search across the dictionary |
| 17 | +- Context-aware responses based on the curated dictionary content |
| 18 | +- Real-time AI assistance for developers exploring technical terms |
| 19 | + |
| 20 | +## Tech Stack |
| 21 | + |
| 22 | +✨jAI is built using the following technologies: |
| 23 | + |
| 24 | +- [OpenAI API](https://openai.com/api/) - Platform for building AI experiences powered by industry-leading models and tools. Powers AI chat responses and generates embeddings for semantic search |
| 25 | +- [Qdrant](https://qdrant.tech/) - Vector database and similarity search engine for AI applications. Stores and searches vector embeddings of dictionary content for context retrieval |
| 26 | +- [LangChain](https://langchain.com/) - Framework for developing applications powered by large language models (LLMs) |
| 27 | + |
| 28 | +## Module Structure |
| 29 | + |
| 30 | +The ✨jAI module is organized into focused utility files: |
| 31 | + |
| 32 | +``` |
| 33 | +apps/jai/ |
| 34 | +├── index.js # Main exports and module interface |
| 35 | +└── lib/ |
| 36 | + ├── jai-prompt.js # AI personality and prompt templates |
| 37 | + ├── model.js # OpenAI model configuration |
| 38 | + ├── utils.js # Utility functions for message formatting |
| 39 | + └── vector-store.js # Qdrant vector store integration |
| 40 | +``` |
| 41 | + |
| 42 | +### Core Components |
| 43 | + |
| 44 | +#### `index.js` |
| 45 | + |
| 46 | +Main module interface that exports all ✨jAI utilities: |
| 47 | + |
| 48 | +```javascript |
| 49 | +export { jAIPrompt, formatMessage, model, vectorStore }; |
| 50 | +``` |
| 51 | + |
| 52 | +#### `lib/jai-prompt.js` |
| 53 | + |
| 54 | +Defines ✨jAI's personality and conversation templates. The AI assistant is designed to: |
| 55 | + |
| 56 | +- Explain technical jargon clearly and concisely |
| 57 | +- Use relatable analogies and developer-friendly examples |
| 58 | +- Maintain a friendly, witty personality |
| 59 | +- Encourage follow-up questions and deeper exploration |
| 60 | + |
| 61 | +#### `lib/model.js` |
| 62 | + |
| 63 | +Configures the OpenAI ChatGPT model with optimized settings for technical explanations: |
| 64 | + |
| 65 | +- Streaming responses for real-time interaction |
| 66 | +- Temperature tuned for consistent, helpful responses |
| 67 | +- Token limits optimized for concise explanations |
| 68 | + |
| 69 | +#### `lib/vector-store.js` |
| 70 | + |
| 71 | +Manages the Qdrant vector database integration: |
| 72 | + |
| 73 | +- Semantic search across dictionary content |
| 74 | +- OpenAI embeddings for high-quality similarity matching |
| 75 | +- Production-ready vector store connection |
| 76 | + |
| 77 | +#### `lib/utils.js` |
| 78 | + |
| 79 | +Utility functions for message processing and formatting. |
| 80 | + |
| 81 | +## Environment Variables |
| 82 | + |
| 83 | +✨jAI requires the following environment variables: |
| 84 | + |
| 85 | +```bash |
| 86 | +# OpenAI Configuration |
| 87 | +OPENAI_API_KEY=your_openai_api_key |
| 88 | +OPENAI_CHAT_MODEL=gpt-4-turbo-preview # or your preferred model |
| 89 | +OPENAI_EMBEDDINGS_MODEL=text-embedding-3-small |
| 90 | + |
| 91 | +# Qdrant Vector Database |
| 92 | +QDRANT_URL=your_qdrant_instance_url |
| 93 | +QDRANT_API_KEY=your_qdrant_api_key |
| 94 | +``` |
| 95 | + |
| 96 | +## Setup and Usage |
| 97 | + |
| 98 | +### 1. Prerequisites |
| 99 | + |
| 100 | +Ensure you have the required environment variables configured in your `.env` file at the project root. |
| 101 | + |
| 102 | +### 2. Seed the Vector Store |
| 103 | + |
| 104 | +Before using ✨jAI, you need to populate the vector store with dictionary content: |
| 105 | + |
| 106 | +```bash |
| 107 | +npm run seed:jai |
| 108 | +``` |
| 109 | + |
| 110 | +This command processes all dictionary entries and creates embeddings for semantic search. |
| 111 | + |
| 112 | +## Architecture Integration |
| 113 | + |
| 114 | +✨jAI is designed as a utility module that integrates seamlessly with the main jargons.dev application. The module is consumed in two primary areas: |
| 115 | + |
| 116 | +### 1. Vector Store Seeding (`dev/seed-vector-store.js`) |
| 117 | + |
| 118 | +Uses the `vectorStore` utility to populate the database with dictionary content. The script fetches dictionary entries from the jargons.dev API, processes them into document chunks, and creates vector embeddings for semantic search capabilities. |
| 119 | + |
| 120 | +### 2. API Endpoint (`src/pages/api/jai/follow-up-chat.js`) |
| 121 | + |
| 122 | +Imports all four core utilities (`jAIPrompt`, `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. |
| 123 | + |
| 124 | +### Integration Flow |
| 125 | + |
| 126 | +1. **Data Preparation**: `seed-vector-store.js` populates the vector database with dictionary content |
| 127 | +2. **Runtime Processing**: API endpoints use ✨jAI utilities for semantic search and AI response generation |
| 128 | +3. **Real-time Interaction**: Streaming responses provide immediate feedback to users |
| 129 | +4. **Context Awareness**: Vector search ensures AI responses are grounded in dictionary content |
| 130 | + |
| 131 | +## Development |
| 132 | + |
| 133 | +### Local Development |
| 134 | + |
| 135 | +✨jAI runs as part of the main jargons.dev development environment: |
| 136 | + |
| 137 | +```bash |
| 138 | +npm start # Starts the development server with ✨jAI enabled |
| 139 | +``` |
| 140 | + |
| 141 | +### Testing |
| 142 | + |
| 143 | +AI functionality is tested as part of the main project's test suite: |
| 144 | + |
| 145 | +```bash |
| 146 | +npm run test # Run all tests including AI utilities |
| 147 | +npm run test:coverage # Generate coverage report |
| 148 | +``` |
| 149 | + |
| 150 | +## Contributing |
| 151 | + |
| 152 | +Contributions to ✨jAI are welcome! Please refer to the main project's [Contribution Guide](../../CONTRIBUTING.md) for guidelines. |
| 153 | + |
| 154 | +When contributing to ✨jAI specifically: |
| 155 | + |
| 156 | +- Follow the modular structure for new utilities |
| 157 | +- Maintain the friendly, developer-focused AI personality |
| 158 | +- Test AI responses for accuracy and helpfulness |
| 159 | +- Document any new environment variables or setup steps |
| 160 | + |
| 161 | +## Support |
| 162 | + |
| 163 | +✨jAI is part of the open-source jargons.dev project. Do leave the project a star ⭐️ |
| 164 | + |
| 165 | +For ✨jAI-specific issues or questions, please use the main project's issue tracker with the `✨jai` label. |
| 166 | + |
| 167 | +--- |
| 168 | + |
| 169 | +**[Back to main jargons.dev project](../../README.md)** |
0 commit comments