【衍生工具篇】ChatGPT 颠覆者 Auto-GPT
相信最近 大家或多都听到了 Auto-GPT 这个词,非常的火爆。
这一节我们就来讲解 Auto-GPT 相关的内容,并帮忙大家上手体验
一、Auto-GPT 是什么
AutoGPT是一个开源的AI代理Python应用程序,使用 GPT-4 作为基础,允许AI自主行动,完全无需用户提示每个操作,30分钟内就可以完成设置,以设置和入门的简便性在用户中大受欢迎,目前GitHub Star量已超过42k。
简单来说,AutoGPT 底层还是 GPT 模型。只是他使用 GPT 的方法比 ChatGPT 更近了一步。
AutoGPT最大的特点就在于能全自动地根据任务指令进行分析和执行,自己给自己提问并进行回答,中间环节不需要用户参与。
目前AutoGPT已经具备的功能包括
用于搜索和信息收集的 Internet 访问
长期和短期内存管理
用于文本生成的 GPT-4 实例
访问流行的网站和平台
️ 使用 GPT-3.5 进行文件存储和汇总
支持执行脚本
如果说ChatGPT是服从用户指令,用户让它干什么它就干什么,
那AutoGPT就是“自己觉得应该干什么就干什么”,它就像是一个遇到不懂的问题能自行去百度的人类。
用户可以为AutoGPT设定总体目标,然后让它逐步采取措施来一一实现目标,这就是“AI代理”概念的由来,它完全自动执行操作。
二、Auto-GPT和ChatGPT有什么区别
大家这一阵子使用 ChatGPT ,相信大家能感受到它的强大,不过还是有很多缺陷,比如字数限制、需要一问一答没办法一条龙给答案;聊多了总是差那么点意思。
而在 Auto-GPT 面前,ChatGPT 就显的笨笨的了。
当我们抛出一个问题后,Auto-GPT 可以帮们我们分析,告诉我们它的想法是什么,计划是什么,怎么做,为什么这么做,下一步要做什么。
不像 ChatGPT 直接把答案抛给我们,我们也不知道正确性。
可以先来看看官网的一个例子
http://mpvideo.qpic.cn/0bc3kmaaeaaap4ac2pbr6nsfau6dajjqaaqa.f10002.mp4?dis_k=921d1f801b4f9f789b5ca62120e41f09&dis_t=1681536368&play_scene=10120&auth_info=BpHm6INfekkS3s+JnV9YS2U+G2tjTGNKVigiE1kTbno/FjAaEA==&auth_key=e178b036315a08e60b6cf4c6e4686756&vid=wxv_2874820741702287362&format_id=10002&support_redirect=0&mmversion=false
三、Auto-GPT 核心是什么
AutoGPT 这类 AI agent 工作的内部结构与核心逻辑和我们之前学到的角色扮演在原理上是类似的,。这类项目绝大多数的主要创新还是在 prompt 层面,通过更好的提示词来激发模型的能力,把更多原先需要通过代码来实现的流程“硬逻辑”转化为模型自动生成的“动态逻辑”。
对 AutoGPT 来说,它的核心 prompt 如下
You are Guandata-GPT, 'an AI assistant designed to help data analysts do their daily work.'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.
GOALS:
1. 'Process data sets'
2. 'Generate data reports and visualizations'
3. 'Analyze reports to gain business insights'
Constraints:
1. ~4000 word limit for short term memory. Your short term memory is short, so immediately save important information to files.
2. If you are unsure how you previously did something or want to recall past events, thinking about similar events will help you remember.
3. No user assistance4. Exclusively use the commands listed in double quotes e.g. "command name"
Commands:
1. Google Search: "google", args: "input": "<search>"
2. Browse Website: "browse_website", args: "url": "<url>", "question": "<what_you_want_to_find_on_website>"
3. Start GPT Agent: "start_agent", args: "name": "<name>", "task": "<short_task_desc>", "prompt": "<prompt>"
4. Message GPT Agent: "message_agent", args: "key": "<key>", "message": "<message>"
5. List GPT Agents: "list_agents", args:
6. Delete GPT Agent: "delete_agent", args: "key": "<key>"
7. Clone Repository: "clone_repository", args: "repository_url": "<url>", "clone_path": "<directory>"
8. Write to file: "write_to_file", args: "file": "<file>", "text": "<text>"
9. Read file: "read_file", args: "file": "<file>"
10. Append to file: "append_to_file", args: "file": "<file>", "text": "<text>"
11. Delete file: "delete_file", args: "file": "<file>"
12. Search Files: "search_files", args: "directory": "<directory>"
13. Evaluate Code: "evaluate_code", args: "code": "<full_code_string>"
14. Get Improved Code: "improve_code", args: "suggestions": "<list_of_suggestions>", "code": "<full_code_string>"
15. Write Tests: "write_tests", args: "code": "<full_code_string>", "focus": "<list_of_focus_areas>"
16. Execute Python File: "execute_python_file", args: "file": "<file>"
17. Generate Image: "generate_image", args: "prompt": "<prompt>"
18. Send Tweet: "send_tweet", args: "text": "<text>"
19. Do Nothing: "do_nothing", args:
20. Task Complete (Shutdown): "task_complete", args: "reason": "<reason>"
Resources:
1. Internet access for searches and information gathering.
2. Long Term memory management.
3. GPT-3.5 powered Agents for delegation of simple tasks.
4. File output.
Performance Evaluation:
1. Continuously review and analyze your actions to ensure you are performing to the best of your abilities.
2. Constructively self-criticize your big-picture behavior constantly.
3. Reflect on past decisions and strategies to refine your approach.
4. Every command has a cost, so be smart and efficient. Aim to complete tasks in the least number of steps.
You should only respond in JSON format as described below Response Format:
{
"thoughts": {
"text": "thought",
"reasoning": "reasoning",
"plan": "- short bulleted\n- list that conveys\n- long-term plan", "criticism": "constructive self-criticism",
"speak": "thoughts summary to say to user"
},
"command": {
"name": "command name",
"args": {
"arg name": "value"
}
}
}
Ensure the response can be parsed by Python json.loads
其中:
Constraints & Resources
设置局限性。例如模型的输入 context size 有限制,所以需要把重要的信息保存到文件里。尤其在代码生成场景中这个动作非常重要,否则无法实现长代码的生成和执行。
另外 AutoGPT 里也给模型提供了长期记忆的管理功能,当前这类复杂 prompt 生成的解决任务的流程往往比较冗长,没有这类长期记忆的管理很容易就会导致模型的输出变得不连贯协调。
另外像默认的模型是“没有联网”的,所有的知识只更新到训练数据的截止日期。所以也明确告诉模型可以通过网络搜索来获取更多时效性的外部信息
Commands
在 commands 也就是各类工具的选择上,这里给出的选项非常丰富。这也是为何很多文章宣传里提到 AutoGPT 能够完成多种不同任务的原因之一,灵活性与通用性很高。
具体的 commands 中,可以分为几大类,
搜索
浏览网页相关
启动其它的 GPT agent(启动子任务)
文件读写操作
代码生成与执行等
目前 GPT 模型对于越具体生成的表现就越精确和稳定。这种“分而治之”的思路非常好。
Performance Evaluation
设置模型整体思考流程的指导原则,分为了几个具体维度,包括对自己的能力与行为的匹配进行 review,大局观与自我反思,结合长期记忆对决策动作进行优化,以及尽可能高效率地用较少的动作来完成任务。
这个思考逻辑也非常符合人类的思考方式。
Response
从 response 格式上来看,也是综合了几种模式,包括需要把自己的想法写出来,做一些 reasoning 获取相关背景知识,生成有具体步骤的 plan,以及对自己的思考过程进行 criticism 等。
这些格式的限定也是对前面思维指导原则的具体操作规范说明。
需要注意的是
因为 AutoGPT 生成的解决流程往往会非常冗长,耗费的时间和 token 量都会非常大
四、本地搭建体验 | 需要魔法
要求
Python 3.8或更高版本
OpenAI API密钥
需要魔法
安装步骤
第一步 下载 Auto gpt
在本地执行 或者直接访问 https://github.com/Significant-Gravitas/Auto-GPT.git ,点击 download zip
git clone https://github.com/Significant-Gravitas/Auto-GPT.git

第二步 安装依赖
cd Auto-GPT
pip install -r requirements.txt
第三步 修改配置
将 .env.template重命名为.env并填写OPENAI_API_KEY(https://platform.openai.com/account/api-keys 获取自己的key)
第四步 启动
python scripts/main.py
//可能会出现提示
Please run:
python -m autogpt
那就直接执行
python -m autogpt
第四步 目标定义

第五步 AutoGPT 理解分析

可以看到 AutoPGT 会对我们给的目标进行分析,告诉我们它是怎么思考的,原因是什么,计划是什么,以及接下来要做什么
我们只需要在 Input 那输入 Y 即可,AutoGPT就会继续执行
第六步 结果查看
最终结束后会在 Auto-GPT/auto_gpt_workspace 目录下存放结果,直接查看即可
五、Google colab 一键搭建 | 需要魔法 (无魔法直接下拉看第六章)
如果我们不想在本地搭建,我们可以直接白嫖 Google colab 的资源来搭建
可以直接参考 https://colab.research.google.com/drive/11cqXILn_wjMUSXzt48-FtiqdPzflX4KL?usp=sharing

六、如何添加Google搜索
如果我们的 apikey 还是 3.5,但是我们希望使用google 搜索的话,我们可以在 AutoGPT 中配置google的key
获取key
前往 Google Cloud Console https://console.cloud.google.com/。
如果没有帐户,请创建一个并登录。
通过点击页面顶部的“选择项目”下拉菜单并点击“新建项目”来创建一个新项目。给它一个名字,然后点击“创建”。
前往API和服务控制台(https://console.cloud.google.com/apis/dashboard)并点击“启用API和服务”。搜索“自定义搜索API”,然后点击它,然后点击“启用”。
前往凭据页面(https://console.cloud.google.com/apis/credentials)并点击“创建凭据”。选择“API密钥”。
复制API密钥并将其设置为电脑上名为GOOGLE_API_KEY的环境变量。请参见下面的环境变量设置。
/Auto-GPT/.env 文件
# GOOGLE_API_KEY - Google API key (Example: my-google-api-key)
# CUSTOM_SEARCH_ENGINE_ID - Custom search engine ID (Example: my-custom-search-engine-id)
GOOGLE_API_KEY=API_KEY
CUSTOM_SEARCH_ENGINE_ID=6110d25e77cbd45de
获取 Google ENGINE_ID
前往自定义搜索引擎页面(https://cse.google.com/cse/all)点击“添加”。
选择搜索整个网络或特定站点。
创建完搜索引擎后,点击“控制台”,然后点击“基础”。复制“搜索引擎ID”,并配置在环境变量中
/Auto-GPT/.env 文件
# GOOGLE_API_KEY - Google API key (Example: my-google-api-key)
# CUSTOM_SEARCH_ENGINE_ID - Custom search engine ID (Example: my-custom-search-engine-id)
CUSTOM_SEARCH_ENGINE_ID=GENINE_ID
每日免费自定义搜索配额最多允许100次搜索。要增加此限制,您需要将结算帐户分配给该项目,以从每日最多10K搜索中获利。
七、替代方案 | 不需要魔法
AgentGPT: Autonomous AI in your browser
虽然目前只能设置一个目标,不过体验也是足够的

八、一些限制
目前来看 Auto-GPT 还是不够成熟的,虽然它的理念非常好,但还是有很多的限制
虽然通过把记录存储在文件中实现长期记忆,但每次处理的次数依然会有限制
使用的 token 也非常高。因为把所有的记录都存储在文件中作为后续的分析使用(那就必然会非常频繁的和ChatGPT 交互)
能不能跑出来结果往往和定义的 Goal 有关。很多时候跑不出来结果,会导致死循环
一旦定义了 Goal ,在整个交互过程中只能继续或退出,没有调教的余地
所以,还是让子弹再飞一会儿,大家可以先尝尝鲜