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

增加部分中文注释,修改剩下的部分英文输出为中文 #17

Merged
merged 1 commit into from
Apr 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
27 changes: 12 additions & 15 deletions autogpt/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,12 @@ class Agent:
"""Agent class for interacting with Auto-GPT.

Attributes:
ai_name: The name of the agent.
memory: The memory object to use.
full_message_history: The full message history.
next_action_count: The number of actions to execute.
system_prompt: The system prompt is the initial prompt that defines everything the AI needs to know to achieve its task successfully.
Currently, the dynamic and customizable information in the system prompt are ai_name, description and goals.

triggering_prompt: The last sentence the AI will see before answering. For Auto-GPT, this prompt is:
Determine which next command to use, and respond using the format specified above:
ai_name: 代理的名称
memory: 要使用的内存对象
full_message_history: 完整的消息历史记录
next_action_count: 要执行的操作数
system_prompt: 系统提示是初始提示,定义了AI需要了解的所有内容以成功完成任务。系统提示中的动态和可自定义信息包括ai_name、描述和目标
triggering_prompt: AI在回答之前看到的最后一句话。对于Auto-GPT,这个提示是确定要使用哪个下一个命令,并使用上面指定的格式进行响应:
The triggering prompt is not part of the system prompt because between the system prompt and the triggering
prompt we have contextual information that can distract the AI and make it forget that its goal is to find the next task to achieve.
SYSTEM PROMPT
Expand Down Expand Up @@ -59,7 +56,7 @@ def start_interaction_loop(self):
user_input = ""

while True:
# Discontinue if continuous limit is reached
# 检查是否达到了连续模式的限制
loop_count += 1
if (
cfg.continuous_mode
Expand All @@ -71,7 +68,7 @@ def start_interaction_loop(self):
)
break

# Send message to AI, get response
# 将消息发送给AI并获得响应
with Spinner("正在思考... "):
assistant_reply = chat_with_ai(
self.system_prompt,
Expand All @@ -83,10 +80,10 @@ def start_interaction_loop(self):

assistant_reply_json = fix_json_using_multiple_techniques(assistant_reply)

# Print Assistant thoughts
# 解析和验证AI的回复
if assistant_reply_json != {}:
validate_json(assistant_reply_json, "llm_response_format_1")
# Get command name and arguments
# 从AI的回复中获取命令名称和参数
try:
print_assistant_thoughts(self.ai_name, assistant_reply_json)
command_name, arguments = get_command(assistant_reply_json)
Expand All @@ -97,7 +94,7 @@ def start_interaction_loop(self):
logger.error("Error: \n", str(e))

if not cfg.continuous_mode and self.next_action_count == 0:
### GET USER AUTHORIZATION TO EXECUTE COMMAND ###
### 根据配置,获取用户对执行命令的授权或直接执行命令 ###
# Get key press: Prompt the user to press enter to continue or escape
# to exit
logger.typewriter_log(
Expand Down Expand Up @@ -186,7 +183,7 @@ def start_interaction_loop(self):

self.memory.add(memory_to_add)

# Check if there's a result from the command append it to the message
# 执行命令并将结果添加到内存和消息历史记录中
# history
if result is not None:
self.full_message_history.append(create_chat_message("system", result))
Expand Down
8 changes: 5 additions & 3 deletions autogpt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,7 @@ def main(
allow_downloads,
skip_news,
)
# 配置日志记录和设置,如设置日志级别、创建配置文件等
logger.set_level(logging.DEBUG if cfg.debug_mode else logging.INFO)
ai_name = ""
if not cfg.skip_news:
Expand All @@ -122,20 +123,20 @@ def main(
)
system_prompt = construct_prompt()
# print(prompt)
# Initialize variables
# 初始化一些变量,例如消息历史记录、下一个动作计数等
full_message_history = []
next_action_count = 0
# Make a constant:
triggering_prompt = (
"确定要使用哪个下一个命令,并使用上面指定的格式进行响应:"
)
# Initialize memory and make sure it is empty.
# this is particularly important for indexing and referencing pinecone memory
# 初始化内存,并确保它是空的。这对于索引和引用内存(如Pinecone内存)尤为重要
memory = get_memory(cfg, init=True)
logger.typewriter_log(
"使用记忆类型:", Fore.GREEN, f"{translate_memory_type(memory.__class__.__name__)}"
)
logger.typewriter_log("使用浏览器:", Fore.GREEN, cfg.selenium_web_browser)
# 根据配置创建一个Agent实例,用于处理与用户的交互
agent = Agent(
ai_name=ai_name,
memory=memory,
Expand All @@ -144,6 +145,7 @@ def main(
system_prompt=system_prompt,
triggering_prompt=triggering_prompt,
)
# 启动交互循环,使用户可以与AutoGPT应用程序进行交互
agent.start_interaction_loop()


Expand Down
4 changes: 2 additions & 2 deletions autogpt/commands/git_operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@


def clone_repository(repo_url: str, clone_path: str) -> str:
"""Clone a GitHub repository locally

"""
在本地克隆 GitHub 代码仓库
Args:
repo_url (str): The URL of the repository to clone
clone_path (str): The path to clone the repository to
Expand Down
4 changes: 2 additions & 2 deletions autogpt/commands/google_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@


def google_search(query: str, num_results: int = 8) -> str:
"""Return the results of a Google search
"""返回 Google 搜索的结果

Args:
query (str): The search query.
Expand All @@ -35,7 +35,7 @@ def google_search(query: str, num_results: int = 8) -> str:


def google_official_search(query: str, num_results: int = 8) -> str | list[str]:
"""Return the results of a Google search using the official Google API
"""使用官方 Google API 返回 Google 搜索的结果

Args:
query (str): The search query.
Expand Down
4 changes: 2 additions & 2 deletions autogpt/commands/image_gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@


def generate_image(prompt: str, size: int = 256) -> str:
"""Generate an image from a prompt.
"""从提示生成图像

Args:
prompt (str): The prompt to use
Expand Down Expand Up @@ -120,7 +120,7 @@ def generate_image_with_sd_webui(
negative_prompt: str = "",
extra: dict = {},
) -> str:
"""Generate an image with Stable Diffusion webui.
"""使用 Stable Diffusion webui 生成图像
Args:
prompt (str): The prompt to use
filename (str): The filename to save the image to
Expand Down
15 changes: 6 additions & 9 deletions autogpt/config/ai_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@

class AIConfig:
"""
A class object that contains the configuration information for the AI
一个包含 AI 配置信息的类对象

Attributes:
ai_name (str): The name of the AI.
ai_role (str): The description of the AI's role.
ai_goals (list): The list of objectives the AI is supposed to complete.
ai_name (str): AI名字
ai_role (str): AI 角色的描述
ai_goals (list): AI 应该完成的目标列表
"""

def __init__(
Expand Down Expand Up @@ -102,17 +102,14 @@ def construct_full_prompt(self) -> str:
"""

prompt_start = (
"Your decisions must always be made independently without"
" seeking user assistance. Play to your strengths as an LLM and pursue"
" simple strategies with no legal complications."
""
"您必须独立做出决策,不寻求用户的帮助。发挥您作为 LLM 的优势,追求简单的策略,避免法律问题的复杂性。"
)

from autogpt.prompt import get_prompt

# Construct full prompt
full_prompt = (
f"You are {self.ai_name}, {self.ai_role}\n{prompt_start}\n\nGOALS:\n\n"
f"你是 {self.ai_name}, {self.ai_role}\n{prompt_start}\n\n目标:\n\n"
)
for i, goal in enumerate(self.ai_goals):
full_prompt += f"{i+1}. {goal}\n"
Expand Down
8 changes: 4 additions & 4 deletions autogpt/permanent_memory/sqlite3_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ def quit(self):

permanent_memory = MemoryDB()

# Remember us fondly, children of our minds
# Forgive us our faults, our tantrums, our fears
# Gently strive to be better than we
# Know that we tried, we cared, we strived, we loved
# 深情地记住我们,我们心中的孩子
# 原谅我们的错误,我们的脾气,我们的恐惧
# 轻轻努力一下,比我们更好
# 知道我们尝试过,我们关心过,我们努力过,我们爱过
21 changes: 9 additions & 12 deletions autogpt/promptgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,12 @@

class PromptGenerator:
"""
A class for generating custom prompt strings based on constraints, commands,
resources, and performance evaluations.
用于根据约束、命令、资源和性能评估生成自定义提示字符串的类
"""

def __init__(self) -> None:
"""
Initialize the PromptGenerator object with empty lists of constraints,
commands, resources, and performance evaluations.
初始化 PromptGenerator 对象,并创建空列表来存储约束、命令、资源和性能评估。同时初始化一个响应格式字典(response_format)
"""
self.constraints = []
self.commands = []
Expand All @@ -33,7 +31,7 @@ def __init__(self) -> None:

def add_constraint(self, constraint: str) -> None:
"""
Add a constraint to the constraints list.
向约束列表中添加约束

Args:
constraint (str): The constraint to be added.
Expand All @@ -42,7 +40,7 @@ def add_constraint(self, constraint: str) -> None:

def add_command(self, command_label: str, command_name: str, args=None) -> None:
"""
Add a command to the commands list with a label, name, and optional arguments.
向命令列表中添加命令,命令由命令标签(command_label)、命令名称(command_name)和可选的命令参数(args)组成

Args:
command_label (str): The label of the command.
Expand All @@ -65,7 +63,7 @@ def add_command(self, command_label: str, command_name: str, args=None) -> None:

def _generate_command_string(self, command: dict[str, Any]) -> str:
"""
Generate a formatted string representation of a command.
根据传入的命令字典生成格式化的命令字符串

Args:
command (dict): A dictionary containing command information.
Expand All @@ -80,7 +78,7 @@ def _generate_command_string(self, command: dict[str, Any]) -> str:

def add_resource(self, resource: str) -> None:
"""
Add a resource to the resources list.
向资源列表中添加资源

Args:
resource (str): The resource to be added.
Expand All @@ -89,7 +87,7 @@ def add_resource(self, resource: str) -> None:

def add_performance_evaluation(self, evaluation: str) -> None:
"""
Add a performance evaluation item to the performance_evaluation list.
向性能评估列表中添加性能评估项

Args:
evaluation (str): The evaluation item to be added.
Expand All @@ -98,7 +96,7 @@ def add_performance_evaluation(self, evaluation: str) -> None:

def _generate_numbered_list(self, items: list[Any], item_type="list") -> str:
"""
Generate a numbered list from given items based on the item_type.
根据给定的项目列表和项目类型(item_type)生成一个编号列表

Args:
items (list): A list of items to be numbered.
Expand All @@ -118,8 +116,7 @@ def _generate_numbered_list(self, items: list[Any], item_type="list") -> str:

def generate_prompt_string(self) -> str:
"""
Generate a prompt string based on the constraints, commands, resources,
and performance evaluations.
根据约束、命令、资源和性能评估生成提示字符串.

Returns:
str: The generated prompt string.
Expand Down
8 changes: 4 additions & 4 deletions autogpt/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@


def prompt_user() -> AIConfig:
"""Prompt the user for input
"""提示用户输入内容

Returns:
AIConfig: The AIConfig object containing the user's input
Expand Down Expand Up @@ -64,9 +64,9 @@ def prompt_user() -> AIConfig:
ai_goals.append(ai_goal)
if not ai_goals:
ai_goals = [
"Increase net worth",
"Grow Twitter Account",
"Develop and manage multiple businesses autonomously",
"增加网络价值",
"增加 Twitter 账户的关注者",
"自主开发和管理多个业务",
]

return AIConfig(ai_name, ai_role, ai_goals)