Skip to content

Commit 3a7c3dc

Browse files
feat: add interactive playground tools to documentation
This commit adds three interactive React components to enhance the documentation experience: Interactive Components: 1. Code Playground - Live code editor with 4 preset examples - StackBlitz integration for instant environment - Copy-to-clipboard functionality - Examples: Basic pipeline, Custom embedder, Caching, Security 2. Configuration Generator - Step-by-step wizard for pipeline configuration - 4-step process: Embedder → Retriever → LLM → Advanced - Real-time code generation - Visual selection of components and options 3. Performance Calculator - Real-time throughput and latency estimation - Cost analysis per query and monthly - Automatic optimization recommendations - Configurable parameters: queries, embedder, caching, retriever, LLM New Files: - src/components/CodePlayground/index.jsx - src/components/CodePlayground/styles.module.css - src/components/ConfigGenerator/index.jsx - src/components/ConfigGenerator/styles.module.css - src/components/PerformanceCalculator/index.jsx - src/components/PerformanceCalculator/styles.module.css - docs/Interactive-Tools.mdx Features: - Fully responsive design - Dark mode support - Production-ready React components - Zero external dependencies - Accessible UI with keyboard navigation Updated Navigation: - Added "Interactive Tools" to Developer Guide section - Build verified successfully 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent bf6f574 commit 3a7c3dc

File tree

8 files changed

+1732
-1
lines changed

8 files changed

+1732
-1
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
---
2+
sidebar_position: 8
3+
---
4+
5+
# Interactive Tools
6+
7+
Explore RAG Pipeline Utils with our interactive tools designed to help you build, configure, and optimize your RAG applications.
8+
9+
## Code Playground
10+
11+
Try RAG Pipeline Utils directly in your browser with live code examples.
12+
13+
import CodePlayground from "@site/src/components/CodePlayground";
14+
15+
<CodePlayground />
16+
17+
## Configuration Generator
18+
19+
Build your RAG pipeline configuration step-by-step with our interactive wizard.
20+
21+
import ConfigGenerator from "@site/src/components/ConfigGenerator";
22+
23+
<ConfigGenerator />
24+
25+
## Performance Calculator
26+
27+
Estimate throughput, latency, and costs for your RAG pipeline based on your configuration.
28+
29+
import PerformanceCalculator from "@site/src/components/PerformanceCalculator";
30+
31+
<PerformanceCalculator />
32+
33+
## Additional Resources
34+
35+
- [Getting Started Guide](/docs/Introduction)
36+
- [API Reference](/docs/API-Reference)
37+
- [Deployment Guides](/docs/Deployment-Docker)
38+
- [Performance Optimization](/docs/Performance)

docs-site/sidebars.js

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,14 @@ const sidebars = {
2020
type: "category",
2121
label: "Developer Guide",
2222
collapsed: false,
23-
items: ["Usage", "CLI", "API-Reference", "Examples", "Plugins"],
23+
items: [
24+
"Usage",
25+
"CLI",
26+
"API-Reference",
27+
"Examples",
28+
"Interactive-Tools",
29+
"Plugins",
30+
],
2431
},
2532
{
2633
type: "category",
Lines changed: 263 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,263 @@
1+
import React, { useState } from "react";
2+
import styles from "./styles.module.css";
3+
4+
const EXAMPLES = {
5+
basic: {
6+
title: "Basic RAG Pipeline",
7+
code: `const { createRagPipeline } = require('@devilsdev/rag-pipeline-utils');
8+
9+
// Initialize pipeline
10+
const pipeline = createRagPipeline({
11+
embedder: {
12+
type: 'openai',
13+
apiKey: process.env.OPENAI_API_KEY
14+
},
15+
retriever: {
16+
type: 'pinecone',
17+
apiKey: process.env.PINECONE_API_KEY,
18+
indexName: 'docs'
19+
},
20+
llm: {
21+
type: 'openai',
22+
model: 'gpt-3.5-turbo'
23+
}
24+
});
25+
26+
// Ingest documents
27+
await pipeline.ingest('./documents');
28+
29+
// Query the pipeline
30+
const result = await pipeline.query('How does authentication work?');
31+
console.log(result.answer);`,
32+
},
33+
customEmbedder: {
34+
title: "Custom Embedder",
35+
code: `const { createRagPipeline } = require('@devilsdev/rag-pipeline-utils');
36+
37+
// Define custom embedder
38+
class CustomEmbedder {
39+
async embed(text) {
40+
// Your custom embedding logic
41+
const embedding = await this.computeEmbedding(text);
42+
return embedding;
43+
}
44+
45+
async embedBatch(texts) {
46+
// Batch processing for efficiency
47+
return Promise.all(texts.map(t => this.embed(t)));
48+
}
49+
50+
async computeEmbedding(text) {
51+
// Example: Use a local model or API
52+
const response = await fetch('http://localhost:8080/embed', {
53+
method: 'POST',
54+
body: JSON.stringify({ text }),
55+
headers: { 'Content-Type': 'application/json' }
56+
});
57+
return response.json();
58+
}
59+
}
60+
61+
// Use custom embedder in pipeline
62+
const pipeline = createRagPipeline({
63+
embedder: new CustomEmbedder(),
64+
retriever: myRetriever,
65+
llm: myLLM
66+
});`,
67+
},
68+
caching: {
69+
title: "Caching Strategy",
70+
code: `const { createRagPipeline } = require('@devilsdev/rag-pipeline-utils');
71+
const NodeCache = require('node-cache');
72+
73+
class CachedEmbedder {
74+
constructor(baseEmbedder) {
75+
this.baseEmbedder = baseEmbedder;
76+
this.cache = new NodeCache({
77+
stdTTL: 3600, // 1 hour
78+
maxKeys: 10000
79+
});
80+
}
81+
82+
async embed(text) {
83+
const key = this.hash(text);
84+
85+
// Check cache
86+
const cached = this.cache.get(key);
87+
if (cached) return cached;
88+
89+
// Compute and cache
90+
const embedding = await this.baseEmbedder.embed(text);
91+
this.cache.set(key, embedding);
92+
return embedding;
93+
}
94+
95+
hash(text) {
96+
return require('crypto')
97+
.createHash('md5')
98+
.update(text.toLowerCase().trim())
99+
.digest('hex');
100+
}
101+
}
102+
103+
const pipeline = createRagPipeline({
104+
embedder: new CachedEmbedder(baseEmbedder),
105+
retriever: myRetriever,
106+
llm: myLLM
107+
});`,
108+
},
109+
security: {
110+
title: "Security & Authentication",
111+
code: `const {
112+
createRagPipeline,
113+
JwtValidator,
114+
InputSanitizer,
115+
RateLimiter
116+
} = require('@devilsdev/rag-pipeline-utils');
117+
118+
// Setup security components
119+
const jwtValidator = new JwtValidator({
120+
issuer: 'https://auth.example.com',
121+
audience: 'rag-api'
122+
});
123+
124+
const sanitizer = new InputSanitizer({
125+
maxLength: 2000,
126+
blockPatterns: [/ignore.*previous/i]
127+
});
128+
129+
const limiter = new RateLimiter({
130+
capacity: 100,
131+
refillRate: 10
132+
});
133+
134+
// Protected endpoint
135+
app.post('/api/query', async (req, res) => {
136+
try {
137+
// Authenticate
138+
const user = await jwtValidator.validate(
139+
req.headers.authorization
140+
);
141+
142+
// Rate limit
143+
await limiter.checkLimit(user.id);
144+
145+
// Sanitize input
146+
const query = sanitizer.sanitize(req.body.query);
147+
148+
// Query pipeline
149+
const result = await pipeline.query(query);
150+
151+
res.json(result);
152+
} catch (error) {
153+
res.status(401).json({ error: error.message });
154+
}
155+
});`,
156+
},
157+
};
158+
159+
export default function CodePlayground() {
160+
const [selectedExample, setSelectedExample] = useState("basic");
161+
const [code, setCode] = useState(EXAMPLES.basic.code);
162+
163+
const handleExampleChange = (exampleKey) => {
164+
setSelectedExample(exampleKey);
165+
setCode(EXAMPLES[exampleKey].code);
166+
};
167+
168+
const openInStackBlitz = () => {
169+
const project = {
170+
title: "RAG Pipeline Utils Example",
171+
description: "Interactive example using RAG Pipeline Utils",
172+
template: "node",
173+
files: {
174+
"index.js": code,
175+
"package.json": JSON.stringify(
176+
{
177+
name: "rag-pipeline-example",
178+
version: "1.0.0",
179+
dependencies: {
180+
"@devilsdev/rag-pipeline-utils": "^2.3.1",
181+
},
182+
},
183+
null,
184+
2,
185+
),
186+
"README.md":
187+
"# RAG Pipeline Utils Example\n\nRun `node index.js` to execute.",
188+
},
189+
};
190+
191+
const form = document.createElement("form");
192+
form.method = "POST";
193+
form.action = "https://stackblitz.com/run";
194+
form.target = "_blank";
195+
196+
const input = document.createElement("input");
197+
input.type = "hidden";
198+
input.name = "project[files]";
199+
input.value = JSON.stringify(project);
200+
form.appendChild(input);
201+
202+
document.body.appendChild(form);
203+
form.submit();
204+
document.body.removeChild(form);
205+
};
206+
207+
const copyToClipboard = () => {
208+
navigator.clipboard.writeText(code);
209+
alert("Code copied to clipboard!");
210+
};
211+
212+
return (
213+
<div className={styles.playground}>
214+
<div className={styles.header}>
215+
<h2>Interactive Code Playground</h2>
216+
<p>Explore RAG Pipeline Utils with live examples</p>
217+
</div>
218+
219+
<div className={styles.exampleSelector}>
220+
{Object.entries(EXAMPLES).map(([key, example]) => (
221+
<button
222+
key={key}
223+
className={`${styles.exampleButton} ${
224+
selectedExample === key ? styles.active : ""
225+
}`}
226+
onClick={() => handleExampleChange(key)}
227+
>
228+
{example.title}
229+
</button>
230+
))}
231+
</div>
232+
233+
<div className={styles.editorContainer}>
234+
<div className={styles.editorHeader}>
235+
<span className={styles.filename}>index.js</span>
236+
<div className={styles.actions}>
237+
<button onClick={copyToClipboard} className={styles.actionButton}>
238+
Copy
239+
</button>
240+
<button onClick={openInStackBlitz} className={styles.actionButton}>
241+
Open in StackBlitz
242+
</button>
243+
</div>
244+
</div>
245+
<textarea
246+
className={styles.editor}
247+
value={code}
248+
onChange={(e) => setCode(e.target.value)}
249+
spellCheck={false}
250+
/>
251+
</div>
252+
253+
<div className={styles.info}>
254+
<h3>Try it yourself:</h3>
255+
<ol>
256+
<li>Modify the code above to experiment</li>
257+
<li>Click "Open in StackBlitz" to run in a live environment</li>
258+
<li>Or copy the code and run locally with npm</li>
259+
</ol>
260+
</div>
261+
</div>
262+
);
263+
}

0 commit comments

Comments
 (0)