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)
|
mkdir -p $(INTERMEDIATE_DIR)
|
||||||
cp -r $(SOURCE_DIR)/* $(INTERMEDIATE_DIR)
|
cp -r $(SOURCE_DIR)/* $(INTERMEDIATE_DIR)
|
||||||
mkdir -p $(INTERMEDIATE_DIR)/templates
|
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)
|
$(PYTHON) scripts/model_feat_table.py $(INTERMEDIATE_DIR)
|
||||||
|
|
||||||
|
@ -83,6 +83,7 @@ const config = {
|
|||||||
/** @type {import('@docusaurus/preset-classic').Options} */
|
/** @type {import('@docusaurus/preset-classic').Options} */
|
||||||
({
|
({
|
||||||
docs: {
|
docs: {
|
||||||
|
editUrl: "https://github.com/langchain-ai/langchain/edit/master/docs/",
|
||||||
sidebarPath: require.resolve("./sidebars.js"),
|
sidebarPath: require.resolve("./sidebars.js"),
|
||||||
remarkPlugins: [
|
remarkPlugins: [
|
||||||
[require("@docusaurus/remark-plugin-npm2yarn"), { sync: true }],
|
[require("@docusaurus/remark-plugin-npm2yarn"), { sync: true }],
|
||||||
|
@ -27,6 +27,7 @@ if __name__ == "__main__":
|
|||||||
|
|
||||||
sidebar_hidden = """---
|
sidebar_hidden = """---
|
||||||
sidebar_class_name: hidden
|
sidebar_class_name: hidden
|
||||||
|
custom_edit_url:
|
||||||
---
|
---
|
||||||
|
|
||||||
"""
|
"""
|
||||||
|
@ -103,6 +103,7 @@ LLM_TEMPLATE = """\
|
|||||||
sidebar_position: 1
|
sidebar_position: 1
|
||||||
sidebar_class_name: hidden
|
sidebar_class_name: hidden
|
||||||
keywords: [compatibility]
|
keywords: [compatibility]
|
||||||
|
custom_edit_url:
|
||||||
---
|
---
|
||||||
|
|
||||||
# LLMs
|
# LLMs
|
||||||
@ -124,6 +125,7 @@ CHAT_MODEL_TEMPLATE = """\
|
|||||||
sidebar_position: 0
|
sidebar_position: 0
|
||||||
sidebar_class_name: hidden
|
sidebar_class_name: hidden
|
||||||
keywords: [compatibility, bind_tools, tool calling, function calling, structured output, with_structured_output, json mode, local model]
|
keywords: [compatibility, bind_tools, tool calling, function calling, structured output, with_structured_output, json mode, local model]
|
||||||
|
custom_edit_url:
|
||||||
---
|
---
|
||||||
|
|
||||||
# Chat models
|
# Chat models
|
||||||
|
@ -111,15 +111,39 @@ def _process_path(tup: Tuple[Path, Path, Path]):
|
|||||||
notebook_path, intermediate_docs_dir, output_docs_dir = tup
|
notebook_path, intermediate_docs_dir, output_docs_dir = tup
|
||||||
relative = notebook_path.relative_to(intermediate_docs_dir)
|
relative = notebook_path.relative_to(intermediate_docs_dir)
|
||||||
output_path = output_docs_dir / relative.parent / (relative.stem + ".md")
|
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:
|
with open(notebook_path) as f:
|
||||||
nb = nbformat.read(f, as_version=4)
|
nb = nbformat.read(f, as_version=4)
|
||||||
|
|
||||||
body, resources = exporter.from_notebook_node(nb)
|
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)
|
output_path.parent.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
with open(output_path, "w") as f:
|
with open(output_path, "w") as f:
|
||||||
|
@ -13,8 +13,13 @@ def update_links(doc_path, docs_link):
|
|||||||
# replace relative links
|
# replace relative links
|
||||||
content = re.sub(r"\]\(\.\/", f"]({docs_link}", content)
|
content = re.sub(r"\]\(\.\/", f"]({docs_link}", content)
|
||||||
|
|
||||||
|
frontmatter = """---
|
||||||
|
custom_edit_url:
|
||||||
|
---
|
||||||
|
"""
|
||||||
|
|
||||||
with open(DOCS_DIR / doc_path, "w") as f:
|
with open(DOCS_DIR / doc_path, "w") as f:
|
||||||
f.write(content)
|
f.write(frontmatter + content)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
Loading…
Reference in New Issue
Block a user