Skip to content

Commit

Permalink
Fix toctrees and reference pages
Browse files Browse the repository at this point in the history
  • Loading branch information
philippjfr committed Jan 2, 2025
1 parent 647209f commit 5a43d87
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 16 deletions.
51 changes: 38 additions & 13 deletions doc/generate_reference.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
import lumen.sources.intake
import lumen.sources.intake_sql

from lumen.ai.actor import Actor
from lumen.ai.agents import Agent
from lumen.base import MultiTypeComponent
from lumen.dashboard import Auth, Config, Defaults
from lumen.filters import Filter
Expand All @@ -28,7 +30,7 @@
from lumen.variables import Variable
from lumen.views import View

bases = [Config, Variable, Pipeline, Source, Filter, Transform, View, Layout, Auth, Defaults]
bases = [Agent, Config, Variable, Pipeline, Source, Filter, Transform, View, Layout, Auth, Defaults]

BASE_PATH = pathlib.Path(lumen.__file__).parent.parent
REFERENCE_PATH = BASE_PATH / 'doc' / 'reference'
Expand Down Expand Up @@ -128,7 +130,7 @@ def generate_param_docs(base, component, gutter=3, margin=0):
pobj = component.param[pname]
ptype = type(pobj)
pbadge = f'<span style="font-size: 1.25em;">{{bdg-dark}}`{pname}`'
if pname in component._required_keys:
if pname in getattr(component, '_required_keys', []):
pbadge += '&emsp;&emsp;&emsp;{bdg-warning}`required`'
pbadge += '</span>'
pitems = []
Expand Down Expand Up @@ -189,7 +191,7 @@ def generate_automethods(component):

def generate_page(base, component):
title = f'# {component.__name__}'
if base is not component:
if base is not component and issubclass(component, MultiTypeComponent):
ctype = getattr(component, f'{base.__name__.lower()}_type')
title += f'&nbsp;&nbsp;{{bdg-primary}}`type: {ctype}`'
title += '\n'
Expand Down Expand Up @@ -230,9 +232,9 @@ def generate_grid(base, gridspec='2 2 3 3', gutter=3, margin=0, rel=''):
description = component.__doc__.split('\n')[1].strip()
else:
description = f'{name} {base.__name__}'
ctype = getattr(component, f'{base.__name__.lower()}_type')
badge = f' {{bdg-primary}}`type: {ctype}`'
page += f':::{{grid-item-card}} {name} {badge}\n:link: {rel}{name}.html\n:shadow: md\n\n{description}\n:::\n\n'
ctype = getattr(component, f'{base.__name__.lower()}_type', None)
badge = f' {{bdg-primary}}`type: {ctype}`' if ctype else ''
page += f':::{{grid-item-card}} {name}{badge}\n:link: {rel}{name}.html\n:shadow: md\n\n{description}\n:::\n\n'
page += '::::'
return page

Expand All @@ -245,16 +247,28 @@ def generate_multi_component_pages(base):
index = generate_component_index(base)
component_path = REFERENCE_PATH / base.__name__.lower()
component_path.mkdir(exist_ok=True, parents=True)
with open(component_path / 'index.md', 'w') as f:
f.write(index)
toc = ''
for component in concrete_descendents(base).values():
if component.__name__.startswith('_'):
continue
page = generate_page(base, component)
path = REFERENCE_PATH / base.__name__.lower() / f'{component.__name__}.md'
name = component.__name__
path = REFERENCE_PATH / base.__name__.lower() / f'{name}.md'
print(f'Writing {path}.')
with open(path, 'w') as f:
f.write(page)
toc += f'{name}\n'
index += f"""
```{{toctree}}
---
hidden: true
---
{toc[:-1]}
```
"""
with open(component_path / 'index.md', 'w') as f:
f.write(index)
return page

def generate_single_component_page(component):
Expand All @@ -265,29 +279,40 @@ def generate_single_component_page(component):

def write_index(bases):
page = '# Reference\n\n'
toc = ''
for base in bases:
name = base.__name__
if base.__doc__:
description = base.__doc__.split("\n")[1].strip()
else:
description = None
if issubclass(base, MultiTypeComponent):
page += f'## [`{base.__name__}`]({base.__name__.lower()}/index)\n\n'
if issubclass(base, (Actor, MultiTypeComponent)):
page += f'## [`{name}`]({name.lower()}/index)\n\n'
if description:
page += f'{description}\n\n'
page += generate_grid(base, rel=f'{base.__name__.lower()}/')
page += '\n\n'
else:
page += f'## [`{base.__name__}`]({base.__name__})\n\n'
page += f'## [`{name}`]({name})\n\n'
if description:
page += f'{description}\n\n'
toc += f'{name} <{name.lower()}/index>\n'
page += f"""
```{{toctree}}
---
hidden: true
---
{toc[:-1]}
```
"""
path = REFERENCE_PATH / 'index.md'
with open(path, 'w') as f:
f.write(page)

if __name__ == '__main__':
REFERENCE_PATH.mkdir(exist_ok=True, parents=True)
for component in bases:
if issubclass(component, MultiTypeComponent):
if issubclass(component, (Actor, MultiTypeComponent)):
generate_multi_component_pages(component)
else:
generate_single_component_page(component)
Expand Down
17 changes: 16 additions & 1 deletion doc/getting_started/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,13 @@ This _Getting Started_ guide will go through the installation of Lumen, how to b
Install Lumen in a few easy steps
:::

::::

## AI

::::{grid} 1 2 2 3
:gutter: 1 1 1 2

:::{grid-item-card} {octicon}`zap;2em;sd-mr-1` Using Lumen AI
:link: using_lumen_ai
:link-type: doc
Expand All @@ -26,6 +33,13 @@ How to explore your data with Lumen AI
Configure Lumen AI to use custom Coordinators, Agents, and LLM providers
:::

::::

## Core

::::{grid} 1 2 2 3
:gutter: 1 1 1 2

:::{grid-item-card} {octicon}`tools;2em;sd-mr-1` Build a dashboard
:link: build_dashboard
:link-type: doc
Expand Down Expand Up @@ -54,7 +68,8 @@ Get an overview of the core concepts of Lumen
hidden: true
---
installation
lumen_ai
using_lumen_ai
configuring_lumen_ai
build_dashboard
core_concepts
pipelines
Expand Down
2 changes: 1 addition & 1 deletion doc/how_to/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ Learn to create and use template prompts for influencing the AI's responses.
:::

::::
2

## Data Intake

::::{grid} 1 2 2 3
Expand Down
2 changes: 1 addition & 1 deletion doc/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Install Lumen in a few easy steps
:::

:::{grid-item-card} {octicon}`zap;2em;sd-mr-1` Exploration with Lumen AI
:link: getting_started/lumen_ai
:link: getting_started/using_lumen_ai
:link-type: doc

How to explore your data with Lumen AI.
Expand Down

0 comments on commit 5a43d87

Please sign in to comment.