Skip to content

Commit

Permalink
fix(docs): Api ref linking in codeblocks
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Dec 16, 2024
1 parent 4d12e31 commit e3f016d
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 50 deletions.
76 changes: 39 additions & 37 deletions docs/core_docs/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ docs/tutorials/classification.md
docs/tutorials/classification.mdx
docs/tutorials/chatbot.md
docs/tutorials/chatbot.mdx
docs/concepts/t.md
docs/concepts/t.mdx
docs/how_to/trim_messages.md
docs/how_to/trim_messages.mdx
docs/how_to/tools_prompting.md
Expand Down Expand Up @@ -216,30 +218,8 @@ docs/how_to/assign.md
docs/how_to/assign.mdx
docs/how_to/agent_executor.md
docs/how_to/agent_executor.mdx
docs/concepts/t.md
docs/concepts/t.mdx
docs/troubleshooting/errors/INVALID_TOOL_RESULTS.md
docs/troubleshooting/errors/INVALID_TOOL_RESULTS.mdx
docs/versions/migrating_memory/conversation_summary_memory.md
docs/versions/migrating_memory/conversation_summary_memory.mdx
docs/versions/migrating_memory/conversation_buffer_window_memory.md
docs/versions/migrating_memory/conversation_buffer_window_memory.mdx
docs/versions/migrating_memory/chat_history.md
docs/versions/migrating_memory/chat_history.mdx
docs/integrations/tools/tavily_search.md
docs/integrations/tools/tavily_search.mdx
docs/integrations/tools/serpapi.md
docs/integrations/tools/serpapi.mdx
docs/integrations/tools/exa_search.md
docs/integrations/tools/exa_search.mdx
docs/integrations/tools/duckduckgo_search.md
docs/integrations/tools/duckduckgo_search.mdx
docs/integrations/toolkits/vectorstore.md
docs/integrations/toolkits/vectorstore.mdx
docs/integrations/toolkits/sql.md
docs/integrations/toolkits/sql.mdx
docs/integrations/toolkits/openapi.md
docs/integrations/toolkits/openapi.mdx
docs/integrations/vectorstores/weaviate.md
docs/integrations/vectorstores/weaviate.mdx
docs/integrations/vectorstores/upstash.md
Expand All @@ -266,20 +246,22 @@ docs/integrations/vectorstores/elasticsearch.md
docs/integrations/vectorstores/elasticsearch.mdx
docs/integrations/vectorstores/chroma.md
docs/integrations/vectorstores/chroma.mdx
docs/integrations/stores/in_memory.md
docs/integrations/stores/in_memory.mdx
docs/integrations/stores/file_system.md
docs/integrations/stores/file_system.mdx
docs/integrations/retrievers/tavily.md
docs/integrations/retrievers/tavily.mdx
docs/integrations/retrievers/kendra-retriever.md
docs/integrations/retrievers/kendra-retriever.mdx
docs/integrations/retrievers/exa.md
docs/integrations/retrievers/exa.mdx
docs/integrations/retrievers/bm25.md
docs/integrations/retrievers/bm25.mdx
docs/integrations/retrievers/bedrock-knowledge-bases.md
docs/integrations/retrievers/bedrock-knowledge-bases.mdx
docs/integrations/tools/tavily_search.md
docs/integrations/tools/tavily_search.mdx
docs/integrations/tools/serpapi.md
docs/integrations/tools/serpapi.mdx
docs/integrations/tools/google_scholar.md
docs/integrations/tools/google_scholar.mdx
docs/integrations/tools/exa_search.md
docs/integrations/tools/exa_search.mdx
docs/integrations/tools/duckduckgo_search.md
docs/integrations/tools/duckduckgo_search.mdx
docs/integrations/toolkits/vectorstore.md
docs/integrations/toolkits/vectorstore.mdx
docs/integrations/toolkits/sql.md
docs/integrations/toolkits/sql.mdx
docs/integrations/toolkits/openapi.md
docs/integrations/toolkits/openapi.mdx
docs/integrations/text_embedding/togetherai.md
docs/integrations/text_embedding/togetherai.mdx
docs/integrations/text_embedding/pinecone.md
Expand All @@ -306,6 +288,20 @@ docs/integrations/text_embedding/bedrock.md
docs/integrations/text_embedding/bedrock.mdx
docs/integrations/text_embedding/azure_openai.md
docs/integrations/text_embedding/azure_openai.mdx
docs/integrations/stores/in_memory.md
docs/integrations/stores/in_memory.mdx
docs/integrations/stores/file_system.md
docs/integrations/stores/file_system.mdx
docs/integrations/retrievers/tavily.md
docs/integrations/retrievers/tavily.mdx
docs/integrations/retrievers/kendra-retriever.md
docs/integrations/retrievers/kendra-retriever.mdx
docs/integrations/retrievers/exa.md
docs/integrations/retrievers/exa.mdx
docs/integrations/retrievers/bm25.md
docs/integrations/retrievers/bm25.mdx
docs/integrations/retrievers/bedrock-knowledge-bases.md
docs/integrations/retrievers/bedrock-knowledge-bases.mdx
docs/integrations/llms/together.md
docs/integrations/llms/together.mdx
docs/integrations/llms/openai.md
Expand Down Expand Up @@ -405,4 +401,10 @@ docs/integrations/document_loaders/web_loaders/pdf.mdx
docs/integrations/document_loaders/web_loaders/langsmith.md
docs/integrations/document_loaders/web_loaders/langsmith.mdx
docs/integrations/document_loaders/web_loaders/firecrawl.md
docs/integrations/document_loaders/web_loaders/firecrawl.mdx
docs/integrations/document_loaders/web_loaders/firecrawl.mdx
docs/versions/migrating_memory/conversation_summary_memory.md
docs/versions/migrating_memory/conversation_summary_memory.mdx
docs/versions/migrating_memory/conversation_buffer_window_memory.md
docs/versions/migrating_memory/conversation_buffer_window_memory.mdx
docs/versions/migrating_memory/chat_history.md
docs/versions/migrating_memory/chat_history.mdx
38 changes: 25 additions & 13 deletions docs/core_docs/scripts/code-block-loader.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,16 @@ const swc = require("@swc/core");
const path = require("path");
const fs = require("fs");

// Directories generated inside the API docs (excluding "modules").
const CATEGORIES = [
"classes",
"enums",
"functions",
"interfaces",
"types",
"variables",
];

/**
* Edge cases where the import will not match the proper API ref path.
* This is typically caused by a re-export, or an aliased export so we
Expand Down Expand Up @@ -90,15 +100,6 @@ const SYMBOLS_TO_SKIP_MAP = {
async function webpackLoader(content, map, meta) {
const cb = this.async();
const BASE_URL = "https://api.js.langchain.com";
// Directories generated inside the API docs (excluding "modules").
const CATEGORIES = [
"classes",
"enums",
"functions",
"interfaces",
"types",
"variables",
];

if (!this.resourcePath.endsWith(".ts")) {
cb(null, JSON.stringify({ content, imports: [] }), map, meta);
Expand Down Expand Up @@ -177,12 +178,13 @@ async function webpackLoader(content, map, meta) {
let cleanedSource = "";
if (source.startsWith("@langchain/")) {
cleanedSource = source
.replace("@langchain/", "langchain_")
.replaceAll("/", "_")
.replaceAll("-", "_");
.replace("@langchain/", "_langchain_")
.replace(/(?<=_langchain_[^/]+)\//, ".")
.replaceAll(/\//g, "_")
.replaceAll(/-/g, "_");
} else if (source.startsWith("langchain")) {
cleanedSource = source
.replace("langchain/", "langchain_")
.replace("langchain/", "langchain.")
.replaceAll("/", "_")
.replaceAll("-", "_");
} else {
Expand All @@ -191,6 +193,7 @@ async function webpackLoader(content, map, meta) {
);
}
const componentPath = `${cleanedSource}.${imported}.html`;
const componentIndexPath = `${cleanedSource}.index.${imported}.html`;

/**
* Defaults to null, reassigned to string if a match is found.
Expand All @@ -202,11 +205,19 @@ async function webpackLoader(content, map, meta) {
return;
}
const fullPath = `${category}/${componentPath}`;
const fullIndexPath = `${category}/${componentIndexPath}`;

const pathExists = fs.existsSync(getDocsPath(fullPath));
if (pathExists) {
actualPath = fullPath;
return;
}
const indexPathExists = fs.existsSync(getDocsPath(fullIndexPath));
if (indexPathExists) {
actualPath = fullIndexPath;
}
});

return actualPath;
};

Expand All @@ -222,6 +233,7 @@ async function webpackLoader(content, map, meta) {
const cleanedResourcePath = this.resourcePath.includes("examples/")
? this.resourcePath.split("examples/")[1]
: this.resourcePath;

console.warn(
{
imported,
Expand Down

0 comments on commit e3f016d

Please sign in to comment.