Skip to content

Commit c0deffd

Browse files
authored
feat: new documentation website (#62)
* feat: new documentation website * feat: improve `chat` command * chore: add CPU info to default bug report template
1 parent ada896b commit c0deffd

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

45 files changed

+3071
-506
lines changed

.config/typedoc.json

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"$schema": "https://typedoc.org/schema.json",
33
"entryPoints": ["../src/index.ts"],
4-
"out": "../docs-site",
4+
"out": "../docs/api",
55
"tsconfig": "../tsconfig.json",
66
"customCss": "./typedoc.css",
77
"readme": "../README.md",
@@ -11,5 +11,12 @@
1111
"githubPages": true,
1212
"hideGenerator": true,
1313
"jsDocCompatibility": true,
14-
"htmlLang": "en"
14+
"htmlLang": "en",
15+
"plugin": ["typedoc-plugin-markdown", "typedoc-vitepress-theme", "typedoc-plugin-mdn-links"],
16+
"hideBreadcrumbs": true,
17+
"hidePageHeader": true,
18+
"preserveAnchorCasing": true,
19+
"useCodeBlocks": true,
20+
"expandObjects": true,
21+
"parametersFormat": "table"
1522
}

.github/ISSUE_TEMPLATE/bug-report.yml

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -52,12 +52,13 @@ body:
5252
Please add any other relevant dependencies to this table at the end.
5353
For example: Electron, Bun, Webpack.
5454
value: |
55-
| Dependency | Version |
56-
| --- | --- |
57-
| Operating System | |
58-
| Node.js version | x.y.zzz |
59-
| Typescript version | x.y.zzz |
60-
| `node-llama-cpp` version | x.y.zzz |
55+
| Dependency | Version |
56+
| --- | --- |
57+
| Operating System | |
58+
| CPU | Intel i9 / Apple M1 |
59+
| Node.js version | x.y.zzz |
60+
| Typescript version | x.y.zzz |
61+
| `node-llama-cpp` version | x.y.zzz |
6162
validations:
6263
required: true
6364
- type: textarea

.github/PULL_REQUEST_TEMPLATE.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,4 @@
2929
- [ ] This pull request links relevant issues as `Fixes #0000`
3030
- [ ] There are new or updated unit tests validating the change
3131
- [ ] Documentation has been updated to reflect this change
32-
- [ ] The new commits and pull request title follow conventions explained in [CONTRIBUTING.md](https://github.com/withcatai/node-llama-cpp/blob/master/CONTRIBUTING.md) (PRs that do not follow this convention will not be merged)
32+
- [ ] The new commits and pull request title follow conventions explained in [pull request guidelines](https://withcatai.github.io/node-llama-cpp/guide/contributing) (PRs that do not follow this convention will not be merged)

.github/workflows/build.yml

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,6 @@ jobs:
1717
run: npm ci
1818
- name: Build
1919
run: npm run build
20-
- name: Generate docs
21-
run: npm run generate-docs
2220
- name: Download latest llama.cpp release
2321
env:
2422
CI: true
@@ -33,11 +31,6 @@ jobs:
3331
with:
3432
name: "binariesGithubRelease"
3533
path: "llama/binariesGithubRelease.json"
36-
- name: Upload build artifact
37-
uses: actions/upload-artifact@v3
38-
with:
39-
name: "docs-site"
40-
path: "docs-site"
4134
- name: Upload llama.cpp artifact
4235
uses: actions/upload-artifact@v3
4336
with:
@@ -243,7 +236,6 @@ jobs:
243236
mkdir -p llamaBins
244237
mv artifacts/bins-*/* llamaBins/
245238
mv artifacts/build dist/
246-
mv artifacts/docs-site docs-site/
247239
248240
cp -r artifacts/llama.cpp/grammars llama/grammars
249241
@@ -268,6 +260,13 @@ jobs:
268260
if [ -f .semanticRelease.npmPackage.deployedVersion.txt ]; then
269261
echo "npm-url=https://www.npmjs.com/package/node-llama-cpp/v/$(cat .semanticRelease.npmPackage.deployedVersion.txt)" >> $GITHUB_OUTPUT
270262
fi
263+
- name: Generate docs
264+
if: steps.set-npm-url.outputs.npm-url != ''
265+
env:
266+
DOCS_URL_BASE: "/node-llama-cpp/"
267+
run: |
268+
export DOCS_PACKAGE_VERSION=$(cat .semanticRelease.npmPackage.deployedVersion.txt)
269+
npm run docs:build
271270
- name: Upload docs to GitHub Pages
272271
if: steps.set-npm-url.outputs.npm-url != ''
273272
uses: actions/upload-pages-artifact@v2

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,11 @@ node_modules
55

66
/dist
77
/docs-site
8+
/docs/api
89

910
/.env
1011
/.eslintcache
12+
/.vitepress/.cache
1113

1214
/llama/compile_commands.json
1315
/llama/llama.cpp

.vitepress/config.ts

Lines changed: 210 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,210 @@
1+
import {defineConfig, DefaultTheme} from "vitepress";
2+
import path from "path";
3+
import fs from "fs-extra";
4+
import {fileURLToPath} from "url";
5+
import typedocSidebar from "../docs/api/typedoc-sidebar.json"; // if this import fails, run `npm run docs:generateTypedoc`
6+
import envVar from "env-var";
7+
import process from "process";
8+
9+
const __dirname = path.dirname(fileURLToPath(import.meta.url));
10+
const packageJson: typeof import("../package.json") = fs.readJsonSync(path.join(__dirname, "..", "package.json"));
11+
const env = envVar.from(process.env);
12+
13+
const urlBase = env.get("DOCS_URL_BASE").asString();
14+
const packageVersion = env.get("DOCS_PACKAGE_VERSION").default(packageJson.version).asString();
15+
16+
const chatWrappersOrder = [
17+
"GeneralChatPromptWrapper",
18+
"LlamaChatPromptWrapper",
19+
"ChatMLChatPromptWrapper",
20+
"FalconChatPromptWrapper"
21+
] as const;
22+
23+
function resolveHref(href: string) {
24+
if (urlBase == null)
25+
return href;
26+
27+
if (urlBase.endsWith("/") && href.startsWith("/"))
28+
return urlBase.slice(0, -1) + href;
29+
30+
return urlBase + href;
31+
}
32+
33+
export default defineConfig({
34+
title: "node-llama-cpp",
35+
description: "Run AI models locally on your machine with node.js bindings for llama.cpp",
36+
37+
srcDir: "./docs",
38+
outDir: "./docs-site",
39+
cacheDir: "./.vitepress/.cache",
40+
41+
cleanUrls: true,
42+
lastUpdated: true,
43+
44+
base: urlBase,
45+
sitemap: {
46+
hostname: "https://withcatai.github.io/node-llama-cpp/"
47+
},
48+
head: [
49+
["link", {rel: "icon", type: "image/svg+xml", href: resolveHref("/favicon.svg")}],
50+
["link", {rel: "icon", type: "image/png", href: resolveHref("/favicon.png")}],
51+
["meta", {name: "theme-color", content: "#cd8156"}],
52+
["meta", {name: "theme-color", content: "#dd773e", media: "(prefers-color-scheme: dark)"}],
53+
["meta", {name: "og:type", content: "website"}],
54+
["meta", {name: "og:locale", content: "en"}],
55+
["meta", {name: "og:site_name", content: "node-llama-cpp"}]
56+
],
57+
transformPageData(pageData) {
58+
if (pageData.filePath.startsWith("api/") || pageData.filePath.startsWith("guide/cli/")) {
59+
pageData.frontmatter.editLink = false;
60+
pageData.frontmatter.lastUpdated = false;
61+
}
62+
},
63+
themeConfig: {
64+
editLink: {
65+
pattern: "https://github.com/withcatai/node-llama-cpp/edit/main/docs/:path"
66+
},
67+
nav: [
68+
{text: "Guide", link: "/guide/", activeMatch: "/guide/"},
69+
{text: "API Reference", link: "/api/classes/LlamaModel", activeMatch: "/api/"},
70+
{
71+
text: packageVersion,
72+
items: [{
73+
text: "Changelog",
74+
link: "https://github.com/withcatai/node-llama-cpp/releases"
75+
}, {
76+
text: "npm",
77+
link: "https://www.npmjs.com/package/node-llama-cpp"
78+
}, {
79+
text: "Contributing",
80+
link: "/guide/contributing"
81+
}]
82+
}
83+
],
84+
search: {
85+
provider: "local"
86+
},
87+
sidebar: {
88+
"/api/": orderApiReferenceSidebar(getApiReferenceSidebar()),
89+
90+
"/guide/": [{
91+
text: "Guide",
92+
base: "/guide",
93+
items: [
94+
{text: "Getting started", link: "/"},
95+
{text: "Chat session", link: "/chat-session"},
96+
{text: "Chat prompt wrapper", link: "/chat-prompt-wrapper"},
97+
{text: "Using grammar", link: "/grammar"}
98+
]
99+
}, {
100+
text: "Advanced",
101+
base: "/guide",
102+
items: [
103+
{text: "Building from source", link: "/building-from-source"},
104+
{text: "Metal support", link: "/Metal"},
105+
{text: "CUDA support", link: "/CUDA"}
106+
]
107+
}, {
108+
text: "Contributing",
109+
base: "/guide",
110+
items: [
111+
{text: "Setting up a dev environment", link: "/development"},
112+
{text: "Pull request guidelines", link: "/contributing"}
113+
]
114+
}, {
115+
text: "CLI",
116+
base: "/guide/cli",
117+
collapsed: true,
118+
link: "/",
119+
items: [
120+
{text: "Chat", link: "/chat"},
121+
{text: "Download", link: "/download"},
122+
{text: "Build", link: "/build"},
123+
{text: "Clear", link: "/clear"}
124+
]
125+
}]
126+
},
127+
socialLinks: [
128+
{icon: "github", link: "https://github.com/withcatai/node-llama-cpp"}
129+
]
130+
}
131+
});
132+
133+
function getApiReferenceSidebar(): typeof typedocSidebar {
134+
return structuredClone(typedocSidebar)
135+
.map((item) => {
136+
switch (item.text) {
137+
case "README":
138+
case "API":
139+
return null;
140+
case "Classes":
141+
case "Type Aliases":
142+
case "Functions":
143+
if (item.text === "Type Aliases")
144+
item.text = "Types";
145+
146+
if (item.collapsed)
147+
item.collapsed = false;
148+
149+
if (item.items instanceof Array)
150+
item.items = item.items.map((subItem) => {
151+
if (subItem.collapsed)
152+
// @ts-ignore
153+
delete subItem.collapsed;
154+
155+
return subItem;
156+
})
157+
return item;
158+
}
159+
160+
return item;
161+
})
162+
.filter((item) => item != null) as typeof typedocSidebar;
163+
}
164+
165+
function orderApiReferenceSidebar(sidebar: typeof typedocSidebar): typeof typedocSidebar {
166+
const baseChatPromptWrapper = "ChatPromptWrapper";
167+
const chatPromptWrapperItems: DefaultTheme.SidebarItem[] = [];
168+
169+
const classes = sidebar.find((item) => item.text === "Classes");
170+
171+
if (classes == null || !(classes.items instanceof Array))
172+
return sidebar;
173+
174+
(classes.items as DefaultTheme.SidebarItem[]).unshift({
175+
text: "Chat wrappers",
176+
collapsed: false,
177+
items: chatPromptWrapperItems
178+
});
179+
180+
const chatPromptWrapper = classes.items.find((item) => item.text === baseChatPromptWrapper);
181+
if (chatPromptWrapper != null) {
182+
classes.items.splice(classes.items.indexOf(chatPromptWrapper), 1);
183+
classes.items.unshift(chatPromptWrapper);
184+
}
185+
186+
for (const item of classes.items.slice()) {
187+
if (item.text === baseChatPromptWrapper || !item.text.endsWith(baseChatPromptWrapper))
188+
continue;
189+
190+
classes.items.splice(classes.items.indexOf(item), 1);
191+
chatPromptWrapperItems.push(item);
192+
}
193+
194+
chatPromptWrapperItems.sort((a, b) => {
195+
const aIndex = chatWrappersOrder.indexOf(a.text as typeof chatWrappersOrder[number]);
196+
const bIndex = chatWrappersOrder.indexOf(b.text as typeof chatWrappersOrder[number]);
197+
198+
if (aIndex < 0 && bIndex < 0)
199+
return 0;
200+
if (aIndex < 0)
201+
return 1;
202+
if (bIndex < 0)
203+
return -1;
204+
205+
return aIndex - bIndex;
206+
});
207+
208+
return sidebar;
209+
}
210+

.vitepress/theme/index.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {h} from "vue";
2+
import Theme from "vitepress/theme";
3+
import "./style.css";
4+
5+
export default {
6+
extends: Theme,
7+
Layout: () => {
8+
return h(Theme.Layout, null, {});
9+
},
10+
enhanceApp({app, router, siteData}) {}
11+
};

.vitepress/theme/style.css

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
:root {
2+
--vp-c-brand-1: #b26134;
3+
--vp-c-brand-2: #cc6e3a;
4+
--vp-c-brand-3: #cd8156;
5+
--vp-c-brand-soft: rgb(255 156 100 / 14%);
6+
}
7+
8+
.dark {
9+
--vp-c-brand-1: #ffc7a8;
10+
--vp-c-brand-2: #e78e5c;
11+
--vp-c-brand-3: #dd773e;
12+
--vp-c-brand-soft: rgb(255 156 100 / 16%);
13+
}
14+
15+
:root {
16+
--vp-home-hero-name-color: transparent;
17+
--vp-home-hero-name-background: -webkit-linear-gradient(
18+
108deg,
19+
#bd44c5 16%,
20+
#faad5e
21+
);
22+
23+
--vp-home-hero-image-background-image: linear-gradient(
24+
108deg,
25+
#faad5e 50%,
26+
#bd44c5 50%
27+
);
28+
--vp-home-hero-image-filter: blur(40px);
29+
}
30+
31+
@media (min-width: 640px) {
32+
:root {
33+
--vp-home-hero-image-filter: blur(56px);
34+
}
35+
}
36+
37+
@media (min-width: 960px) {
38+
:root {
39+
--vp-home-hero-image-filter: blur(72px) opacity(0.8);
40+
}
41+
}
42+
43+
.main-badges>p {
44+
display: flex;
45+
flex-direction: row;
46+
align-items: center;
47+
justify-content: center;
48+
gap: 4px;
49+
}
50+
51+
img[src$="assets/logo.roundEdges.png"],
52+
img[src$="assets/logo.png"] {
53+
box-shadow: 0px 4px 12px 0px rgb(0 0 0 / 16%), 0px 8px 64px 0px rgb(0 0 0 / 24%);
54+
border-radius: 14px;
55+
margin-bottom: 12px;
56+
}
57+
58+
div[align="center"] > img[alt="Star please"][src$="assets/star.please.roundEdges.png"] ~ p[align="right"],
59+
div[align="center"] > img[alt="Star please"][src$="assets/star.please.png"] ~ p[align="right"] {
60+
max-width: 360px;
61+
margin-top: -12px;
62+
}
63+
div[align="center"] > img[alt="Star please"][src$="assets/star.please.roundEdges.png"] ~ p[align="right"]>*,
64+
div[align="center"] > img[alt="Star please"][src$="assets/star.please.png"] ~ p[align="right"]>* {
65+
display: none;
66+
}
67+
div[align="center"] > img[alt="Star please"][src$="assets/star.please.roundEdges.png"] ~ p[align="right"]>:first-of-type,
68+
div[align="center"] > img[alt="Star please"][src$="assets/star.please.png"] ~ p[align="right"]>:first-of-type {
69+
display: block;
70+
}

0 commit comments

Comments
 (0)