Skip to content

Commit

Permalink
add experimental ref (langchain-ai#8435)
Browse files Browse the repository at this point in the history
  • Loading branch information
baskaryan authored Jul 28, 2023
1 parent fab2445 commit 2db2987
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ docs/.docusaurus/
docs/.cache-loader/
docs/_dist
docs/api_reference/api_reference.rst
docs/api_reference/experimental_api_reference.rst
docs/api_reference/_build
docs/api_reference/*/
!docs/api_reference/_static/
Expand Down
1 change: 1 addition & 0 deletions docs/api_reference/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
_DIR = Path(__file__).parent.absolute()
sys.path.insert(0, os.path.abspath("."))
sys.path.insert(0, os.path.abspath("../../libs/langchain"))
sys.path.insert(0, os.path.abspath("../../libs/experimental"))

with (_DIR.parents[1] / "libs" / "langchain" / "pyproject.toml").open("r") as f:
data = toml.load(f)
Expand Down
34 changes: 19 additions & 15 deletions docs/api_reference/create_api_rst.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,15 @@

ROOT_DIR = Path(__file__).parents[2].absolute()
PKG_DIR = ROOT_DIR / "libs" / "langchain" / "langchain"
EXP_DIR = ROOT_DIR / "libs" / "experimental" / "langchain_experimental"
WRITE_FILE = Path(__file__).parent / "api_reference.rst"
EXP_WRITE_FILE = Path(__file__).parent / "experimental_api_reference.rst"


def load_members() -> dict:
def load_members(dir: Path) -> dict:
members: dict = {}
for py in glob.glob(str(PKG_DIR) + "/**/*.py", recursive=True):
module = py[len(str(PKG_DIR)) + 1 :].replace(".py", "").replace("/", ".")
for py in glob.glob(str(dir) + "/**/*.py", recursive=True):
module = py[len(str(dir)) + 1 :].replace(".py", "").replace("/", ".")
top_level = module.split(".")[0]
if top_level not in members:
members[top_level] = {"classes": [], "functions": []}
Expand All @@ -26,12 +28,10 @@ def load_members() -> dict:
return members


def construct_doc(members: dict) -> str:
full_doc = """\
.. _api_reference:
def construct_doc(pkg: str, members: dict) -> str:
full_doc = f"""\
=============
API Reference
``{pkg}`` API Reference
=============
"""
Expand All @@ -40,12 +40,12 @@ def construct_doc(members: dict) -> str:
functions = _members["functions"]
if not (classes or functions):
continue
section = f":mod:`langchain.{module}`"
section = f":mod:`{pkg}.{module}`"
full_doc += f"""\
{section}
{'=' * (len(section) + 1)}
.. automodule:: langchain.{module}
.. automodule:: {pkg}.{module}
:no-members:
:no-inherited-members:
Expand All @@ -56,7 +56,7 @@ def construct_doc(members: dict) -> str:
full_doc += f"""\
Classes
--------------
.. currentmodule:: langchain
.. currentmodule:: {pkg}
.. autosummary::
:toctree: {module}
Expand All @@ -70,7 +70,7 @@ def construct_doc(members: dict) -> str:
full_doc += f"""\
Functions
--------------
.. currentmodule:: langchain
.. currentmodule:: {pkg}
.. autosummary::
:toctree: {module}
Expand All @@ -83,10 +83,14 @@ def construct_doc(members: dict) -> str:


def main() -> None:
members = load_members()
full_doc = construct_doc(members)
lc_members = load_members(PKG_DIR)
lc_doc = ".. _api_reference:\n\n" + construct_doc("langchain", lc_members)
with open(WRITE_FILE, "w") as f:
f.write(full_doc)
f.write(lc_doc)
exp_members = load_members(EXP_DIR)
exp_doc = ".. _experimental_api_reference:\n\n" + construct_doc("langchain_experimental", exp_members)
with open(EXP_WRITE_FILE, "w") as f:
f.write(exp_doc)


if __name__ == "__main__":
Expand Down
3 changes: 3 additions & 0 deletions docs/api_reference/themes/scikit-learn-modern/nav.html
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@
<li class="nav-item">
<a class="sk-nav-link nav-link" href="{{ pathto('api_reference') }}">API</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link" href="{{ pathto('experimental_api_reference') }}">Experimental</a>
</li>
<li class="nav-item">
<a class="sk-nav-link nav-link" target="_blank" rel="noopener noreferrer" href="https://python.langchain.com/">Python Docs</a>
</li>
Expand Down

0 comments on commit 2db2987

Please sign in to comment.