mirror of
https://github.com/hwchase17/langchain.git
synced 2025-06-19 21:33:51 +00:00
docs: edit links, direct for notebooks (#22051)
This commit is contained in:
parent
42ffcb2ff1
commit
8acadc34f5
@ -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)
|
||||
|
||||
|
@ -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 }],
|
||||
|
@ -27,6 +27,7 @@ if __name__ == "__main__":
|
||||
|
||||
sidebar_hidden = """---
|
||||
sidebar_class_name: hidden
|
||||
custom_edit_url:
|
||||
---
|
||||
|
||||
"""
|
||||
|
@ -103,6 +103,7 @@ LLM_TEMPLATE = """\
|
||||
sidebar_position: 1
|
||||
sidebar_class_name: hidden
|
||||
keywords: [compatibility]
|
||||
custom_edit_url:
|
||||
---
|
||||
|
||||
# LLMs
|
||||
@ -124,6 +125,7 @@ CHAT_MODEL_TEMPLATE = """\
|
||||
sidebar_position: 0
|
||||
sidebar_class_name: hidden
|
||||
keywords: [compatibility, bind_tools, tool calling, function calling, structured output, with_structured_output, json mode, local model]
|
||||
custom_edit_url:
|
||||
---
|
||||
|
||||
# Chat models
|
||||
|
@ -111,15 +111,39 @@ def _process_path(tup: Tuple[Path, Path, Path]):
|
||||
notebook_path, intermediate_docs_dir, output_docs_dir = tup
|
||||
relative = 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 _convert_notebook(notebook_path: Path, output_path: Path):
|
||||
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, 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:
|
||||
|
@ -13,8 +13,13 @@ def update_links(doc_path, docs_link):
|
||||
# replace relative links
|
||||
content = 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__":
|
||||
|
Loading…
Reference in New Issue
Block a user