Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DRAFT] trulens-legacy and trulens-api #1307

Draft
wants to merge 219 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 215 commits
Commits
Show all changes
219 commits
Select commit Hold shift + click to select a range
19fac9a
decouple core trulens packages
sfc-gh-chu Jul 19, 2024
9e24508
add root poetry files
sfc-gh-chu Jul 19, 2024
329a1c1
merge utils with core
sfc-gh-chu Jul 19, 2024
24caa3c
move feedback to feedback functions
sfc-gh-chu Jul 22, 2024
f457edd
feedback -> feedbacks
sfc-gh-chu Jul 22, 2024
3a06199
include compiled react components
sfc-gh-chu Jul 22, 2024
75e0c25
fmt
sfc-gh-chu Jul 22, 2024
cf45eae
fmt
sfc-gh-chu Jul 22, 2024
3058e45
Merge branch 'main' into corey/package
sfc-gh-chu Jul 23, 2024
0e08974
feedbacks -> external for clarity
sfc-gh-chu Jul 23, 2024
5fb16aa
fix dashboard dependencies
sfc-gh-chu Jul 23, 2024
5f32dc8
fix test imports
sfc-gh-chu Jul 23, 2024
ce834e7
update dev installs for llamaindex, langchain
sfc-gh-chu Jul 23, 2024
d6a1d84
core cleanup
sfc-gh-chu Jul 23, 2024
06e2b85
fix import
sfc-gh-chu Jul 23, 2024
506ccf5
move core to trulens.core and resolve import errors
sfc-gh-chu Jul 23, 2024
417ce96
fix import errors from trulens.core
sfc-gh-chu Jul 23, 2024
4fdbc36
fix imports in examples
sfc-gh-chu Jul 24, 2024
b7f4bef
fix imports in markdown
sfc-gh-chu Jul 24, 2024
525b0ee
fix docstring imports
sfc-gh-chu Jul 24, 2024
6bc0634
add test case generation as subpackage
sfc-gh-chu Jul 24, 2024
d7aab91
add root imports and detach TruRails
sfc-gh-chu Jul 24, 2024
17eee7c
add root imports and langchain dep
sfc-gh-chu Jul 24, 2024
eb7df93
add get_feedback_result and fix docstrings
sfc-gh-chu Jul 24, 2024
fc591f8
add nemo/trurails subpackage
sfc-gh-chu Jul 24, 2024
b6159e6
factor out get_feedback_result
sfc-gh-chu Jul 24, 2024
29aff34
fmt
sfc-gh-chu Jul 24, 2024
52d51e9
update test imports
sfc-gh-chu Jul 24, 2024
62338a9
fmt and rebuild
sfc-gh-chu Jul 24, 2024
fdea9fd
Merge branch 'main' into corey/package
sfc-gh-chu Jul 24, 2024
afc1286
fmt
sfc-gh-chu Jul 24, 2024
9548ed0
rename to trulens-testing
sfc-gh-chu Jul 24, 2024
7cb4b91
add trulens-testing
sfc-gh-chu Jul 24, 2024
c8e4165
remove trulens explain
sfc-gh-chu Jul 24, 2024
f2b2d87
move trulens_eval to root dir
sfc-gh-chu Jul 24, 2024
ab5feae
factor out rag_triad to external
sfc-gh-chu Jul 24, 2024
fc2eb3b
add testing poetry lock
sfc-gh-chu Jul 24, 2024
2d9049f
root packaging
sfc-gh-chu Jul 24, 2024
a05634f
move app types to trulens.core.apps to fix circular import
sfc-gh-chu Jul 24, 2024
47313ca
fix import paths
sfc-gh-chu Jul 24, 2024
1d3c39b
refactor core.app.app to core.app.base
sfc-gh-chu Jul 24, 2024
3625a8c
add __version__
sfc-gh-chu Jul 24, 2024
ffc4873
update formatting
sfc-gh-chu Jul 24, 2024
cd5aadf
fmt w ruff
sfc-gh-chu Jul 24, 2024
18d1e40
lint
sfc-gh-chu Jul 25, 2024
57651df
simple lint fixes
sfc-gh-chu Jul 25, 2024
3b6f583
move instrumentation framework extensions to ext.instrument
sfc-gh-chu Jul 25, 2024
cdee55a
isort rules update matching existing config
sfc-gh-chu Jul 25, 2024
cd3bce1
Merge branch 'corey/lint' into corey/package
sfc-gh-chu Jul 25, 2024
068aa09
split out providers and move instrument packages
sfc-gh-chu Jul 25, 2024
538e066
fix imports and symlinks
sfc-gh-chu Jul 25, 2024
2589095
linting and symlink fixes
sfc-gh-chu Jul 25, 2024
a61ef8b
import fixes and optional dependencies
sfc-gh-chu Jul 25, 2024
2afab84
Merge branch 'main' into corey/package
sfc-gh-chu Jul 25, 2024
5b5ff76
readme/docs updates
sfc-gh-chu Jul 25, 2024
8004e5e
rm old dev deps
sfc-gh-chu Jul 25, 2024
8cabb5f
update imports
sfc-gh-chu Jul 25, 2024
0bfc7d5
update az pipelines
sfc-gh-chu Jul 25, 2024
70c1385
use system python
sfc-gh-chu Jul 25, 2024
80a3547
disable venv
sfc-gh-chu Jul 25, 2024
4a9650f
move testing out of main package
sfc-gh-chu Jul 25, 2024
4845b1e
use system python
sfc-gh-chu Jul 25, 2024
fa8a455
fix config path
sfc-gh-chu Jul 25, 2024
407a4f4
install testing utilities
sfc-gh-chu Jul 25, 2024
deb427c
fmt
sfc-gh-chu Jul 25, 2024
0b64b3b
remove old makefile
sfc-gh-chu Jul 25, 2024
881e970
fix imports and pydantic serialization
sfc-gh-chu Jul 26, 2024
179de88
move out component views to ext
sfc-gh-chu Jul 26, 2024
b2b7ead
slowly deprecate unused optional imports
sfc-gh-chu Jul 26, 2024
bb7871c
add httpx
sfc-gh-chu Jul 26, 2024
4f0ca53
add httpx as optional
sfc-gh-chu Jul 26, 2024
3b193f9
mark group as optional
sfc-gh-chu Jul 26, 2024
871f44a
Docs for TruLens as namespace package (#1306)
sfc-gh-jreini Jul 26, 2024
1292094
remove langchain dependency from feedback prompts
sfc-gh-chu Jul 26, 2024
5cd2cc3
fix broken symlinks and types
sfc-gh-chu Jul 26, 2024
bba99c9
factor out utils
sfc-gh-chu Jul 26, 2024
cef6c01
restore serial
sfc-gh-chu Jul 26, 2024
66f816c
move testing to benchmark
sfc-gh-chu Jul 26, 2024
697a507
bundle utils into core
sfc-gh-chu Jul 26, 2024
bded315
mvoe trulens.testing to trulens.benchmark
sfc-gh-chu Jul 26, 2024
51698db
rollout trulens.ext namespace to trulens.instrument and trulens.provi…
sfc-gh-chu Jul 26, 2024
90496c7
fix symlinks
sfc-gh-chu Jul 26, 2024
62e9126
fmt
sfc-gh-chu Jul 26, 2024
0eed60b
fix select imports
sfc-gh-chu Jul 26, 2024
f7a370d
update makefile, testing, and mypy
sfc-gh-chu Jul 26, 2024
24936d8
update pipeline pytest commands
sfc-gh-chu Jul 26, 2024
6cfb369
first
sfc-gh-pmardziel Jul 26, 2024
8aa8c4b
Merge remote-tracking branch 'origin/corey/package' into piotrm/legac…
sfc-gh-pmardziel Jul 26, 2024
80bc38d
remove ext
sfc-gh-pmardziel Jul 26, 2024
cdc3c4b
fix dep message
sfc-gh-pmardziel Jul 26, 2024
223b579
add lock creation
sfc-gh-chu Jul 27, 2024
e6db7a2
testing fixes
sfc-gh-chu Jul 27, 2024
601b32b
add __init__
sfc-gh-chu Jul 27, 2024
66cfa02
add ipywidgets and traitlets to deps
sfc-gh-chu Jul 27, 2024
417fb03
dashboard fmt
sfc-gh-chu Jul 27, 2024
b201e68
remove pinecone from unittests
sfc-gh-chu Jul 27, 2024
036d5fc
misc fixes
sfc-gh-chu Jul 27, 2024
5e3a518
update pipeline and testing to use makefile
sfc-gh-chu Jul 27, 2024
4e3c32e
add coverage tools
sfc-gh-chu Jul 27, 2024
880e33a
add poetry install
sfc-gh-chu Jul 27, 2024
2cbc69e
only install tests group
sfc-gh-chu Jul 27, 2024
1f09099
set langchain version
sfc-gh-chu Jul 27, 2024
711b11e
update langchain dep
sfc-gh-chu Jul 27, 2024
ed534ee
allow ipywidgets in static tests
sfc-gh-chu Jul 27, 2024
bb022eb
disable nemoguardrails for python3.12
sfc-gh-chu Jul 27, 2024
c51aa47
mod name as unnested
sfc-gh-chu Jul 27, 2024
8b73aeb
skip nemo on 3.12
sfc-gh-chu Jul 28, 2024
beb244a
skip if >
sfc-gh-chu Jul 28, 2024
c15bd26
use makefile for release pipeline
sfc-gh-chu Jul 28, 2024
c57b194
linting fixes
sfc-gh-chu Jul 29, 2024
dc17e93
enable linting hook
sfc-gh-chu Jul 29, 2024
363a98d
Merge branch 'main' into corey/package
sfc-gh-chu Jul 29, 2024
5a7629e
pyproject formatter
sfc-gh-chu Jul 29, 2024
ba07f35
update lock
sfc-gh-chu Jul 29, 2024
114f568
add release process makefile targets
sfc-gh-chu Jul 29, 2024
51e86bd
misc changes to vsc environment
sfc-gh-chu Jul 29, 2024
a306d90
making more aliases
sfc-gh-pmardziel Jul 30, 2024
c07621c
finishing up __init__ aliases.
sfc-gh-pmardziel Jul 30, 2024
365270e
Add test for deprecation aliases
sfc-gh-pmardziel Jul 30, 2024
1dabfa3
use import paths for docs
sfc-gh-chu Jul 30, 2024
51dc4f0
replace docs references to trulens_eval
sfc-gh-chu Jul 30, 2024
a3eb81f
add test-output.xml to git ignores
sfc-gh-pmardziel Jul 30, 2024
82b863b
Merge remote-tracking branch 'origin/corey/package' into piotrm/legac…
sfc-gh-pmardziel Jul 30, 2024
2fac7ee
trying api package
sfc-gh-pmardziel Jul 31, 2024
b600f18
simplify docs paths where possible
sfc-gh-chu Jul 31, 2024
c978acb
add py.typed to subpackages to indicate inline typing
sfc-gh-chu Jul 31, 2024
102dfeb
restore releases
sfc-gh-chu Jul 31, 2024
3fd56c4
add examples and autogen api reference on docs
sfc-gh-chu Jul 31, 2024
c9ec282
update notebook pip installs
sfc-gh-chu Jul 31, 2024
9f746f0
update dashboard build and fragment decorator
sfc-gh-chu Jul 31, 2024
25a3cfa
combine huggingface with huggingfacelocal
sfc-gh-chu Aug 1, 2024
e670b11
add __version__ to all packages
sfc-gh-chu Aug 1, 2024
1d0de82
providers package name should match namespace
sfc-gh-chu Aug 1, 2024
ee7f9cf
fix guardrails imports
sfc-gh-chu Aug 1, 2024
de62a00
relax on minor version instead of patch
sfc-gh-chu Aug 1, 2024
65d1d65
Merge remote-tracking branch 'origin/corey/package' into piotrm/legac…
sfc-gh-pmardziel Aug 1, 2024
a988067
adding lazy loading trulens.* names
sfc-gh-pmardziel Aug 1, 2024
c3cf39b
misc
sfc-gh-pmardziel Aug 1, 2024
2895436
fix OMP error and add package metadata
sfc-gh-chu Aug 1, 2024
68f9999
Merge remote-tracking branch 'origin' into corey/package
sfc-gh-chu Aug 1, 2024
2a3116b
bump all subpackages to 1.0.0
sfc-gh-chu Aug 1, 2024
905bdf7
merge and notebook fixes
sfc-gh-chu Aug 1, 2024
b12a2f8
work
sfc-gh-pmardziel Aug 2, 2024
5bb7929
add snowflake test dependencies
sfc-gh-chu Aug 2, 2024
7073469
Merge branch 'main' into corey/package
sfc-gh-chu Aug 2, 2024
fcd0684
fmt
sfc-gh-chu Aug 2, 2024
5a1acaa
move optional test dependencies to new group
sfc-gh-chu Aug 2, 2024
64c5013
add snowflake as trulens-core extra
sfc-gh-chu Aug 2, 2024
00fbaf1
make BaseEmbedding optional
sfc-gh-chu Aug 2, 2024
9ecb51c
fix importlib failures on py3.9
sfc-gh-chu Aug 2, 2024
9ca5421
fix importlib handling under 3.10
sfc-gh-chu Aug 2, 2024
93a2e1f
resolve langchain(core/community/openai) versions
sfc-gh-chu Aug 2, 2024
f0c08c1
fix docs reading notebook build and examples
sfc-gh-chu Aug 2, 2024
17a7493
report pip and python version in pipeline
sfc-gh-chu Aug 2, 2024
8be6b7c
fix pip version
sfc-gh-chu Aug 2, 2024
f431c68
add make command to publish to pypi and testpypi
sfc-gh-chu Aug 2, 2024
026d50a
truera -> snowflake references
sfc-gh-chu Aug 2, 2024
eadfb44
set version 1.0.1a0 and allow prerelease deps
sfc-gh-chu Aug 2, 2024
1ae7623
move psutils
sfc-gh-chu Aug 2, 2024
5ad1414
update lockfiles
sfc-gh-chu Aug 2, 2024
1e5ba8d
ignore build venvs and mypy
sfc-gh-chu Aug 2, 2024
a0b5adc
add migration guide
sfc-gh-chu Aug 3, 2024
244ef65
update dev guide and add toml extension
sfc-gh-chu Aug 5, 2024
50379c8
fix old code in litellm example
sfc-gh-jreini Aug 5, 2024
ac94a1d
remove requirements from packaging
sfc-gh-chu Aug 5, 2024
de4ae26
remove remaning trulens_eval references
sfc-gh-chu Aug 5, 2024
ee1b68e
dogfood dev and build fixes
sfc-gh-chu Aug 5, 2024
9c9fb5b
update notebooks using optional provider
sfc-gh-chu Aug 5, 2024
10abc61
docs fixes
sfc-gh-chu Aug 5, 2024
add1531
fix links
sfc-gh-chu Aug 5, 2024
7575720
add meta.yaml
sfc-gh-chu Aug 5, 2024
b727370
add page on uninstalling
sfc-gh-chu Aug 5, 2024
95cedc3
update locks
sfc-gh-chu Aug 5, 2024
965bf94
remove App.select_context()
sfc-gh-chu Aug 6, 2024
f91f6d9
remove select_context impl
sfc-gh-chu Aug 6, 2024
932afaa
typos
sfc-gh-chu Aug 6, 2024
a328e91
add note about python version
sfc-gh-chu Aug 6, 2024
138deb2
Update README.md
sfc-gh-jreini Aug 6, 2024
3a539a9
make build path relative from recipe
sfc-gh-chu Aug 6, 2024
ff9248d
pr fixes
sfc-gh-chu Aug 6, 2024
3200627
fmt
sfc-gh-chu Aug 6, 2024
1b5262f
fix confirm
sfc-gh-chu Aug 6, 2024
8c53f8a
clarify sync flag
sfc-gh-chu Aug 6, 2024
defad15
add build section
sfc-gh-chu Aug 6, 2024
284bcb1
templatize ci pipelines
sfc-gh-chu Aug 7, 2024
17acd74
try camelCase
sfc-gh-chu Aug 7, 2024
8b145fa
split off optional test template
sfc-gh-chu Aug 7, 2024
08e777c
remove old reference
sfc-gh-chu Aug 7, 2024
f43ac51
Merge branch 'main' into corey/package
sfc-gh-chu Aug 7, 2024
07f23b6
Merge remote-tracking branch 'origin/corey/package' into piotrm/legac…
sfc-gh-pmardziel Aug 7, 2024
36df589
run precommit check on 3.11
sfc-gh-chu Aug 7, 2024
28b4e89
undo unnecessary quote typing
sfc-gh-chu Aug 7, 2024
befbf04
Merge branch 'main' into corey/package
sfc-gh-chu Aug 7, 2024
ff45768
work
sfc-gh-pmardziel Aug 8, 2024
79e08d3
rename gen docs
sfc-gh-pmardziel Aug 8, 2024
2c5dda6
Merge remote-tracking branch 'origin/corey/package' into piotrm/legac…
sfc-gh-pmardziel Aug 8, 2024
587c202
adjust API readme
sfc-gh-pmardziel Aug 8, 2024
e1447aa
add legacy to gen docs
sfc-gh-pmardziel Aug 8, 2024
23679c4
auto install
sfc-gh-pmardziel Aug 8, 2024
5a3b4ec
interactive API work
sfc-gh-pmardziel Aug 9, 2024
1505450
more interactive api work
sfc-gh-pmardziel Aug 9, 2024
db7762e
working on api docs
sfc-gh-pmardziel Aug 13, 2024
e044aa3
fixing namespace issues
sfc-gh-pmardziel Aug 14, 2024
cf45889
docs fixes
sfc-gh-pmardziel Aug 14, 2024
f45d8ac
Merge remote-tracking branch 'origin/main' into piotrm/legacy_namespace
sfc-gh-pmardziel Aug 14, 2024
780868d
fixing docs
sfc-gh-pmardziel Aug 15, 2024
cf490ee
more cleanup
sfc-gh-pmardziel Aug 15, 2024
651702f
re-testing deprecation
sfc-gh-pmardziel Aug 15, 2024
190cbd7
fix dynamic aliases
sfc-gh-pmardziel Aug 15, 2024
7ae626f
expanding on api design docs
sfc-gh-pmardziel Aug 15, 2024
d48122d
undo heading levels
sfc-gh-pmardziel Aug 15, 2024
547809e
nit and typo
sfc-gh-pmardziel Aug 15, 2024
6067a16
nit to api distinction
sfc-gh-pmardziel Aug 15, 2024
cd40222
Merge remote-tracking branch 'origin/main' into piotrm/legacy_namespace
sfc-gh-pmardziel Aug 15, 2024
2d57e89
docs updates
sfc-gh-pmardziel Aug 15, 2024
5873437
addressing pr comments
sfc-gh-pmardziel Aug 15, 2024
cc0d99d
reverting optional imports machinery that was removed in namespace pa…
sfc-gh-pmardziel Aug 15, 2024
0ff40d3
lock
sfc-gh-pmardziel Aug 15, 2024
3d5fee8
comments
sfc-gh-pmardziel Aug 15, 2024
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ share/python-wheels/
.pypirc
MANIFEST
*.whl
node_modules

# Notebook tests generate these files:
imagenet_class_index.json
Expand Down
2 changes: 1 addition & 1 deletion DEPRECATION.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Deprecation Notes
# Changes prior to the implementation of the deprecation policy

## Changes in 0.19.0

Expand Down
16 changes: 14 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,15 @@ test-%-optional: env-optional
test-unit:
poetry run pytest --rootdir=. tests/unit/*

# Run the static unit tests only, those in the static subfolder. They are run
# for every tested python version while those outside of static are run only for
# the latest (supported) python version.
test-static:
sfc-gh-pmardziel marked this conversation as resolved.
Show resolved Hide resolved
poetry run pytest --rootdir=. tests/unit/static/test_static.py

test-deprecation:
TEST_OPTIONAL=1 poetry run pytest --rootdir=. tests/unit/static/test_deprecation.py

# Tests in the e2e folder make use of possibly costly endpoints. They
# are part of only the less frequently run release tests.
test-e2e:
Expand All @@ -132,6 +141,9 @@ test-e2e:
test-notebook:
poetry run pytest --rootdir=. tests/docs_notebooks/*

install-wheels:
pip install dist/*/*.whl

# Release Steps:
## Step: Clean repo:
clean-dashboard:
Expand All @@ -141,8 +153,8 @@ clean: clean-dashboard
git clean --dry-run -fxd
@read -p "Do you wish to remove these files? (y/N)" -n 1 -r
echo
if [[ $$REPLY =~ ^[Yy]$$ ]]; then
git clean -fxd;
if [[ $$REPLY =~ ^[Yy]$$ ]]; then \
sfc-gh-pmardziel marked this conversation as resolved.
Show resolved Hide resolved
git clean -fxd; \
fi;

## Step: Build wheels
Expand Down
49 changes: 49 additions & 0 deletions POLICIES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Release policies

## Versioning

Releases are organized in `<major>.<minor>.<patch>` style. A release is made
about every week around tuesday-thursday. Releases increment the `minor` version
number. Occasionally bug-fix releases occur after a weekly release. Those
increment only the `patch` number. No releases have yet made a `major` version
increment. Those are expected to be major releases that introduce large number
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

a large number

of breaking changes.

## Deprecation

Changes to the public API are governed by a deprecation process in three stages.
In the warning period of no less than _3 months_, the use of a deprecated
package, module, or value will produce a warning but otherwise operate as
expected. In the subsequent deprecated period of no less than _3 months_, the
use of that component will produce an error after the deprecation message. After
these two periods, the deprecated capability will be completely removed.

!!! Info "Deprecation process"

- 3 months - warning

- 3 months - warning + error

- removal

Changes that result in non-backwards compatible functionality are also reflected
in the version numbering. In such cases, the appropriate level version change
will occur at the introduction of the warning period.

## Currently derpecating features
sfc-gh-pmardziel marked this conversation as resolved.
Show resolved Hide resolved

- Starting 1.0.0, the `trulens_eval` package is being deprecated in favor of
`trulens` and several associated required and optional packages. See
[trulens_eval migration](/trulens/guides/trulens_eval_migration) for details.

- Warning period: 2024-09-01 with `trulens-eval` 1.0.0a0 -- 2024-12-01.
Backwards compatibility during the warning period is provided by the new
content of the `trulens_eval` package which provides aliases to the
features in their new locations. See
[trulens_eval](trulens/api/trulens_eval/index.md).

- Deprecated period: 2024-09-01 -- 2025-02-01 . Usage of `trulens_eval` will
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

have a space before the period.

produce warnings and errors.

- Removed expected 2024-02-01 Installation of the latest version of
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this sentence (or multiple sentences?) is kidna confusing.

`trulens_eval` will be an error itself.
7 changes: 0 additions & 7 deletions RELEASES.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,5 @@
# Releases

Releases are organized in `<major>.<minor>.<patch>` style. A release is made
about every week around tuesday-thursday. Releases increment the `minor` version
number. Occasionally bug-fix releases occur after a weekly release. Those
increment only the `patch` number. No releases have yet made a `major` version
increment. Those are expected to be major releases that introduce large number
of breaking changes.

## 0.33.0

### What's Changed
Expand Down
5 changes: 1 addition & 4 deletions _trulens/trulens/_bundle/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
"""
TruLens: Don't just vibe check your LLM app!

"""
"""TruLens: Don't just vibe check your LLM app!"""

from importlib.metadata import version

Expand Down
107 changes: 83 additions & 24 deletions docs/gen_ref_pages.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
"""Generate the code reference pages and navigation."""

from inspect import cleandoc
import os
from pathlib import Path
from typing import Optional
from typing import Optional, Tuple

import mkdocs_gen_files

Expand All @@ -16,6 +15,8 @@

mod_symbol = '<code class="doc-symbol doc-symbol-nav doc-symbol-module"></code>'

pack_symbol = "(package)" # <code class="doc-symbol doc-symbol-nav doc-symbol-package"></code>'


_SPECIAL_FORMATTING = {
"litellm": "LiteLLM",
Expand All @@ -29,7 +30,7 @@
}


def format_parts(parts: tuple):
def format_parts(parts: Tuple[str, ...]) -> Tuple[str, ...]:
if parts[0] == "trulens":
parts = tuple(parts[1:])

Expand All @@ -42,41 +43,109 @@ def _format_part(idx: int, part: str):
# internal package path starts at 1
# trulens.core.utils -> core is nonmodule, utils is module
seen_package_level = True

if external_package and idx == 1 and part in _SPECIAL_FORMATTING:
# trulens.providers.langchain.provider -> providers is nonmodule, langchain is package-level, provider is module
seen_package_level = True
return _SPECIAL_FORMATTING[part]
return pack_symbol + " " + _SPECIAL_FORMATTING[part]

if not seen_package_level:
return part

return f"{mod_symbol} {part}"

return tuple(_format_part(i, part) for i, part in enumerate(parts))


def write_to_gen_files(
parts: tuple, content: Optional[str] = None, doc_path: Optional[Path] = None
parts: Tuple[str, ...],
content: Optional[str] = None,
doc_path: Optional[Path] = None,
):
doc_path = doc_path or Path(*parts)

print(parts)

if parts[-1] == "__init__":
parts = parts[:-1]
doc_path = doc_path.with_name("index.md")

elif parts[-1] == "__main__":
return

full_doc_path = docs_reference_path / doc_path
nav_parts = format_parts(parts)

if (
parts[0] == "trulens_eval"
): # legacy module is in the trulens-legacy package
nav_parts = format_parts(("legacy", *parts))
else:
nav_parts = format_parts(parts)

# print(nav_parts)

nav[nav_parts] = doc_path.as_posix()

if not content:
ident = ".".join(parts)
content = f"#{ident}\n::: {ident}"
content = f"# {ident}\n::: {ident}"

if "legacy" in parts:
# Show fewer details in the legacy sections.
content += """
options:
heading_level: 2
show_bases: false
show_root_heading: false
show_root_toc_entry: false
show_source: false
show_docstring_classes: false
show_docstring_modules: false
show_docstring_parameters: false
show_docstring_returns: false
show_docstring_description: true
show_docstring_examples: false
show_docstring_other_parameters: false
show_docstring_attributes: false
show_signature: false
separate_signature: false
summary: false
group_by_category: true
members_order: alphabetical
"""
if "api" in parts:
# Show fewer details in the API sections.
content += """
options:
heading_level: 2
show_bases: false
show_root_heading: false
show_root_toc_entry: false
show_source: false
show_docstring_classes: false
show_docstring_modules: false
show_docstring_parameters: false
show_docstring_returns: false
show_docstring_description: true
show_docstring_examples: false
show_docstring_other_parameters: false
show_docstring_attributes: false
show_signature: false
separate_signature: false
summary: false
group_by_category: true
members_order: alphabetical
"""
# content = f"API {ident} [{ident}][{ident}]"

with mkdocs_gen_files.open(full_doc_path, "w") as fd:
print("writing to", full_doc_path)
fd.write(content)


core_packages = [
"api",
"legacy",
"core",
"feedback",
"dashboard",
Expand All @@ -91,20 +160,10 @@ def write_to_gen_files(
packages = core_packages + provider_packages + instrument_packages
print("Collecting from packages:", packages)

# Write Index Page
with mkdocs_gen_files.open(
docs_reference_path / "trulens" / "index.md", "w"
) as fd:
fd.write(
cleandoc(
"""
# TruLens API Reference

Welcome to the TruLens API Reference!
Use the search and navigation to explore the various modules and classes available in the TruLens library.
"""
)
)
nav["API Reference"] = "index.md"
nav["providers"] = "providers/index.md"
nav["instrument"] = "instrument/index.md"
nav["legacy"] = "legacy/index.md"

for package in packages:
# create a nav entry for package/index.md
Expand All @@ -123,12 +182,12 @@ def write_to_gen_files(
continue
if not os.path.exists(path.parent / "__init__.py"):
print(
"Skipping due to missing python package: ",
"Skipping due to missing python module: ",
path.parent / "__init__.py",
)
continue

write_to_gen_files(parts, doc_path=doc_path)

with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:
nav_file.writelines(nav.build_literate_nav())
with mkdocs_gen_files.open("reference/SUMMARY.md", "w") as nav_file:
nav_file.writelines(nav.build_literate_nav())
Loading