The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
docs: automatically add api ref links (#20755)
Bagatur2a11a305729f
diff --git a/docs/.local_build.sh b/docs/.local_build.shindex a1f181198f..cde92e265f 100755--- a/docs/.local_build.sh+++ b/docs/.local_build.sh@@ -19,6 +19,9 @@ poetry run python scripts/copy_templates.pywget -q https://raw.githubusercontent.com/langchain-ai/langserve/main/README.md -O docs/langserve.mdwget -q https://raw.githubusercontent.com/langchain-ai/langgraph/main/README.md -O docs/langgraph.md-yarn-poetry run quarto preview docs+poetry run quarto render docs+poetry run python scripts/generate_api_reference_links.py --docs_dir docs++yarn+yarn startdiff --git a/docs/scripts/generate_api_reference_links.py b/docs/scripts/generate_api_reference_links.pyindex 406c1c79bf..d9b1dafb3a 100644--- a/docs/scripts/generate_api_reference_links.py+++ b/docs/scripts/generate_api_reference_links.py@@ -16,7 +16,7 @@ _BASE_URL = "https://api.python.langchain.com/en/latest/"code_block_re = re.compile(r"^(```python\n)(.*?)(```\n)", re.DOTALL | re.MULTILINE)# Regular expression to match langchain import lines_IMPORT_RE = re.compile(- r"from\s+(langchain\.\w+(\.\w+)*?)\s+import\s+"+ r"from\s+(langchain(?:_\w+)?\.\w+(?:\.\w+)*?)\s+import\s+"r"((?:\w+(?:,\s*)?)*" # Match zero or more words separated by a comma+optional wsr"(?:\s*\(.*?\))?)", # Match optional parentheses blockre.DOTALL, # Match newlines as well@@ -70,7 +70,9 @@ def main():if file_imports:# Use relative file path as keyrelative_path = (- os.path.relpath(file, _DOCS_DIR).replace(".mdx", "").replace(".md", "")+ os.path.relpath(file, args.docs_dir)+ .replace(".mdx", "/")+ .replace(".md", "/"))doc_url = f"https://python.langchain.com/docs/{relative_path}"@@ -122,8 +124,10 @@ def replace_imports(file):imports = []for import_match in _IMPORT_RE.finditer(code):module = import_match.group(1)+ if "pydantic_v1" in module:+ continueimports_str = (- import_match.group(3).replace("(\n", "").replace("\n)", "")+ import_match.group(2).replace("(\n", "").replace("\n)", "")) # Handle newlines within parentheses# remove any newline and spaces, then split by commaimported_classes = [@@ -140,7 +144,8 @@ def replace_imports(file):except ImportError as e:logger.warning(f"Failed to load for class {class_name}, {e}")continue-+ if len(module_path.split(".")) < 2:+ continueurl = (_BASE_URL+ module_path.split(".")[1]diff --git a/docs/vercel_build.sh b/docs/vercel_build.shindex 334f435c85..e63ef563ba 100755--- a/docs/vercel_build.sh+++ b/docs/vercel_build.sh@@ -33,3 +33,4 @@ python3 scripts/resolve_local_links.py docs/langgraph.md https://github.com/lang# renderquarto render docs/+python3 scripts/generate_api_reference_links.py --docs_dir docs\ No newline at end of filediff --git a/docs/vercel_requirements.txt b/docs/vercel_requirements.txtindex b33b3e5b33..9540622c7b 100644--- a/docs/vercel_requirements.txt+++ b/docs/vercel_requirements.txt@@ -1,4 +1,12 @@-e ../libs/langchain-e ../libs/community-e ../libs/core+-e ../libs/experimental+-e ../libs/text-splitters+langchain-cohere+langchain-astradb+langchain-nvidia-ai-endpoints+langchain-nvidia-trt+langchain-elasticsearch+langchain-postgresurllib3==1.26.18