The agent engineering platform.
Python agentsaiai-agentsanthropicchatgptdeepagentsenterpriseframeworkgeminigenerative-ailangchainlanggraphllmmultiagentopen-sourceopenaipydanticpythonragtypescript
docs: edit links, direct for notebooks (#22051)
Erick Friis8acadc34f509
diff --git a/docs/Makefile b/docs/Makefileindex b56bacc274..e33a6654f5 100644--- a/docs/Makefile+++ b/docs/Makefile@@ -35,8 +35,6 @@ generate-files:mkdir -p $(INTERMEDIATE_DIR)cp -r $(SOURCE_DIR)/* $(INTERMEDIATE_DIR)mkdir -p $(INTERMEDIATE_DIR)/templates- cp ../templates/docs/INDEX.md $(INTERMEDIATE_DIR)/templates/index.md- cp ../cookbook/README.md $(INTERMEDIATE_DIR)/cookbook.mdx$(PYTHON) scripts/model_feat_table.py $(INTERMEDIATE_DIR)diff --git a/docs/docusaurus.config.js b/docs/docusaurus.config.jsindex 83c6e022b9..590518d18a 100644--- a/docs/docusaurus.config.js+++ b/docs/docusaurus.config.js@@ -83,6 +83,7 @@ const config = {/** @type {import('@docusaurus/preset-classic').Options} */({docs: {+ editUrl: "https://github.com/langchain-ai/langchain/edit/master/docs/",sidebarPath: require.resolve("./sidebars.js"),remarkPlugins: [[require("@docusaurus/remark-plugin-npm2yarn"), { sync: true }],diff --git a/docs/scripts/copy_templates.py b/docs/scripts/copy_templates.pyindex 015c01611e..46a4a85faf 100644--- a/docs/scripts/copy_templates.py+++ b/docs/scripts/copy_templates.py@@ -27,6 +27,7 @@ if __name__ == "__main__":sidebar_hidden = """---sidebar_class_name: hidden+custom_edit_url:---"""diff --git a/docs/scripts/model_feat_table.py b/docs/scripts/model_feat_table.pyindex 35dac13d23..ebdbaa3e9b 100644--- a/docs/scripts/model_feat_table.py+++ b/docs/scripts/model_feat_table.py@@ -103,6 +103,7 @@ LLM_TEMPLATE = """\sidebar_position: 1sidebar_class_name: hiddenkeywords: [compatibility]+custom_edit_url:---# LLMs@@ -124,6 +125,7 @@ CHAT_MODEL_TEMPLATE = """\sidebar_position: 0sidebar_class_name: hiddenkeywords: [compatibility, bind_tools, tool calling, function calling, structured output, with_structured_output, json mode, local model]+custom_edit_url:---# Chat modelsdiff --git a/docs/scripts/notebook_convert.py b/docs/scripts/notebook_convert.pyindex 76ccaf4500..0830274459 100644--- a/docs/scripts/notebook_convert.py+++ b/docs/scripts/notebook_convert.py@@ -111,15 +111,39 @@ def _process_path(tup: Tuple[Path, Path, Path]):notebook_path, intermediate_docs_dir, output_docs_dir = tuprelative = notebook_path.relative_to(intermediate_docs_dir)output_path = output_docs_dir / relative.parent / (relative.stem + ".md")- _convert_notebook(notebook_path, output_path)+ _convert_notebook(notebook_path, output_path, intermediate_docs_dir)+++def _modify_frontmatter(+ body: str, notebook_path: Path, intermediate_docs_dir: Path+) -> str:+ # if frontmatter exists+ rel_path = notebook_path.relative_to(intermediate_docs_dir).as_posix()+ edit_url = (+ f"https://github.com/langchain-ai/langchain/edit/master/docs/docs/{rel_path}"+ )+ if re.match(r"^[\s\n]*---\n", body):+ # if custom_edit_url already exists, leave it+ if re.match(r"custom_edit_url: ", body):+ return body+ else:+ return re.sub(+ r"^[\s\n]*---\n", f"---\ncustom_edit_url: {edit_url}\n", body, count=1+ )+ else:+ return f"---\ncustom_edit_url: {edit_url}\n---\n{body}"-def _convert_notebook(notebook_path: Path, output_path: Path):+def _convert_notebook(+ notebook_path: Path, output_path: Path, intermediate_docs_dir: Path+) -> Path:with open(notebook_path) as f:nb = nbformat.read(f, as_version=4)body, resources = exporter.from_notebook_node(nb)+ body = _modify_frontmatter(body, notebook_path, intermediate_docs_dir)+output_path.parent.mkdir(parents=True, exist_ok=True)with open(output_path, "w") as f:diff --git a/docs/scripts/resolve_local_links.py b/docs/scripts/resolve_local_links.pyindex 99414e3c80..ee271d3ad5 100644--- a/docs/scripts/resolve_local_links.py+++ b/docs/scripts/resolve_local_links.py@@ -13,8 +13,13 @@ def update_links(doc_path, docs_link):# replace relative linkscontent = re.sub(r"\]\(\.\/", f"]({docs_link}", content)+ frontmatter = """---+custom_edit_url:+---+"""+with open(DOCS_DIR / doc_path, "w") as f:- f.write(content)+ f.write(frontmatter + content)if __name__ == "__main__":