Skip to content

Commit

Permalink
Fix docstring format of GoogleScholar (#138)
Browse files Browse the repository at this point in the history
* fix docstrings

* update pre-commit-hooks

* chores

---------

Co-authored-by: wangzy <[email protected]>
  • Loading branch information
braisedpork1964 and wangzy authored Feb 1, 2024
1 parent 990828c commit 60244a2
Show file tree
Hide file tree
Showing 12 changed files with 51 additions and 57 deletions.
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
5 changes: 2 additions & 3 deletions lagent/actions/bing_map.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: E501
import json
import os
from typing import Optional, Type
Expand Down Expand Up @@ -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.
Expand Down
40 changes: 16 additions & 24 deletions lagent/actions/google_scholar_search.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: E501
import os
from typing import Optional, Type

Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions lagent/actions/ipython_interactive.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 = (
Expand Down
8 changes: 2 additions & 6 deletions lagent/actions/ipython_interpreter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: E501
import base64
import io
import logging
Expand Down Expand Up @@ -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
Expand Down
3 changes: 1 addition & 2 deletions lagent/actions/ppt.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
21 changes: 16 additions & 5 deletions lagent/actions/python_interpreter.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
# flake8: noqa: E501
import copy
import io
from contextlib import redirect_stdout
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lagent/agents/__init__.py
Original file line number Diff line number Diff line change
@@ -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
2 changes: 1 addition & 1 deletion lagent/agents/internlm2_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 8 additions & 6 deletions lagent/llms/__init__.py
Original file line number Diff line number Diff line change
@@ -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'
]
4 changes: 2 additions & 2 deletions requirements/optional.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
lmdeploy
lmdeploy>=0.2.2
streamlit
torch
transformers
transformers>=4.34
1 change: 0 additions & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 60244a2

Please sign in to comment.