Skip to content

Commit 7fd9f30

Browse files
authored
Merge pull request #17 from zky001/main
增加部分中文注释,修改剩下的部分英文输出为中文
2 parents 5465033 + 48ef80a commit 7fd9f30

File tree

9 files changed

+46
-53
lines changed

9 files changed

+46
-53
lines changed

autogpt/agent/agent.py

Lines changed: 12 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,12 @@ class Agent:
1616
"""Agent class for interacting with Auto-GPT.
1717
1818
Attributes:
19-
ai_name: The name of the agent.
20-
memory: The memory object to use.
21-
full_message_history: The full message history.
22-
next_action_count: The number of actions to execute.
23-
system_prompt: The system prompt is the initial prompt that defines everything the AI needs to know to achieve its task successfully.
24-
Currently, the dynamic and customizable information in the system prompt are ai_name, description and goals.
25-
26-
triggering_prompt: The last sentence the AI will see before answering. For Auto-GPT, this prompt is:
27-
Determine which next command to use, and respond using the format specified above:
19+
ai_name: 代理的名称
20+
memory: 要使用的内存对象
21+
full_message_history: 完整的消息历史记录
22+
next_action_count: 要执行的操作数
23+
system_prompt: 系统提示是初始提示,定义了AI需要了解的所有内容以成功完成任务。系统提示中的动态和可自定义信息包括ai_name、描述和目标
24+
triggering_prompt: AI在回答之前看到的最后一句话。对于Auto-GPT,这个提示是确定要使用哪个下一个命令,并使用上面指定的格式进行响应:
2825
The triggering prompt is not part of the system prompt because between the system prompt and the triggering
2926
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.
3027
SYSTEM PROMPT
@@ -59,7 +56,7 @@ def start_interaction_loop(self):
5956
user_input = ""
6057

6158
while True:
62-
# Discontinue if continuous limit is reached
59+
# 检查是否达到了连续模式的限制
6360
loop_count += 1
6461
if (
6562
cfg.continuous_mode
@@ -71,7 +68,7 @@ def start_interaction_loop(self):
7168
)
7269
break
7370

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

8481
assistant_reply_json = fix_json_using_multiple_techniques(assistant_reply)
8582

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

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

187184
self.memory.add(memory_to_add)
188185

189-
# Check if there's a result from the command append it to the message
186+
# 执行命令并将结果添加到内存和消息历史记录中
190187
# history
191188
if result is not None:
192189
self.full_message_history.append(create_chat_message("system", result))

autogpt/cli.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ def main(
101101
allow_downloads,
102102
skip_news,
103103
)
104+
# 配置日志记录和设置,如设置日志级别、创建配置文件等
104105
logger.set_level(logging.DEBUG if cfg.debug_mode else logging.INFO)
105106
ai_name = ""
106107
if not cfg.skip_news:
@@ -122,20 +123,20 @@ def main(
122123
)
123124
system_prompt = construct_prompt()
124125
# print(prompt)
125-
# Initialize variables
126+
# 初始化一些变量,例如消息历史记录、下一个动作计数等
126127
full_message_history = []
127128
next_action_count = 0
128129
# Make a constant:
129130
triggering_prompt = (
130131
"确定要使用哪个下一个命令,并使用上面指定的格式进行响应:"
131132
)
132-
# Initialize memory and make sure it is empty.
133-
# this is particularly important for indexing and referencing pinecone memory
133+
# 初始化内存,并确保它是空的。这对于索引和引用内存(如Pinecone内存)尤为重要
134134
memory = get_memory(cfg, init=True)
135135
logger.typewriter_log(
136136
"使用记忆类型:", Fore.GREEN, f"{translate_memory_type(memory.__class__.__name__)}"
137137
)
138138
logger.typewriter_log("使用浏览器:", Fore.GREEN, cfg.selenium_web_browser)
139+
# 根据配置创建一个Agent实例,用于处理与用户的交互
139140
agent = Agent(
140141
ai_name=ai_name,
141142
memory=memory,
@@ -144,6 +145,7 @@ def main(
144145
system_prompt=system_prompt,
145146
triggering_prompt=triggering_prompt,
146147
)
148+
# 启动交互循环,使用户可以与AutoGPT应用程序进行交互
147149
agent.start_interaction_loop()
148150

149151

autogpt/commands/git_operations.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@
88

99

1010
def clone_repository(repo_url: str, clone_path: str) -> str:
11-
"""Clone a GitHub repository locally
12-
11+
"""
12+
在本地克隆 GitHub 代码仓库
1313
Args:
1414
repo_url (str): The URL of the repository to clone
1515
clone_path (str): The path to clone the repository to

autogpt/commands/google_search.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212

1313
def google_search(query: str, num_results: int = 8) -> str:
14-
"""Return the results of a Google search
14+
"""返回 Google 搜索的结果
1515
1616
Args:
1717
query (str): The search query.
@@ -35,7 +35,7 @@ def google_search(query: str, num_results: int = 8) -> str:
3535

3636

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

autogpt/commands/image_gen.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515

1616

1717
def generate_image(prompt: str, size: int = 256) -> str:
18-
"""Generate an image from a prompt.
18+
"""从提示生成图像
1919
2020
Args:
2121
prompt (str): The prompt to use
@@ -120,7 +120,7 @@ def generate_image_with_sd_webui(
120120
negative_prompt: str = "",
121121
extra: dict = {},
122122
) -> str:
123-
"""Generate an image with Stable Diffusion webui.
123+
"""使用 Stable Diffusion webui 生成图像
124124
Args:
125125
prompt (str): The prompt to use
126126
filename (str): The filename to save the image to

autogpt/config/ai_config.py

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,12 @@
1212

1313
class AIConfig:
1414
"""
15-
A class object that contains the configuration information for the AI
15+
一个包含 AI 配置信息的类对象
1616
1717
Attributes:
18-
ai_name (str): The name of the AI.
19-
ai_role (str): The description of the AI's role.
20-
ai_goals (list): The list of objectives the AI is supposed to complete.
18+
ai_name (str): AI名字
19+
ai_role (str): AI 角色的描述
20+
ai_goals (list): AI 应该完成的目标列表
2121
"""
2222

2323
def __init__(
@@ -102,17 +102,14 @@ def construct_full_prompt(self) -> str:
102102
"""
103103

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

111108
from autogpt.prompt import get_prompt
112109

113110
# Construct full prompt
114111
full_prompt = (
115-
f"You are {self.ai_name}, {self.ai_role}\n{prompt_start}\n\nGOALS:\n\n"
112+
f"你是 {self.ai_name}, {self.ai_role}\n{prompt_start}\n\n目标:\n\n"
116113
)
117114
for i, goal in enumerate(self.ai_goals):
118115
full_prompt += f"{i+1}. {goal}\n"

autogpt/permanent_memory/sqlite3_store.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ def quit(self):
117117

118118
permanent_memory = MemoryDB()
119119

120-
# Remember us fondly, children of our minds
121-
# Forgive us our faults, our tantrums, our fears
122-
# Gently strive to be better than we
123-
# Know that we tried, we cared, we strived, we loved
120+
# 深情地记住我们,我们心中的孩子
121+
# 原谅我们的错误,我们的脾气,我们的恐惧
122+
# 轻轻努力一下,比我们更好
123+
# 知道我们尝试过,我们关心过,我们努力过,我们爱过

autogpt/promptgenerator.py

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,14 +7,12 @@
77

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

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

3432
def add_constraint(self, constraint: str) -> None:
3533
"""
36-
Add a constraint to the constraints list.
34+
向约束列表中添加约束
3735
3836
Args:
3937
constraint (str): The constraint to be added.
@@ -42,7 +40,7 @@ def add_constraint(self, constraint: str) -> None:
4240

4341
def add_command(self, command_label: str, command_name: str, args=None) -> None:
4442
"""
45-
Add a command to the commands list with a label, name, and optional arguments.
43+
向命令列表中添加命令,命令由命令标签(command_label)、命令名称(command_name)和可选的命令参数(args)组成
4644
4745
Args:
4846
command_label (str): The label of the command.
@@ -65,7 +63,7 @@ def add_command(self, command_label: str, command_name: str, args=None) -> None:
6563

6664
def _generate_command_string(self, command: dict[str, Any]) -> str:
6765
"""
68-
Generate a formatted string representation of a command.
66+
根据传入的命令字典生成格式化的命令字符串
6967
7068
Args:
7169
command (dict): A dictionary containing command information.
@@ -80,7 +78,7 @@ def _generate_command_string(self, command: dict[str, Any]) -> str:
8078

8179
def add_resource(self, resource: str) -> None:
8280
"""
83-
Add a resource to the resources list.
81+
向资源列表中添加资源
8482
8583
Args:
8684
resource (str): The resource to be added.
@@ -89,7 +87,7 @@ def add_resource(self, resource: str) -> None:
8987

9088
def add_performance_evaluation(self, evaluation: str) -> None:
9189
"""
92-
Add a performance evaluation item to the performance_evaluation list.
90+
向性能评估列表中添加性能评估项
9391
9492
Args:
9593
evaluation (str): The evaluation item to be added.
@@ -98,7 +96,7 @@ def add_performance_evaluation(self, evaluation: str) -> None:
9896

9997
def _generate_numbered_list(self, items: list[Any], item_type="list") -> str:
10098
"""
101-
Generate a numbered list from given items based on the item_type.
99+
根据给定的项目列表和项目类型(item_type)生成一个编号列表
102100
103101
Args:
104102
items (list): A list of items to be numbered.
@@ -118,8 +116,7 @@ def _generate_numbered_list(self, items: list[Any], item_type="list") -> str:
118116

119117
def generate_prompt_string(self) -> str:
120118
"""
121-
Generate a prompt string based on the constraints, commands, resources,
122-
and performance evaluations.
119+
根据约束、命令、资源和性能评估生成提示字符串.
123120
124121
Returns:
125122
str: The generated prompt string.

autogpt/setup.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88

99
def prompt_user() -> AIConfig:
10-
"""Prompt the user for input
10+
"""提示用户输入内容
1111
1212
Returns:
1313
AIConfig: The AIConfig object containing the user's input
@@ -64,9 +64,9 @@ def prompt_user() -> AIConfig:
6464
ai_goals.append(ai_goal)
6565
if not ai_goals:
6666
ai_goals = [
67-
"Increase net worth",
68-
"Grow Twitter Account",
69-
"Develop and manage multiple businesses autonomously",
67+
"增加网络价值",
68+
"增加 Twitter 账户的关注者",
69+
"自主开发和管理多个业务",
7070
]
7171

7272
return AIConfig(ai_name, ai_role, ai_goals)

0 commit comments

Comments
 (0)