forked from simstudioai/sim
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathllms.ts
More file actions
38 lines (30 loc) · 1.11 KB
/
llms.ts
File metadata and controls
38 lines (30 loc) · 1.11 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
import type { InferPageType } from 'fumadocs-core/source'
import { remarkInclude } from 'fumadocs-mdx/config'
import { remark } from 'remark'
import remarkGfm from 'remark-gfm'
import remarkMdx from 'remark-mdx'
import type { source } from '@/lib/source'
const processor = remark().use(remarkMdx).use(remarkInclude).use(remarkGfm)
export async function getLLMText(page: InferPageType<typeof source>) {
// Skip pages without proper file data
if (!page?.data?._file?.absolutePath || !page?.data?.content) {
return `# ${page.data.title || 'Untitled'}
URL: ${page.url || 'Unknown'}
${page.data.description || 'No description available'}`
}
try {
const processed = await processor.process({
path: page.data._file.absolutePath,
value: page.data.content,
})
return `# ${page.data.title || 'Untitled'}
URL: ${page.url || 'Unknown'}
${page.data.description || ''}
${processed.value}`
} catch (error) {
console.error(`Error processing page ${page.url}:`, error)
return `# ${page.data.title || 'Untitled'}
URL: ${page.url || 'Unknown'}
${page.data.description || 'No description available'}`
}
}