Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion docsite/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,15 @@ class BrandConfig(_Frozen):


class Reference(_Frozen):
"""A generated API reference: one page per top-level module of `package`, with submodules."""
"""A generated API reference: one page per package and subpackage of `package`."""

# The import name, e.g. appinfra or llm_saia
package: str
# The checkout directory that holds the package directory
source: str = "."
# Subpackages left out of the reference with everything under them, as dotted paths relative
# to the package (examples, cli.tools). The packages ship their runnable examples as one.
exclude: tuple[str, ...] = ("examples",)


class Package(_Frozen):
Expand Down
23 changes: 21 additions & 2 deletions docsite/navtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,27 @@ class SectionIndex:


def package_nav(pkg: Package) -> list[NavItem]:
"""The package's docs tree with renames applied, paths relative to the package's directory."""
return map_paths(pkg.docs, pkg.site_path)
"""The package's docs tree with renames applied, paths relative to the package's directory.
Files staged under another name than .md, such as an image a page shows, are published but
are not pages, so they and sections left empty are not in it."""
return _pages_only(map_paths(pkg.docs, pkg.site_path))


def _pages_only(items: Sequence[NavItem]) -> list[NavItem]:
"""The tree without its non-.md paths and the sections that held only those."""
out: list[NavItem] = []
for item in items:
if isinstance(item, str):
if item.endswith(".md"):
out.append(item)
continue
((title, value),) = item.items()
if isinstance(value, str):
if value.endswith(".md"):
out.append(item)
elif kept := _pages_only(value):
out.append({title: kept})
return out


def map_paths(items: Sequence[NavItem], fn: Callable[[str], str]) -> list[NavItem]:
Expand Down
4 changes: 3 additions & 1 deletion docsite/reexports.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,9 @@ class Exports(Extension):
def on_package(self, *, pkg: Module, loader: GriffeLoader, **kwargs: Any) -> None:
"""Rewrite every package of the loaded package."""
for package in _packages(pkg):
rows = [_row(name, *place) for name, place in _take_exports(package)]
# Alphabetical, as mkdocstrings orders the members (zensical.base.toml)
taken = sorted(_take_exports(package), key=lambda item: item[0])
rows = [_row(name, *place) for name, place in taken]
if rows:
_append(package, _HEADER + "\n".join(rows), loader)

Expand Down
14 changes: 8 additions & 6 deletions docsite/reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,20 @@ def reference_modules(checkout: Path, ref: Reference) -> list[str]:
root = checkout / ref.source / ref.package
if not (root / "__init__.py").is_file() or root.is_symlink():
raise ReferenceSourceError(f"{root} is not a package directory")
return _walk(root, ref.package)
return _walk(root, ref.package, {f"{ref.package}.{name}" for name in ref.exclude})


def _walk(folder: Path, dotted: str) -> list[str]:
"""The public subpackages under `folder`, the package `dotted`, recursively."""
def _walk(folder: Path, dotted: str, exclude: set[str]) -> list[str]:
"""The public subpackages under `folder`, the package `dotted`, recursively; an excluded
one is skipped with everything under it."""
packages = []
for entry in sorted(folder.iterdir()):
if entry.name.startswith("_") or entry.is_symlink():
name = f"{dotted}.{entry.name}"
if entry.name.startswith("_") or entry.is_symlink() or name in exclude:
continue
if (entry / "__init__.py").is_file():
packages.append(f"{dotted}.{entry.name}")
packages += _walk(entry, f"{dotted}.{entry.name}")
packages.append(name)
packages += _walk(entry, name, exclude)
return packages


Expand Down
81 changes: 73 additions & 8 deletions etc/docsite.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,16 @@ brand:
# Packages by name. Each is fetched at its git `ref`: a release tag for the published site; for a
# preview, a branch or <branch>@<commit> (pushed), set in a gitignored Makefile.local as
# `serve: export INFRA_PACKAGES_<NAME>_REF := develop@9843ff` (NAME upper-cased, - as _).
# `docs_root` is its docs directory in the repo (default: docs). The package's docs are the source and are published as they are; the
# arrangement is the site's. `docs` is the package's tree in the site nav and its allowlist at
# once: only the files it lists are published, in that order. An entry is a path (titled by the
# page's heading), {Title: path}, or {Section: [entries]}. No wildcards: a new file must be
# listed to ship. `rename` stages a file under another name. `reference` adds an API reference
# generated from the package's docstrings. Each package also needs a landing page,
# pages/<name>/index.md, and an entry {<name>: <name>/index.md} under Packages in
# zensical.base.toml.
# `docs_root` is its docs directory in the repo (default: docs). The package's docs are the source
# and are published as they are; the arrangement is the site's. `docs` is the package's tree in
# the site nav and its allowlist at once: only the files it lists are published, in that order.
# An entry is a path (titled by the page's heading), {Title: path}, or {Section: [entries]}. A
# file that is not a page, such as an image a page shows, is published but stays out of the nav.
# No wildcards: a new file must be listed to ship. `rename` stages a file under another name.
# `reference` adds an API reference generated from the package's docstrings; its `exclude` lists
# subpackages to leave out, as dotted paths relative to the package (default: [examples]). Each
# package also needs a landing page, pages/<name>/index.md, and an entry
# {<name>: <name>/index.md} under Packages in zensical.base.toml.
packages:
appinfra:
repo: https://github.com/llm-works/appinfra.git
Expand Down Expand Up @@ -115,3 +117,66 @@ packages:
- Security policy: SECURITY.md
# The docs are published under appinfra's licence (Apache 2.0), which ships with them
- License: LICENSE

llm-infer:
repo: https://github.com/llm-works/llm-infer.git
ref: v0.9.0
reference:
package: llm_infer
docs:
- usage.md
- client.md
- config.md
- engines.md
- adapters.md
- architecture.md
- api.md
- known-issues.md

llm-saia:
repo: https://github.com/llm-works/llm-saia.git
ref: v0.6.3
reference:
package: llm_saia
docs:
- INTRO.md
# A section without a page of its own: the site generates guides/index.md, listing them
- Guides:
- pydantic.md
- custom-verbs.md
- backend.md
- tool-gates.md
- production.md
- demo/demo.gif

llm-kelt:
repo: https://github.com/llm-works/llm-kelt.git
ref: v0.5.1
# Zensical takes a README.md as the folder's index, which is the landing page here
rename:
README.md: overview.md
reference:
package: llm_kelt
docs:
- README.md
- quickstart.md
- concepts.md
- atomic-memory.md
- knowledge-graph.md
- context-and-rag.md
- conversation.md
- multi-schema.md
- training.md
- cli.md
- glossary.md

llm-gent:
repo: https://github.com/llm-works/llm-gent.git
ref: v0.4.1
# index.md is the landing page here (pages/llm-gent/index.md)
rename:
index.md: guide.md
reference:
package: llm_gent
docs:
- index.md
23 changes: 21 additions & 2 deletions pages/llm-gent/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,28 @@
---
hide:
- toc
---

# llm-gent

Composable agent framework: agents are built from traits that provide capabilities such as LLM
access, storage and learning, and run standalone or as services through the HTTP runtime.
{ .lw-lead }

<div class="grid cards" markdown>

- :lucide-book-open:{ .lw-card-icon }

**[Guide](guide.md)**

Agents, traits and their lifecycle, and flow composition.

- :lucide-braces:{ .lw-card-icon }

**[API reference](reference/index.md)**

Every public module, class and function, generated from the source at the release tag.

!!! info "Coming soon"
The llm-gent guides and API reference.
</div>

Source: [llm-works/llm-gent](https://github.com/llm-works/llm-gent)
36 changes: 34 additions & 2 deletions pages/llm-infer/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,42 @@
---
hide:
- toc
---

# llm-infer

One client for OpenAI, Anthropic, Google and any OpenAI-compatible server, with routing,
cross-provider fallback, retries and rate limiting; plus `llm-infer serve`, which puts local
models behind one OpenAI-compatible endpoint.
{ .lw-lead }

<div class="grid cards" markdown>

- :lucide-book-open:{ .lw-card-icon }

**[Usage guide](usage.md)**

Running `llm-infer serve`: setup, CLI commands, the OpenAI SDK against it, tuning and
debugging.

- :lucide-settings:{ .lw-card-icon }

**[Configuration](config.md)**

The server's configuration: backend selection, engine configs, API and request settings.

- :lucide-compass:{ .lw-card-icon }

**[Architecture](architecture.md)**

The server's layers and engine backends, a request's lifecycle, memory and batching.

- :lucide-braces:{ .lw-card-icon }

**[API reference](reference/index.md)**

Every public module, class and function, generated from the source at the release tag.

!!! info "Coming soon"
The llm-infer guides and API reference.
</div>

Source: [llm-works/llm-infer](https://github.com/llm-works/llm-infer)
35 changes: 33 additions & 2 deletions pages/llm-kelt/index.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,41 @@
---
hide:
- toc
---

# llm-kelt

Persistent memory and fine-tuning data for LLM applications, backed by Postgres: store facts,
feedback and preferences, retrieve them for prompts and RAG, and train LoRA and DPO adapters
from them.
{ .lw-lead }

<div class="grid cards" markdown>

- :lucide-book-open:{ .lw-card-icon }

**[Overview](overview.md)**

Every document and when to read it.

- :lucide-rocket:{ .lw-card-icon }

**[Quickstart](quickstart.md)**

Postgres, install and config, then record a first fact and inject it into a prompt.

- :lucide-compass:{ .lw-card-icon }

**[Concepts](concepts.md)**

Context keys, schemas, atomic memory versus the knowledge graph, and the clients.

- :lucide-braces:{ .lw-card-icon }

**[API reference](reference/index.md)**

Every public module, class and function, generated from the source at the release tag.

!!! info "Coming soon"
The llm-kelt guides and API reference.
</div>

Source: [llm-works/llm-kelt](https://github.com/llm-works/llm-kelt)
29 changes: 27 additions & 2 deletions pages/llm-saia/index.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,34 @@
---
hide:
- toc
---

# llm-saia

Structured verbs for LLM interactions: verify, critique, decompose, extract, synthesize and more,
each returning a typed result instead of free text.
{ .lw-lead }

<div class="grid cards" markdown>

- :lucide-book-open:{ .lw-card-icon }

**[Introduction](INTRO.md)**

Typed contracts for LLM outputs: what the verbs are and how they are used.

- :lucide-compass:{ .lw-card-icon }

**[Guides](guides/index.md)**

Pydantic schemas, custom verbs, backends, tool gates and production use.

- :lucide-braces:{ .lw-card-icon }

**[API reference](reference/index.md)**

Every public module, class and function, generated from the source at the release tag.

!!! info "Coming soon"
The llm-saia guides and API reference.
</div>

Source: [llm-works/llm-saia](https://github.com/llm-works/llm-saia)
14 changes: 4 additions & 10 deletions tests/integration/test_cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,10 @@ def test_build_runs_every_step(
# The staged directory, relative to zensical.toml
assert config["project"]["docs_dir"] == "docs"
entry = config["project"]["nav"][1]["Packages"][1]["pkg"]
assert entry[:3] == [
"pkg/index.md",
{"Introduction": "pkg/intro.md"},
{"Demo": ["pkg/demo/index.md", "pkg/demo/demo.gif"]},
]
assert entry[3]["API reference"][0] == "pkg/reference/index.md"
# The Demo section has no page of its own: one is generated, listing its entries
assert (docs / "pkg" / "demo" / "index.md").read_text(encoding="utf-8") == (
"# Demo\n\n- [Demo](demo.gif)\n"
)
# The Demo section holds only an image: published above, but no pages, so not in the nav
assert entry[:2] == ["pkg/index.md", {"Introduction": "pkg/intro.md"}]
assert entry[2]["API reference"][0] == "pkg/reference/index.md"
assert not (docs / "pkg" / "demo" / "index.md").exists()
python = config["project"]["plugins"]["mkdocstrings"]["handlers"]["python"]
assert python["paths"] == [(tmp_path / "build" / "pkg").as_posix()]

Expand Down
18 changes: 18 additions & 0 deletions tests/integration/test_reference_modules.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,24 @@ def test_public_subpackages_at_every_depth(tmp_path: Path) -> None:
assert reference_modules(tmp_path, ref) == ["mypkg.sub", "mypkg.sub.deep"]


def test_excluded_subpackages_are_left_out_with_their_subpackages(tmp_path: Path) -> None:
"""examples is excluded by default; a nested entry (sub.deep) leaves out only that part."""
pkg = _package(tmp_path)
for rel in ("examples/__init__.py", "examples/demo/__init__.py"):
(pkg / rel).parent.mkdir(parents=True, exist_ok=True)
(pkg / rel).write_text("", encoding="utf-8")
assert reference_modules(tmp_path, Reference(package="mypkg", source="src")) == [
"mypkg.sub",
"mypkg.sub.deep",
]
ref = Reference(package="mypkg", source="src", exclude=("sub.deep",))
assert reference_modules(tmp_path, ref) == [
"mypkg.examples",
"mypkg.examples.demo",
"mypkg.sub",
]


def test_missing_package_fails(tmp_path: Path) -> None:
"""The reference config must point at a package directory."""
with pytest.raises(ReferenceSourceError, match="not a package"):
Expand Down
9 changes: 9 additions & 0 deletions tests/unit/test_navtree.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,15 @@ def test_package_nav_applies_renames_at_any_depth() -> None:
assert package_nav(pkg) == [{"Guide": "guide.md"}, {"Sub": ["sub/overview.md", "sub/x.md"]}]


def test_package_nav_leaves_out_files_that_are_not_pages() -> None:
"""An image a page shows is published with the docs but has no place in the nav; a
plain-text file staged as .md (LICENSE as license.md) is a page and keeps its place."""
docs = ["intro.md", "demo/demo.gif", {"Media": ["img/a.png"]}, {"License": "LICENSE"}]
packages = {"pkg": package_dict(docs=docs, rename={"LICENSE": "license.md"})}
pkg = load_build_config(build_dict(packages=packages)).packages[0]
assert package_nav(pkg) == ["intro.md", {"License": "license.md"}]


def test_index_sections_adds_a_page_to_sections_without_one() -> None:
"""A section gets a generated page first, at its titles slugged; nested sections too."""
tree = ["intro.md", {"Guides": [{"Dev tooling": ["g/a.md"]}, {"B": "g/b.md"}]}]
Expand Down
Loading