The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
docs: fix api ref link autogeneration (#20766)
Bagaturbe51cd3bc9fe
diff --git a/docs/scripts/generate_api_reference_links.py b/docs/scripts/generate_api_reference_links.pyindex d9b1dafb3a..77c32a4732 100644--- a/docs/scripts/generate_api_reference_links.py+++ b/docs/scripts/generate_api_reference_links.py@@ -13,10 +13,10 @@ logger = logging.getLogger(__name__)_BASE_URL = "https://api.python.langchain.com/en/latest/"# Regular expression to match Python code blocks-code_block_re = re.compile(r"^(```python\n)(.*?)(```\n)", re.DOTALL | re.MULTILINE)+code_block_re = re.compile(r"^(```\s?python\n)(.*?)(```)", re.DOTALL | re.MULTILINE)# Regular expression to match langchain import lines_IMPORT_RE = re.compile(- r"from\s+(langchain(?:_\w+)?\.\w+(?:\.\w+)*?)\s+import\s+"+ r"from\s+(langchain(?:_\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@@ -64,7 +64,6 @@ def main():global_imports = {}for file in find_files(args.docs_dir):- print(f"Adding links for imports in {file}") # noqa: T201file_imports = replace_imports(file)if file_imports:@@ -179,6 +178,8 @@ def replace_imports(file):# Use re.sub to replace each Python code blockdata = code_block_re.sub(replacer, data)+ if all_imports:+ print(f"Adding {len(all_imports)} links for imports in {file}") # noqa: T201with open(file, "w") as f:f.write(data)return all_imports