camel
camel copied to clipboard
[Feature Request] Unify format of the docstring for all code
Required prerequisites
- [X] I have searched the Issue Tracker and Discussions that this hasn't already been reported. (+1 or comment there if it has.)
- [ ] Consider asking first in a Discussion.
Motivation
Currently there's some code doesn't follow the docstring standard, we need to review and polish
Solution
Guideline for Writing Docstrings:
This guideline will help you write clear, concise, and structured docstrings for contributing to CAMEL
.
-
Use the Triple-Quoted String with
r"""
(raw string) Begin the docstring withr"""
to indicate a raw docstring. This prevents any issues with special characters and ensures consistent formatting, especially in documentation tools like Sphinx. -
Provide a Brief Class or Method Description Start with a concise summary of the purpose and functionality, keeping each line under
79
characters. The summary should start from the first line without a linebreak:
r"""Class for managing conversations of CAMEL Chat Agents.
"""
- Document the Args Section
Use the
Args
: section to document the constructor parameters, maintaining the79
-character limit for each line. Break long descriptions into multiple lines if necessary, indenting continuation lines by4
spaces. For each parameter, follow this structure:
Parameter name: The name of the parameter as it appears in the function signature.
Type
: The type of the parameter (e.g., int
, str
, custom types like BaseModelBackend
). If a parameter is optional, use the suffix , optional
.
Description: A brief explanation of the parameter’s purpose.
Default value: If applicable, include the default value using the format (default: :obj:<default_value>)
. Use :obj:
to denote Python objects.
4. Explain Optional Parameters Clearly
For optional parameters, describe how the class behaves when the parameter is not provided. Keep each line under 79
characters, breaking longer descriptions into multiple lines.
-
Use
reST
Formatting for Links When referring to objects, types, or classes (e.g.,BaseMessage
), usereST
roles like:obj:
for proper formatting and linking. Ensure that lines do not exceed79
characters. -
Provide Default Values Consistently For parameters with default values, include them in parentheses at the end of the description. Keep the
(default: :obj:<default_value>)
format consistent throughout. Wrap long descriptions to avoid exceeding79
characters. -
Limit Line Length to
79
Characters Ensure that all lines are limited to79
characters for readability. Break long sentences or descriptions into multiple lines, and indent continuation lines by 4 spaces. This improves readability in text editors and follows Python's PEP 8 and PEP 257 guidelines. -
Class Docstring of the Constructor (
__init__
) To improve code hinting in editors like Visual Studio Code, include the constructor's docstring directly under the class definition. This ensures that code editors can display detailed hints.
class MyClass:
r"""Class for managing conversations of CAMEL Chat Agents.
Args:
system_message (BaseMessage): The system message for the chat
agent, used to initialize the conversation and provide context.
model (BaseModelBackend, optional): The model backend to use for
generating responses. If not provided, defaults to
:obj:`OpenAIModel` with `GPT_4O_MINI`.
(default: :obj:`OpenAIModel` with `GPT_4O_MINI`)
memory (AgentMemory, optional): The agent's memory for managing chat
messages. If `None`, a default :obj:`ChatHistoryMemory` will
be used. (default: :obj:`None`)
message_window_size (int, optional): The maximum number of previous
messages to include in the context window. If `None`, no
windowing is applied. (default: :obj:`None`)
token_limit (int, optional): The maximum number of tokens allowed
in the context before pruning occurs. If `None`, the token
limit is automatically set by the backend model.
(default: :obj:`None`)
output_language (str, optional): The language used for the agent's
output. If not specified, defaults to the system's language
setting. (default: :obj:`None`)
tools (List[OpenAIFunction], optional): A list of available
:obj:`OpenAIFunction` instances for the agent. If not provided,
no tools are available. (default: :obj:`None`)
response_terminators (List[ResponseTerminator], optional): A list of
:obj:`ResponseTerminator` instances that control when the agent
terminates its response. (default: :obj:`None`)
"""
def __init__(self, system_message, model=None, memory=None,
message_window_size=None, token_limit=None,
output_language=None, tools=None, response_terminators=None):
pass
Alternatives
No response
Additional context
No response