Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Refactor Lagent #97

Merged
merged 24 commits into from
Jan 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
06bedec
Merge pull request #1 from InternLM/main
Harold-lkk Sep 22, 2023
b49397a
Merge branch 'main' of github.com:Harold-lkk/lagent into main
Harold-lkk Dec 5, 2023
93162b2
Merge branch 'main' of https://github.com/InternLM/lagent into main
Harold-lkk Dec 5, 2023
740c3f9
Merge branch 'main' of https://github.com/InternLM/lagent into main
Harold-lkk Jan 25, 2024
e46e59c
Feature: redesign BaseModel (#80)
liujiangning30 Jan 18, 2024
30f77da
[Refactor] improve `Action` and `ActionExecutor` (#83)
braisedpork1964 Jan 19, 2024
c42c884
[Feature] add tools (#89)
braisedpork1964 Jan 22, 2024
fdaacb8
rename func 'completion' to 'generate' (#90)
liujiangning30 Jan 22, 2024
adefd97
[Feature] support batch inference in API models (#91)
braisedpork1964 Jan 23, 2024
73de598
Feature: lmdeploy_wrapper implemented BaseMode (#86)
liujiangning30 Jan 23, 2024
54e5b61
Fix APITemplateParser object is not callable (#95)
braisedpork1964 Jan 24, 2024
a53bad2
[Feat] support StreamAgent (#82)
Harold-lkk Jan 24, 2024
bdd6a9b
[Feat] hf llm implemented BaseMode (#92)
liujiangning30 Jan 25, 2024
799c6a3
[Feature] support building tool descriptions automatically (#96)
braisedpork1964 Jan 25, 2024
1b5fd99
Enhance tool annotation (#98)
braisedpork1964 Jan 25, 2024
016ee62
[Docs] initialize the documentation (#99)
braisedpork1964 Jan 25, 2024
1292ea7
Modify the structure of `ActionReturn`'s result (#102)
braisedpork1964 Jan 25, 2024
4879194
Fix .readthedocs.yml (#104)
braisedpork1964 Jan 26, 2024
85853da
[Feature] support IPython interpreter action (#103)
braisedpork1964 Jan 26, 2024
a2a0d91
Fix BINGMap key (#105)
braisedpork1964 Jan 26, 2024
183ef77
StreamAgent infer demo (#106)
Harold-lkk Jan 29, 2024
39e00f2
[Docs] Add action tutorials (#107)
braisedpork1964 Jan 29, 2024
b5533b0
Fix returns of OpenAI interface (#108)
braisedpork1964 Jan 29, 2024
1eb10a3
Feat: add warn for func 'generate_from_template' (#109)
liujiangning30 Jan 30, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions .readthedocs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@ version: 2

formats: all

build:
os: ubuntu-22.04
tools:
python: "3.10"

python:
version: 3.7
install:
- requirements: requirements/docs.txt
install:
- requirements: requirements/docs.txt
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Below is an example of running ReWOO with GPT-3.5
```python
# Import necessary modules and classes from the "lagent" library.
from lagent.agents import ReWOO
from lagent.actions import ActionExecutor, GoogleSearch, LLMQA
from lagent.actions import ActionExecutor, GoogleSearch
from lagent.llms import GPTAPI

# Initialize the Language Model (llm) and provide your API key.
Expand All @@ -92,14 +92,11 @@ llm = GPTAPI(model_type='gpt-3.5-turbo', key=['Your OPENAI_API_KEY'])
# Initialize the Google Search tool and provide your API key.
search_tool = GoogleSearch(api_key='Your SERPER_API_KEY')

# Initialize the LLMQA tool using the Language Model (llm).
llmqa_tool = LLMQA(llm)

# Create a chatbot by configuring the ReWOO agent.
chatbot = ReWOO(
llm=llm, # Provide the Language Model instance.
action_executor=ActionExecutor(
actions=[search_tool, llmqa_tool] # Specify the actions the chatbot can perform.
actions=[search_tool] # Specify the actions the chatbot can perform.
),
)

Expand Down Expand Up @@ -154,6 +151,7 @@ response = chatbot.chat(
print(response.response) # Output the response generated by the chatbot.
>>> $-\\frac{1}{3}+\\frac{{\\sqrt{3}}}{3}i$
```

### All Thanks To Our Contributors:
<a href="https://github.com/InternLM/lagent/graphs/contributors">
<img src="https://contrib.rocks/image?repo=InternLM/lagent" />
Expand Down
14 changes: 14 additions & 0 deletions docs/en/_templates/autoapi/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
API Reference
=============

This page contains auto-generated API reference documentation.

.. toctree::
:titlesonly:
:maxdepth: 3

{% for page in pages %}
{% if page.top_level_object and page.display %}
{{ page.include_path }}
{% endif %}
{% endfor %}
112 changes: 112 additions & 0 deletions docs/en/_templates/autoapi/python/module.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
{% if not obj.display %}
:orphan:

{% endif %}
:py:mod:`{{ obj.name if obj.name.count(".") <= 1 else obj.short_name }}`
=========={{ "=" * (obj.name|length if obj.name.count(".") <= 1 else obj.short_name|length) }}

.. py:module:: {{ obj.name }}

{% if obj.docstring %}
.. autoapi-nested-parse::

{{ obj.docstring|indent(3) }}

{% endif %}

{% block subpackages %}
{% set visible_subpackages = obj.subpackages|selectattr("display")|list %}
{% if visible_subpackages %}
Subpackages
-----------
.. toctree::
:titlesonly:
:maxdepth: 3

{% for subpackage in visible_subpackages %}
{{ subpackage.short_name }}/index.rst
{% endfor %}


{% endif %}
{% endblock %}
{% block submodules %}
{% set visible_submodules = obj.submodules|selectattr("display")|list %}
{% if visible_submodules %}
Submodules
----------
.. toctree::
:titlesonly:
:maxdepth: 1

{% for submodule in visible_submodules %}
{{ submodule.short_name }}/index.rst
{% endfor %}


{% endif %}
{% endblock %}
{% block content %}
{% if obj.type is equalto("package") %}
{% set visible_children = obj.children|selectattr("display")|list %}
{% else %}
{% set visible_children = obj.children|selectattr("display")|rejectattr("imported")|list %}
{% endif %}
{% if visible_children %}
{{ obj.type|title }} Contents
{{ "-" * obj.type|length }}---------

{% set visible_classes = visible_children|selectattr("type", "equalto", "class")|list %}
{% set visible_functions = visible_children|selectattr("type", "equalto", "function")|list %}
{% set visible_attributes = visible_children|selectattr("type", "equalto", "data")|list %}
{% if "show-module-summary" in autoapi_options and (visible_classes or visible_functions) %}
{% block classes scoped %}
{% if visible_classes %}
Classes
~~~~~~~

.. autoapisummary::

{% for klass in visible_classes %}
{{ klass.id }}
{% endfor %}


{% endif %}
{% endblock %}

{% block functions scoped %}
{% if visible_functions %}
Functions
~~~~~~~~~

.. autoapisummary::

{% for function in visible_functions %}
{{ function.id }}
{% endfor %}


{% endif %}
{% endblock %}

{% block attributes scoped %}
{% if visible_attributes %}
Attributes
~~~~~~~~~~

.. autoapisummary::

{% for attribute in visible_attributes %}
{{ attribute.id }}
{% endfor %}


{% endif %}
{% endblock %}
{% endif %}
{% for obj_item in visible_children %}
{{ obj_item.render()|indent(0) }}
{% endfor %}
{% endif %}
{% endblock %}
110 changes: 43 additions & 67 deletions docs/en/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,16 @@
# documentation root, use os.path.abspath to make it absolute, like shown here.

import os
import re
import sys

import pytorch_sphinx_theme

sys.path.insert(0, os.path.abspath('../../'))
sys.path.insert(0, os.path.abspath('../..'))

# -- Project information -----------------------------------------------------

project = 'Lagent'
copyright = '2020-2030, InternLM'
author = 'InternLM'
language = 'en'

# The full version, including alpha/beta/rc tags
version_file = '../../lagent/version.py'
Expand All @@ -36,97 +35,74 @@
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
'sphinx_rtd_theme',
'myst_nb',
'autoapi.extension',
'sphinx_markdown_tables',
'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
nb_output_stderr = 'remove-warn'
autodoc_typehints = 'description'

myst_enable_extensions = ['colon_fence']
# sphinx-autoapi configuration
autoapi_dirs = ['../../lagent']
autoapi_options = [
'members',
'undoc-members',
'show-inheritance',
'show-module-summary',
]
autoapi_ignore = ['*migrations*', '*command.py', '*cli.py']
autoapi_template_dir = '_templates/autoapi'
autoapi_add_toctree_entry = False

# 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']
exclude_patterns = []

# -- 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 = 'sphinx_rtd_theme'
html_theme_options = {
'menu': [
{
'name': 'GitHub',
'url': 'https://github.com/InternLM/lagent'
},
],
# Specify the language of shared menu
'menu_lang': 'en'
'navigation_depth': 3,
'titles_only': False,
'style_nav_header_background': '#4fabab',
}

language = 'en'
html_context = {
'display_github': True,
'github_host': 'github.com',
'github_user': 'InternLM',
'github_repo': 'lagent',
'github_version': 'main',
'conf_py_path': '/docs/en/',
}
html_title = 'Lagent'
html_logo = '../imgs/lagent_logo.png'
html_favicon = '../imgs/lagent_icon.png'

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".
# 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 custom_skip(app, what, name, obj, skip, options):
if what in ['data', 'function', 'class'] and re.search('logger', name):
skip = True
return skip


def setup(app):
app.connect('builder-inited', builder_inited_handler)
def setup(sphinx):
sphinx.connect('autoapi-skip-member', custom_skip)
19 changes: 19 additions & 0 deletions docs/en/get_started/install.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Installation

## With pip

Install with pip (Recommended).

```bash
pip install lagent
```

## From source

Optionally, you could also build Lagent from source in case you want to modify the code:

```bash
git clone https://github.com/InternLM/lagent.git
cd lagent
pip install -e .
```
6 changes: 3 additions & 3 deletions docs/en/get_started/overview.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# OVERVIEW
# Overview

This chapter introduces you to the framework of Lagent, and provides links to detailed tutorials about Lagent.

Expand All @@ -18,6 +18,6 @@ Lagent consists of 3 main parts, agents, llms, and actions.

Here is a detailed step-by-step guide to learn more about Lagent:

1. For installation instructions, please see [README](../README.md).
1. For installation instructions, please see [README](https://github.com/InternLM/lagent/blob/main/README.md).

2. We provide several examples to build agents with Lagent in [examples](examples/) by simply run `python examples/react_example.py`.
2. We provide several examples to build agents with Lagent in [examples](https://github.com/InternLM/lagent/tree/main/examples) by simply run `python examples/react_example.py`.
Loading