mirror of
https://github.com/hwchase17/langchain.git
synced 2025-07-06 13:18:12 +00:00
docs: upgrade to docusaurus v3 (#26803)
This commit is contained in:
parent
b1da532522
commit
f9ef688b3a
@ -41,10 +41,7 @@ data = json.loads(Path(file_path).read_text())
|
||||
```python
|
||||
pprint(data)
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
{'image': {'creation_timestamp': 1675549016, 'uri': 'image_of_the_chat.jpg'},
|
||||
'is_still_participant': True,
|
||||
'joinable_mode': {'link': '', 'mode': 1},
|
||||
@ -91,7 +88,6 @@ pprint(data)
|
||||
'title': 'User 1 and User 2 chat'}
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
|
||||
## Using `JSONLoader`
|
||||
@ -115,9 +111,7 @@ data = loader.load()
|
||||
pprint(data)
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
[Document(page_content='Bye!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 1}),
|
||||
Document(page_content='Oh no worries! Bye', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 2}),
|
||||
Document(page_content='No Im sorry it was my mistake, the blue one is not for sale', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 3}),
|
||||
@ -131,7 +125,6 @@ pprint(data)
|
||||
Document(page_content='Hi! Im interested in your bag. Im offering $50. Let me know if you are interested. Thanks!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 11})]
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
|
||||
### JSON Lines file
|
||||
@ -144,9 +137,7 @@ file_path = './example_data/facebook_chat_messages.jsonl'
|
||||
pprint(Path(file_path).read_text())
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
('{"sender_name": "User 2", "timestamp_ms": 1675597571851, "content": "Bye!"}\n'
|
||||
'{"sender_name": "User 1", "timestamp_ms": 1675597435669, "content": "Oh no '
|
||||
'worries! Bye"}\n'
|
||||
@ -154,7 +145,6 @@ pprint(Path(file_path).read_text())
|
||||
'sorry it was my mistake, the blue one is not for sale"}\n')
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
|
||||
```python
|
||||
@ -171,15 +161,12 @@ data = loader.load()
|
||||
pprint(data)
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
[Document(page_content='Bye!', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 1}),
|
||||
Document(page_content='Oh no worries! Bye', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 2}),
|
||||
Document(page_content='No Im sorry it was my mistake, the blue one is not for sale', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 3})]
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
|
||||
Another option is to set `jq_schema='.'` and provide `content_key`:
|
||||
@ -198,15 +185,12 @@ data = loader.load()
|
||||
pprint(data)
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
[Document(page_content='User 2', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 1}),
|
||||
Document(page_content='User 1', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 2}),
|
||||
Document(page_content='User 2', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat_messages.jsonl', 'seq_num': 3})]
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
### JSON file with jq schema `content_key`
|
||||
|
||||
@ -218,9 +202,7 @@ file_path = './sample.json'
|
||||
pprint(Path(file_path).read_text())
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```json
|
||||
```outputjson
|
||||
{"data": [
|
||||
{"attributes": {
|
||||
"message": "message1",
|
||||
@ -234,7 +216,6 @@ pprint(Path(file_path).read_text())
|
||||
"id": "2"}]}
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
|
||||
```python
|
||||
@ -252,14 +233,11 @@ data = loader.load()
|
||||
pprint(data)
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
[Document(page_content='message1', metadata={'source': '/path/to/sample.json', 'seq_num': 1}),
|
||||
Document(page_content='message2', metadata={'source': '/path/to/sample.json', 'seq_num': 2})]
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
## Extracting metadata
|
||||
|
||||
@ -309,9 +287,7 @@ data = loader.load()
|
||||
pprint(data)
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
[Document(page_content='Bye!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 1, 'sender_name': 'User 2', 'timestamp_ms': 1675597571851}),
|
||||
Document(page_content='Oh no worries! Bye', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 2, 'sender_name': 'User 1', 'timestamp_ms': 1675597435669}),
|
||||
Document(page_content='No Im sorry it was my mistake, the blue one is not for sale', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 3, 'sender_name': 'User 2', 'timestamp_ms': 1675596277579}),
|
||||
@ -325,7 +301,6 @@ pprint(data)
|
||||
Document(page_content='Hi! Im interested in your bag. Im offering $50. Let me know if you are interested. Thanks!', metadata={'source': '/Users/avsolatorio/WBG/langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 11, 'sender_name': 'User 1', 'timestamp_ms': 1675549022673})]
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
Now, you will see that the documents contain the metadata associated with the content we extracted.
|
||||
|
||||
@ -368,9 +343,7 @@ data = loader.load()
|
||||
pprint(data)
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
[Document(page_content='Bye!', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 1, 'sender_name': 'User 2', 'timestamp_ms': 1675597571851}),
|
||||
Document(page_content='Oh no worries! Bye', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 2, 'sender_name': 'User 1', 'timestamp_ms': 1675597435669}),
|
||||
Document(page_content='No Im sorry it was my mistake, the blue one is not for sale', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 3, 'sender_name': 'User 2', 'timestamp_ms': 1675596277579}),
|
||||
@ -384,7 +357,6 @@ pprint(data)
|
||||
Document(page_content='Hi! Im interested in your bag. Im offering $50. Let me know if you are interested. Thanks!', metadata={'source': 'langchain/docs/modules/indexes/document_loaders/examples/example_data/facebook_chat.json', 'seq_num': 11, 'sender_name': 'User 1', 'timestamp_ms': 1675549022673})]
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
## Common JSON structures with jq schema
|
||||
|
||||
|
@ -115,13 +115,10 @@ embeddings = embeddings_model.embed_documents(
|
||||
len(embeddings), len(embeddings[0])
|
||||
```
|
||||
|
||||
<CodeOutputBlock language="python">
|
||||
|
||||
```
|
||||
```output
|
||||
(5, 1536)
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
### `embed_query`
|
||||
#### Embed single query
|
||||
@ -132,9 +129,7 @@ embedded_query = embeddings_model.embed_query("What was the name mentioned in th
|
||||
embedded_query[:5]
|
||||
```
|
||||
|
||||
<CodeOutputBlock language="python">
|
||||
|
||||
```
|
||||
```output
|
||||
[0.0053587136790156364,
|
||||
-0.0004999046213924885,
|
||||
0.038883671164512634,
|
||||
@ -142,4 +137,3 @@ embedded_query[:5]
|
||||
-0.00900818221271038]
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
@ -208,7 +208,7 @@
|
||||
"\n",
|
||||
"Metal is a graphics and compute API created by Apple providing near-direct access to the GPU. \n",
|
||||
"\n",
|
||||
"See the [`llama.cpp`](docs/integrations/llms/llamacpp) setup [here](https://github.com/abetlen/llama-cpp-python/blob/main/docs/install/macos.md) to enable this.\n",
|
||||
"See the [`llama.cpp`](/docs/integrations/llms/llamacpp) setup [here](https://github.com/abetlen/llama-cpp-python/blob/main/docs/install/macos.md) to enable this.\n",
|
||||
"\n",
|
||||
"In particular, ensure that conda is using the correct virtual environment that you created (`miniforge3`).\n",
|
||||
"\n",
|
||||
|
@ -124,6 +124,7 @@
|
||||
"We can now create the chain that we will use to do question-answering over.\n",
|
||||
"\n",
|
||||
"Let's first select a LLM.\n",
|
||||
"\n",
|
||||
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
|
||||
"\n",
|
||||
"<ChatModelTabs customVarName=\"llm\" />\n"
|
||||
|
@ -1,7 +1,7 @@
|
||||
{
|
||||
"cells": [
|
||||
{
|
||||
"cell_type": "markdown",
|
||||
"cell_type": "raw",
|
||||
"id": "c47f5b2f-e14c-43e7-a0ab-d71562636624",
|
||||
"metadata": {},
|
||||
"source": [
|
||||
@ -41,6 +41,7 @@
|
||||
"## Load chat model\n",
|
||||
"\n",
|
||||
"Let's first load a chat model:\n",
|
||||
"\n",
|
||||
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
|
||||
"\n",
|
||||
"<ChatModelTabs\n",
|
||||
|
@ -46,6 +46,7 @@
|
||||
"## Load chat model\n",
|
||||
"\n",
|
||||
"Let's first load a chat model:\n",
|
||||
"\n",
|
||||
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
|
||||
"\n",
|
||||
"<ChatModelTabs\n",
|
||||
|
@ -31,6 +31,7 @@
|
||||
"## Load chat model\n",
|
||||
"\n",
|
||||
"Let's first load a chat model:\n",
|
||||
"\n",
|
||||
"import ChatModelTabs from \"@theme/ChatModelTabs\";\n",
|
||||
"\n",
|
||||
"<ChatModelTabs\n",
|
||||
|
@ -116,9 +116,7 @@ docs = db.similarity_search(query)
|
||||
print(docs[0].page_content)
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections.
|
||||
|
||||
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.
|
||||
@ -128,7 +126,6 @@ print(docs[0].page_content)
|
||||
And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
### Similarity search by vector
|
||||
|
||||
@ -140,9 +137,7 @@ docs = db.similarity_search_by_vector(embedding_vector)
|
||||
print(docs[0].page_content)
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections.
|
||||
|
||||
Tonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service.
|
||||
@ -152,7 +147,6 @@ print(docs[0].page_content)
|
||||
And I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
||||
|
||||
## Async Operations
|
||||
|
||||
@ -166,13 +160,9 @@ docs = await db.asimilarity_search(query)
|
||||
docs
|
||||
```
|
||||
|
||||
<CodeOutputBlock lang="python">
|
||||
|
||||
```
|
||||
```output
|
||||
[Document(page_content='Tonight. I call on the Senate to: Pass the Freedom to Vote Act. Pass the John Lewis Voting Rights Act. And while you’re at it, pass the Disclose Act so Americans can know who is funding our elections. \n\nTonight, I’d like to honor someone who has dedicated his life to serve this country: Justice Stephen Breyer—an Army veteran, Constitutional scholar, and retiring Justice of the United States Supreme Court. Justice Breyer, thank you for your service. \n\nOne of the most serious constitutional responsibilities a President has is nominating someone to serve on the United States Supreme Court. \n\nAnd I did that 4 days ago, when I nominated Circuit Court of Appeals Judge Ketanji Brown Jackson. One of our nation’s top legal minds, who will continue Justice Breyer’s legacy of excellence.', metadata={'source': 'state_of_the_union.txt'}),
|
||||
Document(page_content='A former top litigator in private practice. A former federal public defender. And from a family of public school educators and police officers. A consensus builder. Since she’s been nominated, she’s received a broad range of support—from the Fraternal Order of Police to former judges appointed by Democrats and Republicans. \n\nAnd if we are to advance liberty and justice, we need to secure the Border and fix the immigration system. \n\nWe can do both. At our border, we’ve installed new technology like cutting-edge scanners to better detect drug smuggling. \n\nWe’ve set up joint patrols with Mexico and Guatemala to catch more human traffickers. \n\nWe’re putting in place dedicated immigration judges so families fleeing persecution and violence can have their cases heard faster. \n\nWe’re securing commitments and supporting partners in South and Central America to host more refugees and secure their own borders.', metadata={'source': 'state_of_the_union.txt'}),
|
||||
Document(page_content='And for our LGBTQ+ Americans, let’s finally get the bipartisan Equality Act to my desk. The onslaught of state laws targeting transgender Americans and their families is wrong. \n\nAs I said last year, especially to our younger transgender Americans, I will always have your back as your President, so you can be yourself and reach your God-given potential. \n\nWhile it often appears that we never agree, that isn’t true. I signed 80 bipartisan bills into law last year. From preventing government shutdowns to protecting Asian-Americans from still-too-common hate crimes to reforming military justice. \n\nAnd soon, we’ll strengthen the Violence Against Women Act that I first wrote three decades ago. It is important for us to show the nation that we can come together and do big things. \n\nSo tonight I’m offering a Unity Agenda for the Nation. Four big things we can do together. \n\nFirst, beat the opioid epidemic.', metadata={'source': 'state_of_the_union.txt'}),
|
||||
Document(page_content='Tonight, I’m announcing a crackdown on these companies overcharging American businesses and consumers. \n\nAnd as Wall Street firms take over more nursing homes, quality in those homes has gone down and costs have gone up. \n\nThat ends on my watch. \n\nMedicare is going to set higher standards for nursing homes and make sure your loved ones get the care they deserve and expect. \n\nWe’ll also cut costs and keep the economy going strong by giving workers a fair shot, provide more training and apprenticeships, hire them based on their skills not degrees. \n\nLet’s pass the Paycheck Fairness Act and paid leave. \n\nRaise the minimum wage to $15 an hour and extend the Child Tax Credit, so no one has to raise a family in poverty. \n\nLet’s increase Pell Grants and increase our historic support of HBCUs, and invest in what Jill—our First Lady who teaches full-time—calls America’s best-kept secret: community colleges.', metadata={'source': 'state_of_the_union.txt'})]
|
||||
```
|
||||
|
||||
</CodeOutputBlock>
|
@ -12,7 +12,7 @@ You are currently on a page documenting the use of [text completion models](/doc
|
||||
Unless you are specifically using more advanced prompting techniques, you are probably looking for [this page instead](/docs/integrations/chat/).
|
||||
:::
|
||||
|
||||
[LLMs](docs/concepts/#llms) are language models that take a string as input and return a string as output.
|
||||
[LLMs](/docs/concepts/#llms) are language models that take a string as input and return a string as output.
|
||||
|
||||
:::info
|
||||
|
||||
|
@ -229,9 +229,10 @@ query_result = embedder.embed_query(query)
|
||||
|
||||
print(query_result[:5])
|
||||
```
|
||||
<Note>
|
||||
|
||||
:::note
|
||||
Setting `model_name` argument in mandatory for PremAIEmbeddings unlike chat.
|
||||
</Note>
|
||||
:::
|
||||
|
||||
Finally, let's embed some sample document
|
||||
|
||||
|
@ -62,16 +62,10 @@
|
||||
},
|
||||
{
|
||||
"cell_type": "code",
|
||||
"execution_count": 3,
|
||||
"execution_count": null,
|
||||
"id": "f47a2bfe",
|
||||
"metadata": {},
|
||||
"outputs": [
|
||||
{
|
||||
"name": "stderr",
|
||||
"output_type": "stream",
|
||||
"text": []
|
||||
}
|
||||
],
|
||||
"outputs": [],
|
||||
"source": [
|
||||
"from langchain_community.retrievers import (\n",
|
||||
" WeaviateHybridSearchRetriever,\n",
|
||||
|
@ -6,8 +6,10 @@
|
||||
const { ProvidePlugin } = require("webpack");
|
||||
require("dotenv").config();
|
||||
|
||||
const baseLightCodeBlockTheme = require("prism-react-renderer/themes/vsLight");
|
||||
const baseDarkCodeBlockTheme = require("prism-react-renderer/themes/vsDark");
|
||||
const prism = require("prism-react-renderer");
|
||||
|
||||
const baseLightCodeBlockTheme = prism.themes.vsLight;
|
||||
const baseDarkCodeBlockTheme = prism.themes.vsDark;
|
||||
|
||||
const baseUrl = "/";
|
||||
|
||||
|
@ -22,20 +22,21 @@
|
||||
"check-broken-links": "bash vercel_build.sh && node ./scripts/check-broken-links.js"
|
||||
},
|
||||
"dependencies": {
|
||||
"@docusaurus/core": "2.4.3",
|
||||
"@docusaurus/preset-classic": "2.4.3",
|
||||
"@docusaurus/remark-plugin-npm2yarn": "^2.4.3",
|
||||
"@docusaurus/theme-mermaid": "2.4.3",
|
||||
"@mdx-js/react": "^1.6.22",
|
||||
"@docusaurus/core": "3.5.2",
|
||||
"@docusaurus/preset-classic": "3.5.2",
|
||||
"@docusaurus/remark-plugin-npm2yarn": "^3.5.2",
|
||||
"@docusaurus/theme-mermaid": "3.5.2",
|
||||
"prism-react-renderer": "^2.1.0",
|
||||
"@mdx-js/react": "^3",
|
||||
"@supabase/supabase-js": "^2.39.7",
|
||||
"clsx": "^1.2.1",
|
||||
"cookie": "^0.6.0",
|
||||
"isomorphic-dompurify": "^2.7.0",
|
||||
"json-loader": "^0.5.7",
|
||||
"process": "^0.11.10",
|
||||
"react": "^17.0.2",
|
||||
"react-dom": "^17.0.2",
|
||||
"typescript": "^5.1.3",
|
||||
"react": "^18",
|
||||
"react-dom": "^18",
|
||||
"typescript": "^5.2.2",
|
||||
"uuid": "^9.0.0",
|
||||
"webpack": "^5.75.0"
|
||||
},
|
||||
|
@ -25,13 +25,22 @@ class EscapePreprocessor(Preprocessor):
|
||||
cell.source = cell.source.replace("```", r"\`\`\`")
|
||||
# escape ``` in output
|
||||
if "outputs" in cell:
|
||||
for output in cell["outputs"]:
|
||||
filter_out = set()
|
||||
for i, output in enumerate(cell["outputs"]):
|
||||
if "text" in output:
|
||||
if not output["text"].strip():
|
||||
filter_out.add(i)
|
||||
continue
|
||||
output["text"] = output["text"].replace("```", r"\`\`\`")
|
||||
if "data" in output:
|
||||
elif "data" in output:
|
||||
for key, value in output["data"].items():
|
||||
if isinstance(value, str):
|
||||
output["data"][key] = value.replace("```", r"\`\`\`")
|
||||
cell["outputs"] = [
|
||||
output
|
||||
for i, output in enumerate(cell["outputs"])
|
||||
if i not in filter_out
|
||||
]
|
||||
|
||||
return cell, resources
|
||||
|
||||
|
@ -1,17 +0,0 @@
|
||||
import React from "react";
|
||||
|
||||
export function ColumnContainer({children}) {
|
||||
return (
|
||||
<div style={{ display: "flex", flexWrap: "wrap" }}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
||||
|
||||
export function Column({children}) {
|
||||
return (
|
||||
<div style={{ flex: "1 0 300px", padding: "10px", overflowX: "scroll", zoom: '80%' }}>
|
||||
{children}
|
||||
</div>
|
||||
)
|
||||
}
|
@ -1,6 +1,6 @@
|
||||
import React from 'react';
|
||||
import Paginator from '@theme-original/DocItem/Paginator';
|
||||
import Feedback from "../../Feedback";
|
||||
import Feedback from "@theme/Feedback";
|
||||
|
||||
export default function PaginatorWrapper(props) {
|
||||
return (
|
||||
|
@ -1,201 +0,0 @@
|
||||
// Swizzled class to show custom text for canary version.
|
||||
// Should be removed in favor of the stock implementation.
|
||||
|
||||
import React from 'react';
|
||||
import clsx from 'clsx';
|
||||
import useDocusaurusContext from '@docusaurus/useDocusaurusContext';
|
||||
import Link from '@docusaurus/Link';
|
||||
import Translate from '@docusaurus/Translate';
|
||||
import {
|
||||
useActivePlugin,
|
||||
useDocVersionSuggestions,
|
||||
} from '@docusaurus/plugin-content-docs/client';
|
||||
import {ThemeClassNames} from '@docusaurus/theme-common';
|
||||
import {
|
||||
useDocsPreferredVersion,
|
||||
useDocsVersion,
|
||||
} from '@docusaurus/theme-common/internal';
|
||||
function UnreleasedVersionLabel({siteTitle, versionMetadata}) {
|
||||
return (
|
||||
<Translate
|
||||
id="theme.docs.versions.unreleasedVersionLabel"
|
||||
description="The label used to tell the user that he's browsing an unreleased doc version"
|
||||
values={{
|
||||
siteTitle,
|
||||
versionLabel: <b>{versionMetadata.label}</b>,
|
||||
}}>
|
||||
{
|
||||
'This is unreleased documentation for {siteTitle}\'s {versionLabel} version.'
|
||||
}
|
||||
</Translate>
|
||||
);
|
||||
}
|
||||
function UnmaintainedVersionLabel({siteTitle, versionMetadata}) {
|
||||
return (
|
||||
<Translate
|
||||
id="theme.docs.versions.unmaintainedVersionLabel"
|
||||
description="The label used to tell the user that he's browsing an unmaintained doc version"
|
||||
values={{
|
||||
siteTitle,
|
||||
versionLabel: <b>{versionMetadata.label}</b>,
|
||||
}}>
|
||||
{
|
||||
'This is documentation for {siteTitle} {versionLabel}, which is no longer actively maintained.'
|
||||
}
|
||||
</Translate>
|
||||
);
|
||||
}
|
||||
const BannerLabelComponents = {
|
||||
unreleased: UnreleasedVersionLabel,
|
||||
unmaintained: UnmaintainedVersionLabel,
|
||||
};
|
||||
function BannerLabel(props) {
|
||||
const BannerLabelComponent =
|
||||
BannerLabelComponents[props.versionMetadata.banner];
|
||||
return <BannerLabelComponent {...props} />;
|
||||
}
|
||||
function LatestVersionSuggestionLabel({versionLabel, to, onClick}) {
|
||||
return (
|
||||
<Translate
|
||||
id="theme.docs.versions.latestVersionSuggestionLabel"
|
||||
description="The label used to tell the user to check the latest version"
|
||||
values={{
|
||||
versionLabel,
|
||||
latestVersionLink: (
|
||||
<b>
|
||||
<Link to={to} onClick={onClick}>
|
||||
<Translate
|
||||
id="theme.docs.versions.latestVersionLinkLabel"
|
||||
description="The label used for the latest version suggestion link label">
|
||||
this version
|
||||
</Translate>
|
||||
</Link>
|
||||
</b>
|
||||
),
|
||||
}}>
|
||||
{
|
||||
'For the current stable version, see {latestVersionLink} ({versionLabel}).'
|
||||
}
|
||||
</Translate>
|
||||
);
|
||||
}
|
||||
function DocVersionBannerEnabled({className, versionMetadata}) {
|
||||
const {
|
||||
siteConfig: {title: siteTitle},
|
||||
} = useDocusaurusContext();
|
||||
const {pluginId} = useActivePlugin({failfast: true});
|
||||
const getVersionMainDoc = (version) =>
|
||||
version.docs.find((doc) => doc.id === version.mainDocId);
|
||||
const {savePreferredVersionName} = useDocsPreferredVersion(pluginId);
|
||||
const {latestDocSuggestion, latestVersionSuggestion} =
|
||||
useDocVersionSuggestions(pluginId);
|
||||
// Try to link to same doc in latest version (not always possible), falling
|
||||
// back to main doc of latest version
|
||||
const latestVersionSuggestedDoc =
|
||||
latestDocSuggestion ?? getVersionMainDoc(latestVersionSuggestion);
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
className,
|
||||
ThemeClassNames.docs.docVersionBanner,
|
||||
'alert alert--warning margin-bottom--md',
|
||||
)}
|
||||
role="alert">
|
||||
<div>
|
||||
<BannerLabel siteTitle={siteTitle} versionMetadata={versionMetadata} />
|
||||
</div>
|
||||
<div className="margin-top--md">
|
||||
<LatestVersionSuggestionLabel
|
||||
versionLabel={latestVersionSuggestion.label}
|
||||
to={latestVersionSuggestedDoc.path}
|
||||
onClick={() => savePreferredVersionName(latestVersionSuggestion.name)}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function LatestDocVersionBanner({className, versionMetadata}) {
|
||||
const {
|
||||
siteConfig: {title: siteTitle},
|
||||
} = useDocusaurusContext();
|
||||
const {pluginId} = useActivePlugin({failfast: true});
|
||||
const getVersionMainDoc = (version) =>
|
||||
version.docs.find((doc) => doc.id === version.mainDocId);
|
||||
const {savePreferredVersionName} = useDocsPreferredVersion(pluginId);
|
||||
const {latestDocSuggestion, latestVersionSuggestion} =
|
||||
useDocVersionSuggestions(pluginId);
|
||||
// Try to link to same doc in latest version (not always possible), falling
|
||||
// back to main doc of latest version
|
||||
const latestVersionSuggestedDoc =
|
||||
latestDocSuggestion ?? getVersionMainDoc(latestVersionSuggestion);
|
||||
const canaryPath = `/docs/0.2.x/${latestVersionSuggestedDoc.path.slice("/docs/".length)}`;
|
||||
return (
|
||||
<div
|
||||
className={clsx(
|
||||
className,
|
||||
ThemeClassNames.docs.docVersionBanner,
|
||||
'alert alert--info margin-bottom--md',
|
||||
)}
|
||||
role="alert">
|
||||
<div>
|
||||
<Translate
|
||||
id="theme.docs.versions.unmaintainedVersionLabel"
|
||||
description="The label used to encourage the user to view the experimental 0.2.x version"
|
||||
values={{
|
||||
siteTitle,
|
||||
versionLabel: <b>{versionMetadata.label}</b>,
|
||||
}}>
|
||||
{
|
||||
'This is a stable version of documentation for {siteTitle}\'s version {versionLabel}.'
|
||||
}
|
||||
</Translate>
|
||||
</div>
|
||||
<div className="margin-top--md">
|
||||
<Translate
|
||||
id="theme.docs.versions.latestVersionSuggestionLabel"
|
||||
description="The label used to tell the user to check the experimental version"
|
||||
values={{
|
||||
versionLabel: <b>{versionMetadata.label}</b>,
|
||||
latestVersionLink: (
|
||||
<b>
|
||||
<Link to={canaryPath} onClick={() => savePreferredVersionName("0.2.x")}>
|
||||
<Translate
|
||||
id="theme.docs.versions.latestVersionLinkLabel"
|
||||
description="The label used for the latest version suggestion link label">
|
||||
this experimental version
|
||||
</Translate>
|
||||
</Link>
|
||||
</b>
|
||||
),
|
||||
}}>
|
||||
{
|
||||
'You can also check out {latestVersionLink} for an updated experience.'
|
||||
}
|
||||
</Translate>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
export default function DocVersionBanner({className}) {
|
||||
const versionMetadata = useDocsVersion();
|
||||
if (versionMetadata.banner) {
|
||||
return (
|
||||
<DocVersionBannerEnabled
|
||||
className={className}
|
||||
versionMetadata={versionMetadata}
|
||||
/>
|
||||
);
|
||||
} else if (versionMetadata.isLast) {
|
||||
// Uncomment when we are ready to direct people to new build
|
||||
// return (
|
||||
// <LatestDocVersionBanner
|
||||
// className={className}
|
||||
// versionMetadata={versionMetadata}
|
||||
// />
|
||||
// );
|
||||
return null;
|
||||
}
|
||||
return null;
|
||||
}
|
@ -2,7 +2,7 @@ import React from "react";
|
||||
import {useCurrentSidebarCategory} from '@docusaurus/theme-common';
|
||||
import {
|
||||
useDocById,
|
||||
} from '@docusaurus/theme-common/internal';
|
||||
} from '@docusaurus/plugin-content-docs/client';
|
||||
|
||||
const FEATURE_TABLES = {
|
||||
chat: {
|
||||
|
@ -1,8 +1,5 @@
|
||||
import React from 'react';
|
||||
import Translate, {translate} from '@docusaurus/Translate';
|
||||
import {PageMetadata} from '@docusaurus/theme-common';
|
||||
import Layout from '@theme/Layout';
|
||||
|
||||
import clsx from 'clsx';
|
||||
import {useLocation} from 'react-router-dom';
|
||||
|
||||
function LegacyBadge() {
|
||||
@ -11,58 +8,48 @@ function LegacyBadge() {
|
||||
);
|
||||
}
|
||||
|
||||
export default function NotFound() {
|
||||
export default function NotFoundContent({className}) {
|
||||
const location = useLocation();
|
||||
const pathname = location.pathname.endsWith('/') ? location.pathname : location.pathname + '/'; // Ensure the path matches the keys in suggestedLinks
|
||||
const {canonical, alternative} = suggestedLinks[pathname] || {};
|
||||
|
||||
return (
|
||||
<>
|
||||
<PageMetadata
|
||||
title={translate({
|
||||
id: 'theme.NotFound.title',
|
||||
message: 'Page Not Found',
|
||||
})}
|
||||
/>
|
||||
<Layout>
|
||||
<main className="container margin-vert--xl">
|
||||
<div className="row">
|
||||
<div className="col col--6 col--offset-3">
|
||||
<h1 className="hero__title">
|
||||
{canonical ? 'Page Moved' : alternative ? 'Page Removed' : 'Page Not Found'}
|
||||
</h1>
|
||||
{
|
||||
canonical ? (
|
||||
<h3>You can find the new location <a href={canonical}>here</a>.</h3>
|
||||
) : alternative ? (
|
||||
<p>The page you were looking for has been removed.</p>
|
||||
) : (
|
||||
<p>We could not find what you were looking for.</p>
|
||||
)
|
||||
}
|
||||
{alternative && (
|
||||
<p>
|
||||
<details>
|
||||
<summary>Alternative pages</summary>
|
||||
<ul>
|
||||
{alternative.map((alt, index) => (
|
||||
<li key={index}>
|
||||
<a href={alt}>{alt}</a>{alt.startsWith('/v0.1/') && <>{' '}<LegacyBadge/></>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
</p>
|
||||
)}
|
||||
<p>
|
||||
Please contact the owner of the site that linked you to the
|
||||
original URL and let them know their link {canonical ? 'has moved.' : alternative ? 'has been removed.' : 'is broken.'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</Layout>
|
||||
</>
|
||||
<main className={clsx('container margin-vert--xl', className)}>
|
||||
<div className="row">
|
||||
<div className="col col--6 col--offset-3">
|
||||
<h1 className="hero__title">
|
||||
{canonical ? 'Page Moved' : alternative ? 'Page Removed' : 'Page Not Found'}
|
||||
</h1>
|
||||
{
|
||||
canonical ? (
|
||||
<h3>You can find the new location <a href={canonical}>here</a>.</h3>
|
||||
) : alternative ? (
|
||||
<p>The page you were looking for has been removed.</p>
|
||||
) : (
|
||||
<p>We could not find what you were looking for.</p>
|
||||
)
|
||||
}
|
||||
{alternative && (
|
||||
<p>
|
||||
<details>
|
||||
<summary>Alternative pages</summary>
|
||||
<ul>
|
||||
{alternative.map((alt, index) => (
|
||||
<li key={index}>
|
||||
<a href={alt}>{alt}</a>{alt.startsWith('/v0.1/') && <>{' '}<LegacyBadge/></>}
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
</details>
|
||||
</p>
|
||||
)}
|
||||
<p>
|
||||
Please contact the owner of the site that linked you to the
|
||||
original URL and let them know their link {canonical ? 'has moved.' : alternative ? 'has been removed.' : 'is broken.'}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
);
|
||||
}
|
||||
|
25182
docs/yarn.lock
25182
docs/yarn.lock
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user