[Feat] Add docs content (#6)

* add readdoc config

* updata log

* update readthedoc
This commit is contained in:
liukuikun
2023-08-21 15:38:23 +08:00
committed by GitHub
parent 59cc0ab854
commit 3f3eab1872
29 changed files with 589 additions and 0 deletions

1
.gitignore vendored
View File

@@ -159,3 +159,4 @@ cython_debug/
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
#.idea/
.vscode/
docs/*/_build/

8
.readthedocs.yml Normal file
View File

@@ -0,0 +1,8 @@
version: 2
formats: all
python:
version: 3.7
install:
- requirements: requirements/docs.txt

20
docs/en/Makefile Normal file
View File

@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

View File

@@ -0,0 +1,6 @@
.header-logo {
background-image: url("../images/robot.png");
background-size: 40px 40px;
height: 40px;
width: 40px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -0,0 +1 @@
var collapsedSections = ['API Reference']

View File

@@ -0,0 +1,31 @@
$(document).ready(function () {
table = $('.model-summary').DataTable({
"stateSave": false,
"lengthChange": false,
"pageLength": 10,
"order": [],
"scrollX": true,
"columnDefs": [
{ "type": "summary", targets: '_all' },
]
});
// Override the default sorting for the summary columns, which
// never takes the "-" character into account.
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"summary-asc": function (str1, str2) {
if (str1 == "<p>-</p>")
return 1;
if (str2 == "<p>-</p>")
return -1;
return ((str1 < str2) ? -1 : ((str1 > str2) ? 1 : 0));
},
"summary-desc": function (str1, str2) {
if (str1 == "<p>-</p>")
return 1;
if (str2 == "<p>-</p>")
return -1;
return ((str1 < str2) ? 1 : ((str1 > str2) ? -1 : 0));
}
});
})

View File

@@ -0,0 +1,14 @@
.. role:: hidden
:class: hidden-section
.. currentmodule:: {{ module }}
{{ name | underline}}
.. autoclass:: {{ name }}
:members:
..
autogenerated from source/_templates/classtemplate.rst
note it does not have :inherited-members:

132
docs/en/conf.py Normal file
View File

@@ -0,0 +1,132 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
import os
import sys
import pytorch_sphinx_theme
sys.path.insert(0, os.path.abspath('../../'))
# -- Project information -----------------------------------------------------
project = 'Lagent'
copyright = '2020-2030, InternLM'
author = 'InternLM'
# The full version, including alpha/beta/rc tags
version_file = '../../lagent/version.py'
with open(version_file) as f:
exec(compile(f.read(), version_file, 'exec'))
__version__ = locals()['__version__']
release = __version__
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',
'sphinx_markdown_tables',
'sphinx_copybutton',
'myst_parser',
'sphinx.ext.intersphinx',
'sphinx.ext.autodoc.typehints',
'sphinx.ext.autosummary',
'sphinx.ext.autosectionlabel',
'sphinx_tabs.tabs',
]
autodoc_typehints = 'description'
autosummary_generate = True # Turn on sphinx.ext.autosummary
# Ignore >>> when copying code
copybutton_prompt_text = r'>>> |\.\.\. '
copybutton_prompt_is_regexp = True
myst_enable_extensions = ['colon_fence']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
source_suffix = {
'.rst': 'restructuredtext',
'.md': 'markdown',
}
# The master toctree document.
master_doc = 'index'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# html_theme = 'sphinx_rtd_theme'
html_theme = 'pytorch_sphinx_theme'
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
html_theme_options = {
'menu': [
{
'name': 'GitHub',
'url': 'https://github.com/InternLM/lagent'
},
],
# Specify the language of shared menu
'menu_lang': 'en'
}
language = 'en'
master_doc = 'index'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_css_files = [
'https://cdn.datatables.net/1.13.2/css/dataTables.bootstrap5.min.css',
'css/readthedocs.css'
]
html_js_files = [
'https://cdn.datatables.net/1.13.2/js/jquery.dataTables.min.js',
'https://cdn.datatables.net/1.13.2/js/dataTables.bootstrap5.min.js',
'js/collapsed.js',
'js/table.js',
]
myst_heading_anchors = 4
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'numpy': ('https://numpy.org/doc/stable', None),
'torch': ('https://pytorch.org/docs/stable/', None),
}
def builder_inited_handler(app):
pass
def setup(app):
app.connect('builder-inited', builder_inited_handler)

2
docs/en/docutils.conf Normal file
View File

@@ -0,0 +1,2 @@
[html writers]
table_style: colwidths-auto

23
docs/en/index.rst Normal file
View File

@@ -0,0 +1,23 @@
Welcome to Lagent's documentation!
=======================================
You can switch between English and Chinese in the lower-left corner of the layout.
.. toctree::
:maxdepth: 2
:caption: Get Started
get_started/overview.md
.. toctree::
:caption: Switch Language
switch_language.md
Indices and tables
==================
* :ref:`genindex`
* :ref:`search`

36
docs/en/make.bat Normal file
View File

@@ -0,0 +1,36 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

4
docs/en/requirements.txt Normal file
View File

@@ -0,0 +1,4 @@
recommonmark
sphinx
sphinx_markdown_tables
sphinx_rtd_theme

View File

@@ -0,0 +1,3 @@
## <a href='https://lagent.readthedocs.io/en/main/'>English</a>
## <a href='https://lagent.readthedocs.io/zh_CN/main/'>简体中文</a>

20
docs/zh_cn/Makefile Normal file
View File

@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#
# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build
# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
.PHONY: help Makefile
# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

View File

@@ -0,0 +1,6 @@
.header-logo {
background-image: url("../images/robot.png");
background-size: 40px 40px;
height: 40px;
width: 40px;
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB

View File

@@ -0,0 +1 @@
var collapsedSections = ['API 文档']

View File

@@ -0,0 +1,31 @@
$(document).ready(function () {
table = $('.model-summary').DataTable({
"stateSave": false,
"lengthChange": false,
"pageLength": 10,
"order": [],
"scrollX": true,
"columnDefs": [
{ "type": "summary", targets: '_all' },
]
});
// Override the default sorting for the summary columns, which
// never takes the "-" character into account.
jQuery.extend(jQuery.fn.dataTableExt.oSort, {
"summary-asc": function (str1, str2) {
if (str1 == "<p>-</p>")
return 1;
if (str2 == "<p>-</p>")
return -1;
return ((str1 < str2) ? -1 : ((str1 > str2) ? 1 : 0));
},
"summary-desc": function (str1, str2) {
if (str1 == "<p>-</p>")
return 1;
if (str2 == "<p>-</p>")
return -1;
return ((str1 < str2) ? 1 : ((str1 > str2) ? -1 : 0));
}
});
})

View File

@@ -0,0 +1,14 @@
.. role:: hidden
:class: hidden-section
.. currentmodule:: {{ module }}
{{ name | underline}}
.. autoclass:: {{ name }}
:members:
..
autogenerated from source/_templates/classtemplate.rst
note it does not have :inherited-members:

133
docs/zh_cn/conf.py Normal file
View File

@@ -0,0 +1,133 @@
# Configuration file for the Sphinx documentation builder.
#
# This file only contains a selection of the most common options. For a full
# list see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html
# -- Path setup --------------------------------------------------------------
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
import os
import subprocess
import sys
import pytorch_sphinx_theme
sys.path.insert(0, os.path.abspath('../../'))
# -- Project information -----------------------------------------------------
project = 'Lagent'
copyright = '2020-2030, InternLM'
author = 'InternLM'
# The full version, including alpha/beta/rc tags
version_file = '../../lagent/version.py'
with open(version_file) as f:
exec(compile(f.read(), version_file, 'exec'))
__version__ = locals()['__version__']
release = __version__
# -- General configuration ---------------------------------------------------
# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode',
'sphinx_markdown_tables',
'sphinx_copybutton',
'myst_parser',
'sphinx.ext.intersphinx',
'sphinx.ext.autodoc.typehints',
'sphinx.ext.autosummary',
'sphinx.ext.autosectionlabel',
'sphinx_tabs.tabs',
]
autodoc_typehints = 'description'
autosummary_generate = True # Turn on sphinx.ext.autosummary
# Ignore >>> when copying code
copybutton_prompt_text = r'>>> |\.\.\. '
copybutton_prompt_is_regexp = True
myst_enable_extensions = ['colon_fence']
# Add any paths that contain templates here, relative to this directory.
templates_path = ['_templates']
# The suffix(es) of source filenames.
# You can specify multiple suffix as a list of string:
#
source_suffix = {
'.rst': 'restructuredtext',
'.md': 'markdown',
}
# The master toctree document.
master_doc = 'index'
# List of patterns, relative to source directory, that match files and
# directories to ignore when looking for source files.
# This pattern also affects html_static_path and html_extra_path.
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
# -- Options for HTML output -------------------------------------------------
# The theme to use for HTML and HTML Help pages. See the documentation for
# a list of builtin themes.
#
# html_theme = 'sphinx_rtd_theme'
html_theme = 'pytorch_sphinx_theme'
html_theme_path = [pytorch_sphinx_theme.get_html_theme_path()]
html_theme_options = {
'menu': [
{
'name': 'GitHub',
'url': 'https://github.com/InternLM/lagent'
},
],
# Specify the language of shared menu
'menu_lang': 'cn',
}
language = 'zh_CN'
master_doc = 'index'
# Add any paths that contain custom static files (such as style sheets) here,
# relative to this directory. They are copied after the builtin static files,
# so a file named "default.css" will overwrite the builtin "default.css".
html_static_path = ['_static']
html_css_files = [
'https://cdn.datatables.net/1.13.2/css/dataTables.bootstrap5.min.css',
'css/readthedocs.css'
]
html_js_files = [
'https://cdn.datatables.net/1.13.2/js/jquery.dataTables.min.js',
'https://cdn.datatables.net/1.13.2/js/dataTables.bootstrap5.min.js',
'js/collapsed.js',
'js/table.js',
]
myst_heading_anchors = 4
# Configuration for intersphinx
intersphinx_mapping = {
'python': ('https://docs.python.org/3', None),
'numpy': ('https://numpy.org/doc/stable', None),
'torch': ('https://pytorch.org/docs/stable/', None),
}
def builder_inited_handler(app):
subprocess.run(['./cp_origin_docs.sh'])
def setup(app):
app.connect('builder-inited', builder_inited_handler)

9
docs/zh_cn/cp_origin_docs.sh Executable file
View File

@@ -0,0 +1,9 @@
#!/usr/bin/env bash
# Copy *.md files from docs/ if it doesn't have a Chinese translation
for filename in $(find ../en/ -name '*.md' -printf "%P\n");
do
mkdir -p $(dirname $filename)
cp -n ../en/$filename ./$filename
done

2
docs/zh_cn/docutils.conf Normal file
View File

@@ -0,0 +1,2 @@
[html writers]
table_style: colwidths-auto

View File

@@ -0,0 +1,23 @@
# OVERVIEW
This chapter introduces you to the framework of LAgent, and provides links to detailed tutorials about LAgent.
## What is LAgent
LAgent is an open source LLM agent framework, which enables people to efficiently turn a large language model to agent. It also provides some typical tools to enlighten the ablility of LLM, and the whole framework is shown below:
![image](https://github.com/InternLM/lagent/assets/24351120/e104171e-4baf-43b3-8e6d-90cff1b298b6)
LAgent consists of 3 main parts, agents, llms, and actions.
- **agents** provides agent implementation, such as ReAct, AutoGPT.
- **llms** supports various large language models, including open-sourced models (Llama-2, InterLM) through HuggingFace models or closed-source models like GPT3.5/4.
- **actions** contains a series of actions, as well as an action executor to manage all actions.
## How to Use
Here is a detailed step-by-step guide to learn more about LAgent:
1. For installation instructions, please see [get_started](get_started.md).
2. We provide several examples to build agents with LAgent in [examples](examples/) by simply run `python examples/react_example.py`.

21
docs/zh_cn/index.rst Normal file
View File

@@ -0,0 +1,21 @@
欢迎来到 Lagent 的中文文档!
=======================================
您可以在页面左下角切换中英文文档。
.. toctree::
:maxdepth: 2
:caption: 新手入门
get_started/overview.md
.. toctree::
:caption: 切换语言
switch_language.md
导引
==================
* :ref:`genindex`
* :ref:`search`

36
docs/zh_cn/make.bat Normal file
View File

@@ -0,0 +1,36 @@
@ECHO OFF
pushd %~dp0
REM Command file for Sphinx documentation
if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build
if "%1" == "" goto help
%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.http://sphinx-doc.org/
exit /b 1
)
%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end
:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
:end
popd

View File

@@ -0,0 +1,3 @@
## <a href='https://lagent.readthedocs.io/en/main/'>English</a>
## <a href='https://lagent.readthedocs.io/zh_CN/main/'>简体中文</a>

9
requirements/docs.txt Normal file
View File

@@ -0,0 +1,9 @@
docutils==0.16.0
markdown>=3.4.0
myst-parser
-e git+https://github.com/open-mmlab/pytorch_sphinx_theme.git#egg=pytorch_sphinx_theme
sphinx==4.0.2
sphinx-tabs
sphinx_copybutton
sphinx_markdown_tables>=0.0.16
tabulate