Skip to content

Commit

Permalink
Prompt sinicization (#3)
Browse files Browse the repository at this point in the history
* refactor: 汉化prompt,减少gpt生成回复的冲突 (#1)

* refactor: 优化triggering_prompt

1.修改triggering_prompt,降低gpt回复格式的出错率
2.一些代码语法的修改

* refactor: 优化triggering_prompt

1.修改triggering_prompt,降低gpt回复格式的出错率
2.一些代码语法的修改
  • Loading branch information
g1331 committed Apr 24, 2023
1 parent 11eddfc commit 7d250e2
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 33 deletions.
14 changes: 11 additions & 3 deletions autogpt/agent/agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ def start_interaction_loop(self):
# 检查是否达到了连续模式的限制
loop_count += 1
if (
cfg.continuous_mode
and cfg.continuous_limit > 0
and loop_count > cfg.continuous_limit
cfg.continuous_mode
and 0 < cfg.continuous_limit < loop_count
):
logger.typewriter_log(
"连续达到限制: ", Fore.YELLOW, f"{cfg.continuous_limit}"
Expand All @@ -80,6 +79,15 @@ def start_interaction_loop(self):

assistant_reply_json = fix_json_using_multiple_techniques(assistant_reply)

if not isinstance(assistant_reply_json, dict):
logger.error(
"=" * 20 + "\n" +
f"修复JSON失败:\n"
f"原始回复: {assistant_reply}\n"
f"修复后的回复: {assistant_reply_json}"
+ "\n" + "=" * 20
)

# 解析和验证AI的回复
if assistant_reply_json != {}:
validate_json(assistant_reply_json, "llm_response_format_1")
Expand Down
5 changes: 2 additions & 3 deletions autogpt/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,8 +126,7 @@ def execute_command(command_name: str, arguments):
# search method
key = CFG.google_api_key
if key and key.strip() and key != "your-google-api-key":
google_result = google_official_search(arguments["input"])
return google_result
return google_official_search(arguments["input"])
else:
google_result = google_search(arguments["input"])

Expand Down Expand Up @@ -256,7 +255,7 @@ def get_hyperlinks(url: str) -> Union[str, List[str]]:

def shutdown() -> NoReturn:
"""Shut down the program"""
print("Shutting down...")
print("关闭中...")
quit()


Expand Down
2 changes: 1 addition & 1 deletion autogpt/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ def main(
next_action_count = 0
# Make a constant:
triggering_prompt = (
"确定要使用哪个下一个命令,并使用上面指定的格式进行响应:"
"确定要使用的下一个命令,并使用上面指定的JSON格式响应:"
)
# 初始化内存,并确保它是空的。这对于索引和引用内存(如Pinecone内存)尤为重要
memory = get_memory(cfg, init=True)
Expand Down
3 changes: 2 additions & 1 deletion autogpt/localization.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@
'name': '名称',
'agent_type': '代理人类型',
'repository_url': '仓库网址',
'query': '搜索词'
'query': '搜索词',
'reason': '原因',
}

mem_type_tr: dict[str, str] = {
Expand Down
32 changes: 14 additions & 18 deletions autogpt/prompt.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,20 +28,18 @@ def get_prompt() -> str:

# Add constraints to the PromptGenerator object
prompt_generator.add_constraint(
"~4000 word limit for short term memory. Your short term memory is short, so"
" immediately save important information to files."
"短期内存限制为4000字左右。你的短期记忆是短暂的,所以立即将重要的信息保存到文件中。"
)
prompt_generator.add_constraint(
"If you are unsure how you previously did something or want to recall past"
" events, thinking about similar events will help you remember."
"如果你不确定你以前是怎么做的,或者想回忆过去的事情,想想类似的事情会帮助你记忆。"
)
prompt_generator.add_constraint("No user assistance")
prompt_generator.add_constraint("Please localize natural language strings in your reply to Chinese")
prompt_generator.add_constraint("无用户协助")
prompt_generator.add_constraint("请在回复中文时本地化自然语言字符串")
prompt_generator.add_constraint(
'Exclusively use the commands listed in double quotes e.g. "command name"'
'只使用双引号中列出的命令,例如: "command name"'
)
prompt_generator.add_constraint(
"Use subprocesses for commands that will not terminate within a few minutes"
"将子流程用于几分钟内不会终止的命令"
)

# Define the command list
Expand Down Expand Up @@ -137,28 +135,26 @@ def get_prompt() -> str:

# Add resources to the PromptGenerator object
prompt_generator.add_resource(
"Internet access for searches and information gathering."
"上网搜索和收集信息。"
)
prompt_generator.add_resource("Long Term memory management.")
prompt_generator.add_resource("长期记忆管理。")
prompt_generator.add_resource(
"GPT-3.5 powered Agents for delegation of simple tasks."
"支持GPT-3.5的代理,用于委派简单的任务。"
)
prompt_generator.add_resource("File output.")
prompt_generator.add_resource("文件输出。")

# Add performance evaluations to the PromptGenerator object
prompt_generator.add_performance_evaluation(
"Continuously review and analyze your actions to ensure you are performing to"
" the best of your abilities."
"不断地回顾和分析你的行动,以确保你发挥出了最大的能力。"
)
prompt_generator.add_performance_evaluation(
"Constructively self-criticize your big-picture behavior constantly."
"不断地进行建设性的自我批评。"
)
prompt_generator.add_performance_evaluation(
"Reflect on past decisions and strategies to refine your approach."
"反思过去的决策和策略,以改进你的方法。"
)
prompt_generator.add_performance_evaluation(
"Every command has a cost, so be smart and efficient. Aim to complete tasks in"
" the least number of steps."
"每个命令都有成本,所以要聪明和高效。以最少的步骤完成任务为目标。"
)

# Generate the prompt string
Expand Down
15 changes: 8 additions & 7 deletions autogpt/promptgenerator.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,13 +123,14 @@ def generate_prompt_string(self) -> str:
"""
formatted_response_format = json.dumps(self.response_format, indent=4)
return (
f"Constraints:\n{self._generate_numbered_list(self.constraints)}\n\n"
"Commands:\n"
f"约束:\n{self._generate_numbered_list(self.constraints)}\n\n"
"指令:\n"
f"{self._generate_numbered_list(self.commands, item_type='command')}\n\n"
f"Resources:\n{self._generate_numbered_list(self.resources)}\n\n"
"Performance Evaluation:\n"
f"资源:\n{self._generate_numbered_list(self.resources)}\n\n"
"绩效评估:\n"
f"{self._generate_numbered_list(self.performance_evaluation)}\n\n"
"You should only respond in JSON format as described below \nResponse"
f" Format: \n{formatted_response_format} \nEnsure the response can be"
" parsed by Python json.loads"
"你应该只以JSON格式响应,如下所述 \n"
"响应格式: \n"
f"{formatted_response_format} \n"
"确保响应可以被Python json.loads解析"
)

0 comments on commit 7d250e2

Please sign in to comment.