Skip to content

Commit af89fa4

Browse files
committed
refac
1 parent 8805e1b commit af89fa4

4 files changed

Lines changed: 111 additions & 1 deletion

File tree

docs/intro.mdx

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -168,3 +168,16 @@ Need **custom branding**, **SLA support**, or **Long-Term Support (LTS)** versio
168168
</a>
169169

170170
</div>
171+
172+
---
173+
174+
## For LLMs and coding agents
175+
176+
Machine-readable entry points to this documentation:
177+
178+
- [llms.txt](https://docs.openwebui.com/llms.txt): curated index of every docs page with short descriptions.
179+
- [llms-full.txt](https://docs.openwebui.com/llms-full.txt): every docs page concatenated into a single Markdown file.
180+
- [agents.txt](https://docs.openwebui.com/agents.txt): concise instructions for agents using these docs.
181+
- [api/search?q=YOUR_QUERY](https://docs.openwebui.com/api/search?q=YOUR_QUERY): deterministic docs search.
182+
183+
All files are generated fresh on every deploy.

package.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
"docusaurus": "docusaurus",
77
"start": "docusaurus start",
88
"build": "docusaurus build",
9-
"postbuild": "node scripts/generate-raw-docs.mjs && node scripts/generate-search-corpus.mjs",
9+
"postbuild": "node scripts/generate-raw-docs.mjs && node scripts/generate-search-corpus.mjs && node scripts/generate-llms-files.mjs",
1010
"raw-docs": "node scripts/generate-raw-docs.mjs",
1111
"search-corpus": "node scripts/generate-search-corpus.mjs",
12+
"llms-files": "node scripts/generate-llms-files.mjs",
1213
"test:docs-search": "node scripts/test-docs-search.mjs",
1314
"swizzle": "docusaurus swizzle",
1415
"deploy": "docusaurus deploy",

scripts/generate-llms-files.mjs

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
import fs from "node:fs";
2+
import path from "node:path";
3+
4+
const BUILD_DIR = "build";
5+
const CORPUS_PATH = path.join(BUILD_DIR, "search-corpus.json");
6+
const LLMS_PATH = path.join(BUILD_DIR, "llms.txt");
7+
const LLMS_FULL_PATH = path.join(BUILD_DIR, "llms-full.txt");
8+
9+
function normalizeWhitespace(text) {
10+
return text.replace(/\s+/g, " ").trim();
11+
}
12+
13+
function truncate(text, maxLength) {
14+
if (text.length <= maxLength) {
15+
return text;
16+
}
17+
18+
return `${text.slice(0, maxLength - 1).trimEnd()}...`;
19+
}
20+
21+
function cleanMarkdownInline(text) {
22+
return normalizeWhitespace(
23+
text
24+
.replace(/!\[[^\]]*]\([^)]+\)/g, "")
25+
.replace(/\[([^\]]+)]\([^)]+\)/g, "$1")
26+
.replace(/[*_`]/g, "")
27+
);
28+
}
29+
30+
function descriptionFor(content) {
31+
const lines = content
32+
.split("\n")
33+
.map((line) => line.trim())
34+
.filter(Boolean)
35+
.filter((line) => !line.startsWith("#"))
36+
.filter((line) => !line.startsWith("Source:"))
37+
.filter((line) => !line.startsWith(":::"))
38+
.filter((line) => !line.startsWith("import "));
39+
40+
const firstUsefulLine = lines.find((line) => !line.startsWith("|")) || "";
41+
return truncate(normalizeWhitespace(firstUsefulLine), 180);
42+
}
43+
44+
if (!fs.existsSync(CORPUS_PATH)) {
45+
throw new Error("Run `npm run build` before generating llms files.");
46+
}
47+
48+
const { docs } = JSON.parse(fs.readFileSync(CORPUS_PATH, "utf8"));
49+
50+
const generatedAt = new Date().toISOString();
51+
const llmsLines = [
52+
"# Open WebUI Docs",
53+
"",
54+
"Machine-readable entry points to this documentation:",
55+
"",
56+
"- /llms.txt - curated index of every docs page with short descriptions.",
57+
"- /llms-full.txt - every docs page concatenated into a single Markdown file.",
58+
"- /sitemap.xml - canonical HTML page discovery.",
59+
"- /api/search?q=YOUR_QUERY - deterministic docs search.",
60+
"",
61+
"For any docs page, append `.md` for Markdown or `.txt` for plain text.",
62+
"When citing sources, cite canonical HTML URLs, not `.md`, `.txt`, search API, sitemap, agents.txt, or llms.txt URLs.",
63+
"",
64+
`Generated: ${generatedAt}`,
65+
"",
66+
"## Pages",
67+
"",
68+
];
69+
70+
for (const doc of docs) {
71+
llmsLines.push(
72+
`- [${cleanMarkdownInline(doc.title)}](${doc.url}): ${descriptionFor(doc.content)}`
73+
);
74+
}
75+
76+
fs.writeFileSync(LLMS_PATH, `${llmsLines.join("\n")}\n`);
77+
78+
const fullLines = [
79+
"# Open WebUI Docs Full Corpus",
80+
"",
81+
"Every docs page concatenated into a single Markdown file.",
82+
"When citing sources, cite canonical HTML URLs.",
83+
"",
84+
`Generated: ${generatedAt}`,
85+
"",
86+
];
87+
88+
for (const doc of docs) {
89+
fullLines.push("---", "", doc.content.trim(), "");
90+
}
91+
92+
fs.writeFileSync(LLMS_FULL_PATH, `${fullLines.join("\n")}\n`);
93+
94+
console.log(`Generated llms.txt and llms-full.txt for ${docs.length} docs pages.`);

static/agents.txt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@ This site is agent-readable.
55
Start at https://docs.openwebui.com/sitemap.xml to discover docs pages.
66
Use https://docs.openwebui.com/api/search?q=YOUR_QUERY for docs search.
77
For any docs page, append `.md` for Markdown or `.txt` for plain text.
8+
Use https://docs.openwebui.com/llms.txt for a compact page index.
9+
Use https://docs.openwebui.com/llms-full.txt for a full Markdown corpus.
810

911
When citing sources, cite the canonical HTML URL, not the `.md`, `.txt`, or
1012
search API URL.

0 commit comments

Comments
 (0)