diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 329f2340..a7c3378f 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -38,11 +38,6 @@ repos: rev: v2.2.6 hooks: - id: codespell - - repo: https://github.com/myint/docformatter - rev: v1.7.5 - hooks: - - id: docformatter - args: ["--in-place", "--wrap-descriptions", "79"] - repo: https://github.com/asottile/pyupgrade rev: v3.15.0 hooks: diff --git a/lagent/actions/bing_map.py b/lagent/actions/bing_map.py index 076a7459..86daec77 100644 --- a/lagent/actions/bing_map.py +++ b/lagent/actions/bing_map.py @@ -1,3 +1,4 @@ +# flake8: noqa: E501 import json import os from typing import Optional, Type @@ -103,9 +104,7 @@ def search_nearby(self, latitude: float = 0.0, longitude: float = 0.0, radius: int = 5000) -> dict: - """Search for places nearby a location, within a given radius, and \ - return the results into a list. You can use either the places name or - the \\ latitude and longitude. + """Search for places nearby a location, within a given radius, and return the results into a list. You can use either the places name or the latitude and longitude. Args: search_term (:class:`str`): the place name. diff --git a/lagent/actions/google_scholar_search.py b/lagent/actions/google_scholar_search.py index 3251bb8b..10d61427 100644 --- a/lagent/actions/google_scholar_search.py +++ b/lagent/actions/google_scholar_search.py @@ -1,3 +1,4 @@ +# flake8: noqa: E501 import os from typing import Optional, Type @@ -52,8 +53,7 @@ def search_google_scholar( filter: Optional[str] = None, as_vis: Optional[str] = None, ) -> dict: - """Search for scholarly articles based on a query according to the - google scholar. + """Search for scholarly articles based on a query according to the google scholar. Args: query (str): The query to search for. @@ -133,8 +133,7 @@ def get_author_information(self, no_cache: Optional[bool] = None, async_req: Optional[bool] = None, output: Optional[str] = None) -> dict: - """Search for an author's information by author's id provided by - get_author_id. + """Search for an author's information by author's id provided by get_author_id. Args: author_id (str): Required. The ID of an author. @@ -192,8 +191,7 @@ def get_citation_format(self, no_cache: Optional[bool] = None, async_: Optional[bool] = None, output: Optional[str] = 'json') -> dict: - """Function to get MLA citation format by an identification of - organic_result's id provided by search_google_scholar. + """Function to get MLA citation format by an identification of organic_result's id provided by search_google_scholar. Args: q (str): ID of an individual Google Scholar organic search result. @@ -233,26 +231,20 @@ def get_author_id(self, no_cache: Optional[bool] = False, _async: Optional[bool] = False, output: Optional[str] = 'json') -> dict: - """The getAuthorId function is used to get the author's id by his or - her name. + """The getAuthorId function is used to get the author's id by his or her name. - Args: - mauthors (str): Defines the author you want to search for. - hl (Optional[str]): Defines the language to use for the Google Scholar Profiles search. It's a two-letter \ - language code. (e.g., 'en' for English, 'es' for Spanish, or 'fr' for French). Defaults to 'en'. - after_author (Optional[str]): Defines the next page token. It is used for retrieving the next page \ - results. The parameter has the precedence over before_author parameter. Defaults to None. - before_author (Optional[str]): Defines the previous page token. It is used for retrieving the previous \ - page results. Defaults to None. - no_cache (Optional[bool]): Will force SerpApi to fetch the Google Scholar Profiles results even if a \ - cached version is already present. Defaults to False. - _async (Optional[bool]): Defines the way you want to submit your search to SerpApi. Defaults to False. - output (Optional[str]): Defines the final output you want. It can be set to 'json' (default) to get a \ - structured JSON of the results, or 'html' to get the raw html retrieved. Defaults to 'json'. + Args: + mauthors (str): Defines the author you want to search for. + hl (Optional[str]): Defines the language to use for the Google Scholar Profiles search. It's a two-letter language code. (e.g., 'en' for English, 'es' for Spanish, or 'fr' for French). Defaults to 'en'. + after_author (Optional[str]): Defines the next page token. It is used for retrieving the next page results. The parameter has the precedence over before_author parameter. Defaults to None. + before_author (Optional[str]): Defines the previous page token. It is used for retrieving the previous page results. Defaults to None. + no_cache (Optional[bool]): Will force SerpApi to fetch the Google Scholar Profiles results even if a cached version is already present. Defaults to False. + _async (Optional[bool]): Defines the way you want to submit your search to SerpApi. Defaults to False. + output (Optional[str]): Defines the final output you want. It can be set to 'json' (default) to get a structured JSON of the results, or 'html' to get the raw html retrieved. Defaults to 'json'. - Returns: - :class:`dict`: author id - * author_id: the author_id of the author + Returns: + :class:`dict`: author id + * author_id: the author_id of the author """ params = { 'mauthors': mauthors, diff --git a/lagent/actions/ipython_interactive.py b/lagent/actions/ipython_interactive.py index 20594210..8da7aace 100644 --- a/lagent/actions/ipython_interactive.py +++ b/lagent/actions/ipython_interactive.py @@ -71,8 +71,8 @@ def run(self, command: str, timeout: Optional[int] = None) -> ActionReturn: Args: command (:class:`str`): Python code snippet - timeout (:class:`Optional[int]`): timeout for execution. This - argument only works in the main thread. Defaults to ``None``. + timeout (:class:`Optional[int]`): timeout for execution. + This argument only works in the main thread. Defaults to ``None``. """ tool_return = ActionReturn(args={'text': command}, type=self.name) ret = ( diff --git a/lagent/actions/ipython_interpreter.py b/lagent/actions/ipython_interpreter.py index 1dc9a6c0..491f8c52 100644 --- a/lagent/actions/ipython_interpreter.py +++ b/lagent/actions/ipython_interpreter.py @@ -1,3 +1,4 @@ +# flake8: noqa: E501 import base64 import io import logging @@ -207,12 +208,7 @@ def handler(signum, frame): @tool_api def run(self, command: str, timeout: Optional[int] = None) -> ActionReturn: - r"""When you send a message containing Python code to python, it will be - \ executed in a stateful Jupyter notebook environment. python will - respond with \ the output of the execution or time out after 60.0 - seconds. The drive at '/mnt/data' \ can be used to save and persist - user files. Internet access for this session is \ disabled. Do not make - external web requests or API calls as they will fail. + r"""When you send a message containing Python code to python, it will be executed in a stateful Jupyter notebook environment. python will respond with the output of the execution or time out after 60.0 seconds. The drive at '/mnt/data' can be used to save and persist user files. Internet access for this session is disabled. Do not make external web requests or API calls as they will fail. Args: command (:class:`str`): Python code diff --git a/lagent/actions/ppt.py b/lagent/actions/ppt.py index 643e70dd..1a2dd07f 100644 --- a/lagent/actions/ppt.py +++ b/lagent/actions/ppt.py @@ -16,8 +16,7 @@ class PPT(BaseAction): - """Plugin to create ppt slides with text, paragraph, images in good looking - styles.""" + """Plugin to create ppt slides with text, paragraph, images in good looking styles.""" def __init__(self, theme_mapping: Optional[Dict[str, dict]] = None, diff --git a/lagent/actions/python_interpreter.py b/lagent/actions/python_interpreter.py index 4b2daca0..daeccc3d 100644 --- a/lagent/actions/python_interpreter.py +++ b/lagent/actions/python_interpreter.py @@ -1,3 +1,4 @@ +# flake8: noqa: E501 import copy import io from contextlib import redirect_stdout @@ -65,11 +66,21 @@ def __init__(self, @tool_api def run(self, command: str) -> ActionReturn: """用来执行Python代码。代码必须是一个函数,函数名必须得是 'solution',代码对应你的思考过程。代码实例格式如下: - ```python # import 依赖包 import xxx def solution(): # 初始化一些变量 - variable_names_with_real_meaning = xxx # 步骤一 mid_variable = - func(variable_names_with_real_meaning) # 步骤 x mid_variable = - func(mid_variable) # 最后结果 final_answer = func(mid_variable) return - final_answer ``` + + ```python + # import 依赖包 + import xxx + def solution(): + # 初始化一些变量 + variable_names_with_real_meaning = xxx + # 步骤一 + mid_variable = func(variable_names_with_real_meaning) + # 步骤 x + mid_variable = func(mid_variable) + # 最后结果 + final_answer = func(mid_variable) + return final_answer + ``` Args: command (:class:`str`): Python code snippet diff --git a/lagent/agents/__init__.py b/lagent/agents/__init__.py index ddac33b5..1a6f756f 100644 --- a/lagent/agents/__init__.py +++ b/lagent/agents/__init__.py @@ -1,4 +1,5 @@ from .autogpt import * # noqa: F401, F403 from .base_agent import * # noqa: F401, F403 +from .internlm2_agent import * # noqa: F401, F403 from .react import * # noqa: F401, F403 from .rewoo import * # noqa: F401, F403 diff --git a/lagent/agents/internlm2_agent.py b/lagent/agents/internlm2_agent.py index a49a0895..c74c6fec 100644 --- a/lagent/agents/internlm2_agent.py +++ b/lagent/agents/internlm2_agent.py @@ -3,8 +3,8 @@ from copy import deepcopy from typing import Dict, List, Optional, Union -from lagent import BaseAgent from lagent.actions import ActionExecutor +from lagent.agents.base_agent import BaseAgent from lagent.llms import BaseAPIModel, BaseModel from lagent.schema import ActionReturn, ActionStatusCode, AgentReturn, AgentStatusCode, ModelStatusCode # noqa: E501 diff --git a/lagent/llms/__init__.py b/lagent/llms/__init__.py index 202910c0..7d94eddd 100644 --- a/lagent/llms/__init__.py +++ b/lagent/llms/__init__.py @@ -1,10 +1,12 @@ -from lagent.utils import is_module_exist from .base_api import BaseAPIModel from .base_llm import BaseModel +from .huggingface import HFTransformer, HFTransformerCasualLM +from .lmdepoly_wrapper import LMDeployClient, LMDeployPipeline, LMDeployServer +from .meta_template import INTERNLM2_META from .openai import GPTAPI -__all__ = ['BaseModel', 'BaseAPIModel', 'GPTAPI'] - -if is_module_exist('transformers'): - from .huggingface import HFTransformer, HFTransformerCasualLM # noqa: F401 - __all__.extend(['HFTransformer', 'HFTransformerCasualLM']) +__all__ = [ + 'BaseModel', 'BaseAPIModel', 'GPTAPI', 'LMDeployClient', + 'LMDeployPipeline', 'LMDeployServer', 'HFTransformer', + 'HFTransformerCasualLM', 'INTERNLM2_META' +] diff --git a/requirements/optional.txt b/requirements/optional.txt index 2a8e41b4..12c52ac3 100644 --- a/requirements/optional.txt +++ b/requirements/optional.txt @@ -1,4 +1,4 @@ -lmdeploy +lmdeploy>=0.2.2 streamlit torch -transformers +transformers>=4.34 diff --git a/setup.cfg b/setup.cfg index a63fdc59..e40a95da 100644 --- a/setup.cfg +++ b/setup.cfg @@ -21,5 +21,4 @@ quiet-level = 3 ignore-words-list = patten,nd,ty,mot,hist,formating,winn,gool,datas,wan,confids,TOOD,tood,ba,warmup,nam,DOTA,dota,conveyer,astroid [flake8] -per-file-ignores = ftdp/configs/*: F401,F403,F405 max-line-length = 200