From ea31457fc3e1f6299a66a5705b2fb61629ec3ccb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Thu, 20 Feb 2025 21:47:46 +0800 Subject: [PATCH] feat(docs): add llms.txt --- cspell.config.yaml | 1 + docs/app/llms.txt/route.ts | 45 +++++++++++++++++++++++++++++++++++++ docs/content/docs/index.mdx | 23 +++++++++++++++++++ docs/package.json | 6 +++++ pnpm-lock.yaml | 34 ++++++++++++++++------------ 5 files changed, 95 insertions(+), 14 deletions(-) create mode 100644 docs/app/llms.txt/route.ts diff --git a/cspell.config.yaml b/cspell.config.yaml index 99d4f7bd..90b6d3c4 100644 --- a/cspell.config.yaml +++ b/cspell.config.yaml @@ -19,6 +19,7 @@ words: - Hunyuan - importantimport - koemotion + - llms - masknet - ministral - mistralai diff --git a/docs/app/llms.txt/route.ts b/docs/app/llms.txt/route.ts new file mode 100644 index 00000000..f291d922 --- /dev/null +++ b/docs/app/llms.txt/route.ts @@ -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')) +} diff --git a/docs/content/docs/index.mdx b/docs/content/docs/index.mdx index f91e6851..6be911d1 100644 --- a/docs/content/docs/index.mdx +++ b/docs/content/docs/index.mdx @@ -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} +``` \ No newline at end of file diff --git a/docs/package.json b/docs/package.json index a91949c6..648305d4 100644 --- a/docs/package.json +++ b/docs/package.json @@ -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:^" diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 62e46ecb..fd6239c7 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -153,9 +153,27 @@ importers: autoprefixer: specifier: ^10.4.20 version: 10.4.20(postcss@8.5.3) + fast-glob: + specifier: ^3.3.3 + version: 3.3.3 + gray-matter: + specifier: ^4.0.3 + version: 4.0.3 postcss: specifier: ^8.5.3 version: 8.5.3 + remark: + specifier: ^15.0.1 + version: 15.0.1 + remark-gfm: + specifier: ^4.0.1 + version: 4.0.1 + remark-mdx: + specifier: ^3.1.0 + version: 3.1.0 + remark-stringify: + specifier: ^11.0.0 + version: 11.0.0 tailwindcss: specifier: ^4.0.7 version: 4.0.7 @@ -3631,10 +3649,6 @@ packages: fast-deep-equal@3.1.3: resolution: {integrity: sha512-f3qQ9oQy9j2AhBe/H9VC91wLmKBCCU/gDOnKNAYG5hswO7BLKj09Hc5HYNz9cGI++xlpDCIgDaitVs03ATR84Q==} - fast-glob@3.3.2: - resolution: {integrity: sha512-oX2ruAFQwf/Orj8m737Y5adxDQO0LAB7/S5MnxCdTNDd4p6BsyIVsv9JQsATbTSq8KHRpLwIHbVlUNatxd+1Ow==} - engines: {node: '>=8.6.0'} - fast-glob@3.3.3: resolution: {integrity: sha512-7MptL8U0cqcFdzIzwOTHoilX9x5BrNqye7Z/LuC7kCMRio1EMSyqRK3BEAUD7sXRq4iT4AzTVuZdhgQ2TCvYLg==} engines: {node: '>=8.6.0'} @@ -8090,7 +8104,7 @@ snapshots: '@typescript-eslint/types': 8.21.0 '@typescript-eslint/visitor-keys': 8.21.0 debug: 4.4.0 - fast-glob: 3.3.2 + fast-glob: 3.3.3 is-glob: 4.0.3 minimatch: 9.0.5 semver: 7.6.3 @@ -9329,14 +9343,6 @@ snapshots: fast-deep-equal@3.1.3: {} - fast-glob@3.3.2: - dependencies: - '@nodelib/fs.stat': 2.0.5 - '@nodelib/fs.walk': 1.2.8 - glob-parent: 5.1.2 - merge2: 1.4.1 - micromatch: 4.0.8 - fast-glob@3.3.3: dependencies: '@nodelib/fs.stat': 2.0.5 @@ -9621,7 +9627,7 @@ snapshots: globby@14.0.2: dependencies: '@sindresorhus/merge-streams': 2.3.0 - fast-glob: 3.3.2 + fast-glob: 3.3.3 ignore: 5.3.2 path-type: 5.0.0 slash: 5.1.0