Skip to content

Commit

Permalink
fix docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
pan-x-c committed Oct 29, 2024
1 parent 282244e commit f995ec9
Show file tree
Hide file tree
Showing 11 changed files with 45 additions and 23 deletions.
2 changes: 1 addition & 1 deletion docs/sphinx_doc/zh_CN/source/tutorial/208-distribute.md
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ Client 主要包含 `RpcMeta`、`RpcObject` 两个主要类,其中 `RpcMeta`

#### `async_func``AsyncResult`

{func}`async_func<agentscope.rpc.async_func>` 装饰器的实现位于 `src/agentscope/rpc/rpc_meta.py``AgentBase` 及其所有子类的 `__call__` 以及 `reply` 方法都被标记为了 `async_func` 以避免阻塞。
{func}`async_func<agentscope.rpc.async_func>` 装饰器的实现位于 `src/agentscope/rpc/rpc_meta.py``AgentBase` 及其所有子类的 `__call__` 以及 `reply` 方法都被标记为了 `async_func` 以避免阻塞。

`async_func` 相对的还有 {func}`sync_func<agentscope.rpc.sync_func>` 装饰器,用于标识同步方法。但由于同步方法为默认情况,因此一般不使用。

Expand Down
2 changes: 1 addition & 1 deletion examples/environments/chatroom/chatroom_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def main(args: argparse.Namespace) -> None:
"model_type": "dashscope_chat",
"config_name": "dash",
"model_name": "qwen-turbo",
"api_key": os.environ.get("DASH_API_KEY", ""),
"api_key": os.environ.get("DASHSCOPE_API_KEY", ""),
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def main(args: argparse.Namespace) -> None:
"model_type": "dashscope_chat",
"config_name": "dash",
"model_name": "qwen-turbo",
"api_key": os.environ.get("DASH_API_KEY", ""),
"api_key": os.environ.get("DASHSCOPE_API_KEY", ""),
},
]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
"model_type": "dashscope_chat",
"config_name": MODEL_CONFIG_NAME,
"model_name": "qwen-max",
"api_key": os.environ.get("DASH_API_KEY", ""),
"api_key": os.environ.get("DASHSCOPE_API_KEY", ""),
}

BEGIN_TAG = "[PERSONA BEGIN]"
Expand Down
2 changes: 1 addition & 1 deletion examples/parallel_service/parallel_service.py
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ def main() -> None:
"model_type": "dashscope_chat",
"config_name": "dash",
"model_name": "qwen-turbo",
"api_key": os.environ.get("DASH_API_KEY", ""),
"api_key": os.environ.get("DASHSCOPE_API_KEY", ""),
},
]

Expand Down
2 changes: 1 addition & 1 deletion src/agentscope/agents/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ def __init__(
Whether the agent has memory.
to_dist (`Optional[Union[DistConf, bool]]`, default to `False`):
The configurations passed to :py:meth:`to_dist` method. Used in
:py:class:`_AgentMeta`, when this parameter is provided,
:py:class:`RpcMeta`, when this parameter is provided,
the agent will automatically be converted into its distributed
version. Below are some examples:
Expand Down
32 changes: 27 additions & 5 deletions src/agentscope/environment/env.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,15 @@ def trigger_listener(env: "Env", event: Event) -> None:


def event_func(func: Callable) -> Callable:
"""A decorator to register an event function.
"""A decorator to register an event function in `Env` and its
subclasses.
Note:
This decorator is only available in the subclasses of `Env`.
If a function is decorated with `@event_func`, at the end of
the function, all listeners bound to the function will be
triggered automatically.
Args:
func (`Callable`): The event function.
Expand Down Expand Up @@ -65,8 +73,22 @@ def wrapper( # type: ignore[no-untyped-def]


class EventListener(ABC):
"""A class representing a listener for listening the event of an
env."""
"""A base class representing a listener for listening the event of an
environment. The actions of the listener should be implemented in the
`__call__` method.
Args:
env (`Env`): The environment instance who trigger the listener.
event (`Event`): The event information, which contains the event
function name (`name`: `str`), the arguments of the event function
(`args`: `dict`), and the return value of the event function
(`returns`: `Any`).
Note:
`EventListener` can only be bound to event functions (decorated
with `@event_func`).
"""

def __init__(self, name: str) -> None:
"""Init a EventListener instance.
Expand Down Expand Up @@ -128,8 +150,7 @@ def add_child(self, child: Env) -> bool:
"""Add a child env to the current env.
Args:
child (`Env`): The children
envs.
child (`Env`): The children envs.
Returns:
`bool`: Whether the children were added successfully.
Expand Down Expand Up @@ -200,6 +221,7 @@ class BasicEnv(Env):
and cannot get value.
Note:
`BasicEnv` is used as the base class to implement other
envs. Application developers should not use this class.
"""
Expand Down
6 changes: 4 additions & 2 deletions src/agentscope/rpc/retry_strategy.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,12 @@ def retry( # pylint: disable=R1710
)
file_name = frame_info.filename
line_number = frame_info.lineno
logger.info(
logger.debug(
f"Attempt {attempt + 1} at [{file_name}:{line_number}] failed:"
f"\n{e}.\nRetrying in {random_delay:.2f} seconds...",
)
time.sleep(random_delay)
logger.error(f"Max timeout exceeded at [{file_name}:{line_number}].")
raise TimeoutError("Max retry exceeded.")


Expand Down Expand Up @@ -157,12 +158,13 @@ def retry( # pylint: disable=R1710
)
file_name = frame_info.filename
line_number = frame_info.lineno
logger.info(
logger.debug(
f"Attempt {attempt + 1} at [{file_name}:{line_number}] failed:"
f"\n{e}.\nRetrying in {random_delay:.2f} seconds...",
)
time.sleep(random_delay)
delay *= 2
logger.error(f"Max timeout exceeded at [{file_name}:{line_number}].")
raise TimeoutError("Max retry exceeded.")


Expand Down
6 changes: 3 additions & 3 deletions src/agentscope/rpc/rpc_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ def create_agent(
Args:
agent_configs (`dict`): Init configs of the agent, generated by
`_AgentMeta`.
`RpcMeta`.
agent_id (`str`): agent_id of the created agent.
Returns:
Expand Down Expand Up @@ -315,8 +315,8 @@ def download_file(self, path: str) -> str:
"""Download a file from a remote server to the local machine.
Args:
path (`str`): The path of the file to be downloaded. Note that
it is the path on the remote server.
path (`str`): The path of the file to be downloaded. Note that
it is the path on the remote server.
Returns:
`str`: The path of the downloaded file. Note that it is the path
Expand Down
2 changes: 0 additions & 2 deletions src/agentscope/server/__init__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
# -*- coding: utf-8 -*-
"""Import all server related modules in the package."""
from .launcher import RpcAgentServerLauncher, as_server
from .servicer import AgentServerServicer

__all__ = [
"RpcAgentServerLauncher",
"AgentServerServicer",
"as_server",
]
10 changes: 5 additions & 5 deletions src/agentscope/server/launcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,8 @@ def __init__(
message pool, which can be `local` or `redis`. If `redis` is
specified, you need to start a redis server before launching
the server.
redis-url (`str`, defaults to `"redis://localhost:6379"`): The
address of the redis server.
redis-url (`str`): The address of the redis server.
Defaults to `redis://localhost:6379`.
max_pool_size (`int`, defaults to `8192`):
The max number of async results that the server can
accommodate. Note that the oldest result will be deleted
Expand Down Expand Up @@ -547,9 +547,9 @@ def as_server() -> None:
.. code-block:: shell
as_server start --host localhost \
--port 12345 \
--model-config-path config.json \
as_server start --host localhost \\
--port 12345 \\
--model-config-path config.json \\
--agent-dir ./my_agents
"""
parser = argparse.ArgumentParser()
Expand Down

0 comments on commit f995ec9

Please sign in to comment.