mirror of
https://github.com/hwchase17/langchain.git
synced 2026-01-24 22:05:39 +00:00
attempt
This commit is contained in:
@@ -13,14 +13,19 @@
|
||||
#
|
||||
import os
|
||||
import sys
|
||||
import json
|
||||
from pathlib import Path
|
||||
|
||||
import toml
|
||||
|
||||
_DIR = Path(__file__).parent.absolute()
|
||||
sys.path.insert(0, os.path.abspath("."))
|
||||
sys.path.insert(0, os.path.abspath("../../libs/langchain"))
|
||||
|
||||
with open("../../libs/langchain/pyproject.toml") as f:
|
||||
with (_DIR.parents[1] / "libs" / "langchain" / "pyproject.toml").open("r") as f:
|
||||
data = toml.load(f)
|
||||
with (_DIR / "example_imports.json").open("r") as f:
|
||||
imported_classes = json.load(f)
|
||||
|
||||
# -- Project information -----------------------------------------------------
|
||||
|
||||
@@ -105,6 +110,7 @@ html_context = {
|
||||
"github_version": "master", # Version
|
||||
"conf_py_path": "/docs/api_reference", # Path in the checkout to the docs root
|
||||
"redirects": redirects,
|
||||
"imported_classes": imported_classes
|
||||
}
|
||||
|
||||
# Add any paths that contain custom static files (such as style sheets) here,
|
||||
|
||||
@@ -16,12 +16,10 @@ code_block_re = re.compile(r"^(```python\n)(.*?)(```\n)", re.DOTALL | re.MULTILI
|
||||
# Regular expression to match langchain import lines
|
||||
_IMPORT_RE = re.compile(r"(from\s+(langchain\.\w+(\.\w+)*?)\s+import\s+)(\w+)")
|
||||
|
||||
_CODEBLOCK_PATH = "src/theme/CodeBlock/"
|
||||
_CURRENT_PATH = Path(__file__).parent.absolute()
|
||||
# Directory where generated markdown files are stored
|
||||
_DOCS_DIR = _CURRENT_PATH / "docs"
|
||||
# Will dump to the codeblock directory / imports.json
|
||||
_JSON_PATH = _CURRENT_PATH / _CODEBLOCK_PATH / "imports.json"
|
||||
_JSON_PATH = _CURRENT_PATH.parent / 'api_reference' / "example_imports.json"
|
||||
|
||||
|
||||
def find_files(path):
|
||||
@@ -52,7 +50,12 @@ def main():
|
||||
if file_imports:
|
||||
# Use relative file path as key
|
||||
relative_path = os.path.relpath(file, _DOCS_DIR)
|
||||
global_imports[relative_path] = file_imports
|
||||
doc_url = f"https://python.langchain.com/docs/{relative_path.replace('.mdx', '').replace('.md', '')}"
|
||||
for import_info in file_imports:
|
||||
class_name = import_info["imported"]
|
||||
if class_name not in global_imports:
|
||||
global_imports[class_name] = []
|
||||
global_imports[class_name].append(doc_url)
|
||||
|
||||
# Write the global imports information to a JSON file
|
||||
with _JSON_PATH.open("w") as f:
|
||||
|
||||
Reference in New Issue
Block a user