-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsetup.js
More file actions
109 lines (85 loc) · 4.15 KB
/
setup.js
File metadata and controls
109 lines (85 loc) · 4.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
import fs from 'fs';
import path from 'path';
import { fileURLToPath } from 'url';
import { dirname } from 'path';
const __filename = fileURLToPath(import.meta.url);
const __dirname = dirname(__filename);
async function setup() {
console.log('🚀 Setting up RAG Q&A Chatbot...\n');
// Check if .env exists
const envPath = path.join(__dirname, '.env');
const envExamplePath = path.join(__dirname, '.env.example');
if (!fs.existsSync(envPath)) {
console.log('📝 Creating .env file from .env.example...');
fs.copyFileSync(envExamplePath, envPath);
console.log('✅ .env file created\n');
}
// Display setup instructions
console.log('🔧 Setup Instructions:');
console.log('='.repeat(50));
console.log('1. Configure your API keys in the .env file:');
console.log(' - Get free OpenAI credits: https://platform.openai.com');
console.log(' - Get free Claude credits: https://console.anthropic.com');
console.log(' - Get free Gemini API: https://makersuite.google.com');
console.log(' - Get free Cohere API: https://cohere.ai');
console.log(' - Get free HuggingFace API: https://huggingface.co\n');
console.log('2. Default Configuration (works without API keys):');
console.log(' - Uses Hugging Face free inference API');
console.log(' - Fallback embedding system');
console.log(' - In-memory vector storage\n');
console.log('3. Supported File Types:');
console.log(' - PDF documents');
console.log(' - Word documents (.doc, .docx)');
console.log(' - Text files (.txt, .md)');
console.log(' - CSV files');
console.log(' - HTML files');
console.log(' - JSON files\n');
console.log('4. Features:');
console.log(' ✅ Document upload and processing');
console.log(' ✅ Vector similarity search');
console.log(' ✅ Multiple LLM providers');
console.log(' ✅ Real-time WebSocket chat');
console.log(' ✅ Streaming responses');
console.log(' ✅ Source attribution');
console.log(' ✅ Beautiful web interface\n');
console.log('5. Getting Started:');
console.log(' npm install # Install dependencies');
console.log(' npm start # Start the server');
console.log(' Open: http://localhost:3000\n');
console.log('6. Development:');
console.log(' npm run dev # Start with auto-reload\n');
console.log('🎉 Setup complete! Ready to start your RAG chatbot.');
console.log('📚 Upload documents and start asking questions!\n');
// Create sample documents directory
const sampleDocsDir = path.join(__dirname, 'sample-documents');
if (!fs.existsSync(sampleDocsDir)) {
fs.mkdirSync(sampleDocsDir);
// Create a sample document
const sampleContent = `# Welcome to RAG Q&A Chatbot
## About This System
This is an advanced Retrieval-Augmented Generation (RAG) chatbot that can answer questions based on your uploaded documents.
### Key Features
1. **Document Processing**: Upload PDF, Word, text, and other document formats
2. **Intelligent Search**: Vector-based similarity search to find relevant content
3. **AI Responses**: Multiple LLM providers including OpenAI, Claude, Gemini, and more
4. **Real-time Chat**: WebSocket-based streaming responses
5. **Source Attribution**: See which documents were used to answer your questions
### How It Works
1. Upload your documents using the file upload area
2. The system processes and chunks your documents
3. Creates vector embeddings for semantic search
4. When you ask a question, it finds relevant content
5. Uses AI to generate a comprehensive answer
### Getting Started
Try asking questions like:
- "What are the main points in this document?"
- "Summarize the key findings"
- "What recommendations are mentioned?"
- "Compare different approaches discussed"
Enjoy exploring your documents with AI assistance!`;
fs.writeFileSync(path.join(sampleDocsDir, 'welcome.md'), sampleContent);
console.log('📄 Created sample document: sample-documents/welcome.md');
console.log('💡 Upload this file to test the system!\n');
}
}
setup().catch(console.error);