Skip to content

Commit 441160d

Browse files
authored
Docs: Update contributing documentation (langchain-ai#17557)
This PR adds more details about how to contribute to documentation.
1 parent b13e52b commit 441160d

File tree

1 file changed

+119
-11
lines changed

1 file changed

+119
-11
lines changed

docs/docs/contributing/documentation.mdx

Lines changed: 119 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,24 +3,68 @@ sidebar_position: 3
33
---
44
# Contribute Documentation
55

6-
The docs directory contains Documentation and API Reference.
6+
LangChain documentation consists of two components:
77

8-
Documentation is built using [Quarto](https://quarto.org) and [Docusaurus 2](https://docusaurus.io/).
8+
1. Main Documentation: Hosted at [python.langchain.com](https://python.langchain.com/),
9+
this comprehensive resource serves as the primary user-facing documentation.
10+
It covers a wide array of topics, including tutorials, use cases, integrations,
11+
and more, offering extensive guidance on building with LangChain.
12+
The content for this documentation lives in the `/docs` directory of the monorepo.
13+
2. In-code Documentation: This is documentation of the codebase itself, which is also
14+
used to generate the externally facing [API Reference](https://api.python.langchain.com/en/latest/langchain_api_reference.html).
15+
The content for the API reference is autogenerated by scanning the docstrings in the codebase. For this reason we ask that
16+
developers document their code well.
917

10-
API Reference are largely autogenerated by [sphinx](https://www.sphinx-doc.org/en/master/) from the code and are hosted by [Read the Docs](https://readthedocs.org/).
11-
For that reason, we ask that you add good documentation to all classes and methods.
18+
The main documentation is built using [Quarto](https://quarto.org) and [Docusaurus 2](https://docusaurus.io/).
1219

13-
Similar to linting, we recognize documentation can be annoying. If you do not want to do it, please contact a project maintainer, and they can help you with it. We do not want this to be a blocker for good code getting contributed.
20+
The `API Reference` is largely autogenerated by [sphinx](https://www.sphinx-doc.org/en/master/)
21+
from the code and is hosted by [Read the Docs](https://readthedocs.org/).
1422

15-
## Build Documentation Locally
23+
We appreciate all contributions to the documentation, whether it be fixing a typo,
24+
adding a new tutorial or example and whether it be in the main documentation or the API Reference.
25+
26+
Similar to linting, we recognize documentation can be annoying. If you do not want
27+
to do it, please contact a project maintainer, and they can help you with it. We do not want this to be a blocker for good code getting contributed.
28+
29+
## 📜 Main Documentation
30+
31+
The content for the main documentation is located in the `/docs` directory of the monorepo.
32+
33+
The documentation is written using a combination of ipython notebooks (`.ipynb` files)
34+
and markdown (`.mdx` files). The notebooks are converted to markdown
35+
using [Quarto](https://quarto.org) and then built using [Docusaurus 2](https://docusaurus.io/).
36+
37+
Feel free to make contributions to the main documentation! 🥰
38+
39+
After modifying the documentation:
40+
41+
1. Run the linting and formatting commands (see below) to ensure that the documentation is well-formatted and free of errors.
42+
2. Optionally build the documentation locally to verify that the changes look good.
43+
3. Make a pull request with the changes.
44+
4. You can preview and verify that the changes are what you wanted by clicking the `View deployment` or `Visit Preview` buttons on the pull request `Conversation` page. This will take you to a preview of the documentation changes.
45+
46+
## ⚒️ Linting and Building Documentation Locally
47+
48+
After writing up the documentation, you may want to lint and build the documentation
49+
locally to ensure that it looks good and is free of errors.
50+
51+
If you're unable to build it locally that's okay as well, as you will be able to
52+
see a preview of the documentation on the pull request page.
1653

1754
### Install dependencies
1855

19-
- [Quarto](https://quarto.org) - package that converts Jupyter notebooks (`.ipynb` files) into mdx files for serving in Docusaurus.
20-
- `poetry install --with lint,docs --no-root` from the monorepo root.
56+
- [Quarto](https://quarto.org) - package that converts Jupyter notebooks (`.ipynb` files) into mdx files for serving in Docusaurus. [Download link](https://quarto.org/docs/download/).
57+
58+
From the **monorepo root**, run the following command to install the dependencies:
59+
60+
```bash
61+
poetry install --with lint,docs --no-root
62+
````
2163

2264
### Building
2365

66+
The code that builds the documentation is located in the `/docs` directory of the monorepo.
67+
2468
In the following commands, the prefix `api_` indicates that those are operations for the API Reference.
2569

2670
Before building the documentation, it is always a good idea to clean the build directory:
@@ -46,7 +90,7 @@ make api_docs_linkcheck
4690

4791
### Linting and Formatting
4892

49-
The docs are linted from the monorepo root. To lint the docs, run the following from there:
93+
The Main Documentation is linted from the **monorepo root**. To lint the main documentation, run the following from there:
5094

5195
```bash
5296
make lint
@@ -56,9 +100,73 @@ If you have formatting-related errors, you can fix them automatically with:
56100

57101
```bash
58102
make format
59-
```
103+
```
104+
105+
## ⌨️ In-code Documentation
106+
107+
The in-code documentation is largely autogenerated by [sphinx](https://www.sphinx-doc.org/en/master/) from the code and is hosted by [Read the Docs](https://readthedocs.org/).
108+
109+
For the API reference to be useful, the codebase must be well-documented. This means that all functions, classes, and methods should have a docstring that explains what they do, what the arguments are, and what the return value is. This is a good practice in general, but it is especially important for LangChain because the API reference is the primary resource for developers to understand how to use the codebase.
110+
111+
We generally follow the [Google Python Style Guide](https://google.github.io/styleguide/pyguide.html#38-comments-and-docstrings) for docstrings.
112+
113+
Here is an example of a well-documented function:
114+
115+
```python
116+
117+
def my_function(arg1: int, arg2: str) -> float:
118+
"""This is a short description of the function. (It should be a single sentence.)
119+
120+
This is a longer description of the function. It should explain what
121+
the function does, what the arguments are, and what the return value is.
122+
It should wrap at 88 characters.
123+
124+
Examples:
125+
This is a section for examples of how to use the function.
126+
127+
.. code-block:: python
128+
129+
my_function(1, "hello")
130+
131+
Args:
132+
arg1: This is a description of arg1. We do not need to specify the type since
133+
it is already specified in the function signature.
134+
arg2: This is a description of arg2.
135+
136+
Returns:
137+
This is a description of the return value.
138+
"""
139+
return 3.14
140+
```
141+
142+
### Linting and Formatting
143+
144+
The in-code documentation is linted from the directories belonging to the packages
145+
being documented.
146+
147+
For example, if you're working on the `langchain-community` package, you would change
148+
the working directory to the `langchain-community` directory:
149+
150+
```bash
151+
cd [root]/libs/langchain-community
152+
```
153+
154+
Set up a virtual environment for the package if you haven't done so already.
155+
156+
Install the dependencies for the package.
157+
158+
```bash
159+
poetry install --with lint
160+
```
161+
162+
Then you can run the following commands to lint and format the in-code documentation:
163+
164+
```bash
165+
make format
166+
make lint
167+
```
60168

61-
## Verify Documentation changes
169+
## Verify Documentation Changes
62170

63171
After pushing documentation changes to the repository, you can preview and verify that the changes are
64172
what you wanted by clicking the `View deployment` or `Visit Preview` buttons on the pull request `Conversation` page.

0 commit comments

Comments
 (0)