mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-19 19:11:33 +00:00
API Reference building script update (#13587)
The namespaces like `langchain.agents.format_scratchpad` clogging the API Reference sidebar. This change removes those 3-level namespaces from sidebar (this issue was discussed with @efriis ) --------- Co-authored-by: Erick Friis <erick@langchain.dev>
This commit is contained in:
parent
76f30f5297
commit
7186faefb2
3
.gitignore
vendored
3
.gitignore
vendored
@ -167,8 +167,7 @@ docs/node_modules/
|
|||||||
docs/.docusaurus/
|
docs/.docusaurus/
|
||||||
docs/.cache-loader/
|
docs/.cache-loader/
|
||||||
docs/_dist
|
docs/_dist
|
||||||
docs/api_reference/api_reference.rst
|
docs/api_reference/*api_reference.rst
|
||||||
docs/api_reference/experimental_api_reference.rst
|
|
||||||
docs/api_reference/_build
|
docs/api_reference/_build
|
||||||
docs/api_reference/*/
|
docs/api_reference/*/
|
||||||
!docs/api_reference/_static/
|
!docs/api_reference/_static/
|
||||||
|
@ -196,11 +196,13 @@ def _load_package_modules(
|
|||||||
return modules_by_namespace
|
return modules_by_namespace
|
||||||
|
|
||||||
|
|
||||||
def _construct_doc(pkg: str, members_by_namespace: Dict[str, ModuleMembers]) -> str:
|
def _construct_doc(
|
||||||
|
package_namespace: str, members_by_namespace: Dict[str, ModuleMembers]
|
||||||
|
) -> str:
|
||||||
"""Construct the contents of the reference.rst file for the given package.
|
"""Construct the contents of the reference.rst file for the given package.
|
||||||
|
|
||||||
Args:
|
Args:
|
||||||
pkg: The package name
|
package_namespace: The package top level namespace
|
||||||
members_by_namespace: The members of the package, dict organized by top level
|
members_by_namespace: The members of the package, dict organized by top level
|
||||||
module contains a list of classes and functions
|
module contains a list of classes and functions
|
||||||
inside of the top level namespace.
|
inside of the top level namespace.
|
||||||
@ -210,7 +212,7 @@ def _construct_doc(pkg: str, members_by_namespace: Dict[str, ModuleMembers]) ->
|
|||||||
"""
|
"""
|
||||||
full_doc = f"""\
|
full_doc = f"""\
|
||||||
=======================
|
=======================
|
||||||
``{pkg}`` API Reference
|
``{package_namespace}`` API Reference
|
||||||
=======================
|
=======================
|
||||||
|
|
||||||
"""
|
"""
|
||||||
@ -222,13 +224,13 @@ def _construct_doc(pkg: str, members_by_namespace: Dict[str, ModuleMembers]) ->
|
|||||||
functions = _members["functions"]
|
functions = _members["functions"]
|
||||||
if not (classes or functions):
|
if not (classes or functions):
|
||||||
continue
|
continue
|
||||||
section = f":mod:`{pkg}.{module}`"
|
section = f":mod:`{package_namespace}.{module}`"
|
||||||
underline = "=" * (len(section) + 1)
|
underline = "=" * (len(section) + 1)
|
||||||
full_doc += f"""\
|
full_doc += f"""\
|
||||||
{section}
|
{section}
|
||||||
{underline}
|
{underline}
|
||||||
|
|
||||||
.. automodule:: {pkg}.{module}
|
.. automodule:: {package_namespace}.{module}
|
||||||
:no-members:
|
:no-members:
|
||||||
:no-inherited-members:
|
:no-inherited-members:
|
||||||
|
|
||||||
@ -238,7 +240,7 @@ def _construct_doc(pkg: str, members_by_namespace: Dict[str, ModuleMembers]) ->
|
|||||||
full_doc += f"""\
|
full_doc += f"""\
|
||||||
Classes
|
Classes
|
||||||
--------------
|
--------------
|
||||||
.. currentmodule:: {pkg}
|
.. currentmodule:: {package_namespace}
|
||||||
|
|
||||||
.. autosummary::
|
.. autosummary::
|
||||||
:toctree: {module}
|
:toctree: {module}
|
||||||
@ -270,7 +272,7 @@ Classes
|
|||||||
full_doc += f"""\
|
full_doc += f"""\
|
||||||
Functions
|
Functions
|
||||||
--------------
|
--------------
|
||||||
.. currentmodule:: {pkg}
|
.. currentmodule:: {package_namespace}
|
||||||
|
|
||||||
.. autosummary::
|
.. autosummary::
|
||||||
:toctree: {module}
|
:toctree: {module}
|
||||||
@ -282,57 +284,57 @@ Functions
|
|||||||
return full_doc
|
return full_doc
|
||||||
|
|
||||||
|
|
||||||
def _document_langchain_experimental() -> None:
|
def _build_rst_file(package_name: str = "langchain") -> None:
|
||||||
"""Document the langchain_experimental package."""
|
"""Create a rst file for building of documentation.
|
||||||
# Generate experimental_api_reference.rst
|
|
||||||
exp_members = _load_package_modules(EXP_DIR)
|
Args:
|
||||||
exp_doc = ".. _experimental_api_reference:\n\n" + _construct_doc(
|
package_name: Can be either "langchain" or "core" or "experimental".
|
||||||
"langchain_experimental", exp_members
|
"""
|
||||||
|
package_members = _load_package_modules(_package_dir(package_name))
|
||||||
|
with open(_out_file_path(package_name), "w") as f:
|
||||||
|
f.write(
|
||||||
|
_doc_first_line(package_name)
|
||||||
|
+ _construct_doc(package_namespace[package_name], package_members)
|
||||||
)
|
)
|
||||||
with open(EXP_WRITE_FILE, "w") as f:
|
|
||||||
f.write(exp_doc)
|
|
||||||
|
|
||||||
|
|
||||||
def _document_langchain_core() -> None:
|
package_namespace = {
|
||||||
"""Document the langchain_core package."""
|
"langchain": "langchain",
|
||||||
# Generate core_api_reference.rst
|
"experimental": "langchain_experimental",
|
||||||
core_members = _load_package_modules(CORE_DIR)
|
"core": "langchain_core",
|
||||||
core_doc = ".. _core_api_reference:\n\n" + _construct_doc(
|
}
|
||||||
"langchain_core", core_members
|
|
||||||
)
|
|
||||||
with open(CORE_WRITE_FILE, "w") as f:
|
|
||||||
f.write(core_doc)
|
|
||||||
|
|
||||||
|
|
||||||
def _document_langchain() -> None:
|
def _package_dir(package_name: str = "langchain") -> Path:
|
||||||
"""Document the main langchain package."""
|
"""Return the path to the directory containing the documentation."""
|
||||||
# load top level module members
|
return ROOT_DIR / "libs" / package_name / package_namespace[package_name]
|
||||||
lc_members = _load_package_modules(PKG_DIR)
|
|
||||||
|
|
||||||
# Add additional packages
|
|
||||||
tools = _load_package_modules(PKG_DIR, "tools")
|
|
||||||
agents = _load_package_modules(PKG_DIR, "agents")
|
|
||||||
schema = _load_package_modules(PKG_DIR, "schema")
|
|
||||||
|
|
||||||
lc_members.update(
|
def _out_file_path(package_name: str = "langchain") -> Path:
|
||||||
{
|
"""Return the path to the file containing the documentation."""
|
||||||
"agents.output_parsers": agents["output_parsers"],
|
name_prefix = {
|
||||||
"agents.format_scratchpad": agents["format_scratchpad"],
|
"langchain": "",
|
||||||
"tools.render": tools["render"],
|
"experimental": "experimental_",
|
||||||
|
"core": "core_",
|
||||||
}
|
}
|
||||||
)
|
return HERE / f"{name_prefix[package_name]}api_reference.rst"
|
||||||
|
|
||||||
lc_doc = ".. _api_reference:\n\n" + _construct_doc("langchain", lc_members)
|
|
||||||
|
|
||||||
with open(WRITE_FILE, "w") as f:
|
def _doc_first_line(package_name: str = "langchain") -> str:
|
||||||
f.write(lc_doc)
|
"""Return the path to the file containing the documentation."""
|
||||||
|
prefix = {
|
||||||
|
"langchain": "",
|
||||||
|
"experimental": "experimental",
|
||||||
|
"core": "core",
|
||||||
|
}
|
||||||
|
return f".. {prefix[package_name]}_api_reference:\n\n"
|
||||||
|
|
||||||
|
|
||||||
def main() -> None:
|
def main() -> None:
|
||||||
"""Generate the reference.rst file for each package."""
|
"""Generate the api_reference.rst file for each package."""
|
||||||
_document_langchain()
|
_build_rst_file(package_name="core")
|
||||||
_document_langchain_experimental()
|
_build_rst_file(package_name="langchain")
|
||||||
_document_langchain_core()
|
_build_rst_file(package_name="experimental")
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user