Skip to content

Commit

Permalink
feat(docs): add llms.txt
Browse files Browse the repository at this point in the history
  • Loading branch information
kwaa committed Feb 20, 2025
1 parent df122dd commit ea31457
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 14 deletions.
1 change: 1 addition & 0 deletions cspell.config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ words:
- Hunyuan
- importantimport
- koemotion
- llms
- masknet
- ministral
- mistralai
Expand Down
45 changes: 45 additions & 0 deletions docs/app/llms.txt/route.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
import fg from 'fast-glob'
import { remarkInstall } from 'fumadocs-docgen'
import { remarkInclude } from 'fumadocs-mdx/config'
import matter from 'gray-matter'
import { readFile } from 'node:fs/promises'
import { remark } from 'remark'
import remarkGfm from 'remark-gfm'
import remarkMdx from 'remark-mdx'
import remarkStringify from 'remark-stringify'

export const revalidate = false

const processContent = async (content: string) => String(await remark()
.use(remarkMdx)
// https://fumadocs.vercel.app/docs/mdx/include
.use(remarkInclude)
// gfm styles
.use(remarkGfm)
// your remark plugins
.use(remarkInstall, { persist: { id: 'package-manager' } })
// to string
.use(remarkStringify)
.process(content))

/** @see {@link https://fumadocs.vercel.app/docs/ui/llms} */
export const GET = async () => {
// all scanned content
const files = await fg(['./content/docs/**/*.mdx'])

const scan = files.map(async (file) => {
const fileContent = await readFile(file)
const { content, data } = matter(fileContent.toString())
const processed = await processContent(content)
return [
`file: ${file}`,
`meta: ${JSON.stringify(data, null, 2)}`,
'',
processed,
].join('\n')
})

const scanned = await Promise.all(scan)

return new Response(scanned.join('\n\n'))
}
23 changes: 23 additions & 0 deletions docs/content/docs/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,26 @@ description: extra-small AI SDK for Browser, Node.js, Deno, Bun or Edge Runtime.
xsAI has a similar interface to the Vercel AI SDK, but is significantly smaller.

This makes it ideal for a variety of scenarios that require smaller bundle size, such as web applications, cli running through npx, and so on.

## `llms.txt`

You can access the entire xsAI documentation in Markdown format at https://xsai.js.org/llms.txt.

This can be used to ask any LLM (assuming it has a big enough context window)

questions about the xsAI based on the most up-to-date documentation.

### Example Usage

For instance, to prompt an LLM with questions about the xsAI:

1. Copy the documentation contents from https://xsai.js.org/llms.txt
2. Use the following prompt format:

```
Documentation:
{paste documentation here}
---
Based on the above documentation, answer the following:
{your question}
```
6 changes: 6 additions & 0 deletions docs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@
"@xsai/stream-text": "workspace:^",
"@xsai/tool": "workspace:^",
"autoprefixer": "^10.4.20",
"fast-glob": "^3.3.3",
"gray-matter": "^4.0.3",
"postcss": "^8.5.3",
"remark": "^15.0.1",
"remark-gfm": "^4.0.1",
"remark-mdx": "^3.1.0",
"remark-stringify": "^11.0.0",
"tailwindcss": "^4.0.7",
"valibot": "catalog:",
"xsai": "workspace:^"
Expand Down
34 changes: 20 additions & 14 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit ea31457

Please sign in to comment.