Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 9d2fe2c

Browse files
committed
fixed AI search formatting and added load time logging
1 parent 560f274 commit 9d2fe2c

File tree

4 files changed

+40
-18
lines changed

4 files changed

+40
-18
lines changed

docs/src/components/aiSearch/AIResponse.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@ const MemoizedMarkdown = memo(({ content }: { content: string }) => (
5151
br: ({ node, ...props }) => (
5252
<br className="mb-2" {...props} />
5353
),
54-
code({ node, inline, className, children, ...props }) {
54+
code({ node, className, children, ...props }) {
5555
const match = /language-(\w+)/.exec(className || '')
56-
return inline ? (
57-
<code className={className} {...props}>
58-
{children}
59-
</code>
60-
) : (
56+
return (
6157
<div className="relative">
6258
<code className={`language-${match?.[1] || 'text'}`} {...props}>
6359
{children}

docs/src/lib/aisearch/embeddings.worker.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@ class EmbeddingPipelineSingleton {
66
static instance: Promise<any> | null = null;
77

88
static async getInstance(progress_callback: ProgressCallback | null = null) {
9-
this.instance ??= pipeline(this.task, this.model, {
10-
progress_callback: progress_callback ?? undefined
11-
});
9+
if (!this.instance) {
10+
console.log('[Embeddings Worker] Initializing embedding pipeline...');
11+
const startTime = performance.now();
12+
13+
this.instance = pipeline(this.task, this.model, {
14+
progress_callback: (progress) => {
15+
progress_callback?.(progress);
16+
}
17+
}).then((pipeline) => {
18+
const loadTime = (performance.now() - startTime) / 1000;
19+
console.log(`[Embeddings Worker] Pipeline ready in ${loadTime.toFixed(2)}s`);
20+
return pipeline;
21+
});
22+
}
23+
1224
return this.instance;
1325
}
1426
}
@@ -18,10 +30,13 @@ self.addEventListener('message', async (event) => {
1830
self.postMessage({ status: 'progress', progress: x });
1931
});
2032

33+
const startTime = performance.now();
2134
const output = await embedder(event.data.text, {
2235
pooling: 'mean',
2336
normalize: true
2437
});
38+
const inferenceTime = (performance.now() - startTime) / 1000;
39+
console.log(`[Embeddings Worker] Embedding generated in ${inferenceTime.toFixed(2)}s`);
2540

2641
self.postMessage({
2742
status: 'complete',

packages/akiradocs/src/components/aiSearch/AIResponse.tsx

+2-6
Original file line numberDiff line numberDiff line change
@@ -51,13 +51,9 @@ const MemoizedMarkdown = memo(({ content }: { content: string }) => (
5151
br: ({ node, ...props }) => (
5252
<br className="mb-2" {...props} />
5353
),
54-
code({ node, inline, className, children, ...props }) {
54+
code({ node, className, children, ...props }) {
5555
const match = /language-(\w+)/.exec(className || '')
56-
return inline ? (
57-
<code className={className} {...props}>
58-
{children}
59-
</code>
60-
) : (
56+
return (
6157
<div className="relative">
6258
<code className={`language-${match?.[1] || 'text'}`} {...props}>
6359
{children}

packages/akiradocs/src/lib/aisearch/embeddings.worker.ts

+18-3
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,21 @@ class EmbeddingPipelineSingleton {
66
static instance: Promise<any> | null = null;
77

88
static async getInstance(progress_callback: ProgressCallback | null = null) {
9-
this.instance ??= pipeline(this.task, this.model, {
10-
progress_callback: progress_callback ?? undefined
11-
});
9+
if (!this.instance) {
10+
console.log('[Embeddings Worker] Initializing embedding pipeline...');
11+
const startTime = performance.now();
12+
13+
this.instance = pipeline(this.task, this.model, {
14+
progress_callback: (progress) => {
15+
progress_callback?.(progress);
16+
}
17+
}).then((pipeline) => {
18+
const loadTime = (performance.now() - startTime) / 1000;
19+
console.log(`[Embeddings Worker] Pipeline ready in ${loadTime.toFixed(2)}s`);
20+
return pipeline;
21+
});
22+
}
23+
1224
return this.instance;
1325
}
1426
}
@@ -18,10 +30,13 @@ self.addEventListener('message', async (event) => {
1830
self.postMessage({ status: 'progress', progress: x });
1931
});
2032

33+
const startTime = performance.now();
2134
const output = await embedder(event.data.text, {
2235
pooling: 'mean',
2336
normalize: true
2437
});
38+
const inferenceTime = (performance.now() - startTime) / 1000;
39+
console.log(`[Embeddings Worker] Embedding generated in ${inferenceTime.toFixed(2)}s`);
2540

2641
self.postMessage({
2742
status: 'complete',

0 commit comments

Comments
 (0)