任务拆解,悠然自得,自动版本的ChatGPT,AutoGPT自动人工智能AI任务实践(Python3.10)

简介: 当我们使用ChatGPT完成某些工作的时候,往往需要多轮对话,比如让ChatGPT分析、翻译、总结一篇网上的文章或者文档,再将总结的结果以文本的形式存储在本地。过程中免不了要和ChatGPT“折冲樽俎”一番,事实上,这个“交涉”的过程也可以自动化,AutoGPT可以帮助我们自动拆解任务,没错,程序能做到的事情,人类绝不亲力亲为。我们唯一需要做的,就是告诉AutoGPT一个任务目标,AutoGPT会自动根据任务目标将任务拆解成一个个的小任务,并且逐个完成,简单且高效。

当我们使用ChatGPT完成某些工作的时候,往往需要多轮对话,比如让ChatGPT分析、翻译、总结一篇网上的文章或者文档,再将总结的结果以文本的形式存储在本地。过程中免不了要和ChatGPT“折冲樽俎”一番,事实上,这个“交涉”的过程也可以自动化,AutoGPT可以帮助我们自动拆解任务,没错,程序能做到的事情,人类绝不亲力亲为。

我们唯一需要做的,就是告诉AutoGPT一个任务目标,AutoGPT会自动根据任务目标将任务拆解成一个个的小任务,并且逐个完成,简单且高效。

配置AutoGPT

先确保本地环境安装好了Python3.10.9

接着运行Git命令拉取项目:

git clone https://github.com/Significant-Gravitas/Auto-GPT.git
AI 代码解读

随后进入项目的目录:

cd Auto-GPT
AI 代码解读

安装相关的依赖库:

pip3 install -r requirements.txt
AI 代码解读

安装成功后,复制一下项目的配置文件:

cp .env.template .env
AI 代码解读

这里通过cp命令将配置文件模版.env.template复制成为一个新的配置文件.env。

随后将Openai的秘钥填入配置文件:

### OPENAI  
# OPENAI_API_KEY - OpenAI API Key (Example: my-openai-api-key)  
# TEMPERATURE - Sets temperature in OpenAI (Default: 0)  
# USE_AZURE - Use Azure OpenAI or not (Default: False)  
OPENAI_API_KEY=您的秘钥  
TEMPERATURE=0  
USE_AZURE=False
AI 代码解读

除了Openai官方的接口秘钥,AutoGPT也支持微软Azure的接口。

如果希望使用微软Azure的接口,需要将配置中的USE\_AZURE设置为True,随后复制azure.yaml.template配置模版为新的azure.yaml配置文件。

接着将微软Azure服务的秘钥填入azure.yaml即可。

由于微软Azure接入Openai接口需要极其复杂的申请流程,这里还是直接使用OpenAI官方的接口。

当然了,如果不想在本地装那么多依赖,也可以通过Docker来构建Auto-GPT的容器:

docker build -t autogpt .  
docker run -it --env-file=./.env -v $PWD/auto_gpt_workspace:/app/auto_gpt_workspace autogpt
AI 代码解读

这里Docker会自动读取项目中的Dockerfile配置文件进行构建,相当方便。

至此,Auto-GPT就配置好了。

运行Auto-GPT

在项目根目录运行命令:

python3 -m autogpt --debug
AI 代码解读

即可启动AutoGPT:

➜  Auto-GPT git:(master) python -m autogpt --debug         
Warning: The file 'AutoGpt.json' does not exist. Local memory would not be saved to a file.  
Debug Mode:  ENABLED  
Welcome to Auto-GPT!  Enter the name of your AI and its role below. Entering nothing will load defaults.  
Name your AI:  For example, 'Entrepreneur-GPT'  
AI Name:
AI 代码解读

首先创建AutoGPT机器人的名字:

AI Name: v3u.cn  
v3u.cn here!  I am at your service.  
Describe your AI's role:  For example, 'an AI designed to autonomously develop and run businesses with the sole goal of increasing your net worth.'  
v3u.cn is:
AI 代码解读

创建好名字以后,Auto-GPT就可以随时为您效劳了。

首先为AutoGPT设置目标:

v3u.cn is: Analyze the contents of this article,the url is https://v3u.cn/a_id_303,and write the result to goal.txt
AI 代码解读

这里我们要求AutoGPT分析并且总结v3u.cn/a\_id\_303这篇文章,并且将分析结果写入本地的goal.txt文件。

程序返回:

Enter up to 5 goals for your AI:  For example: Increase net worth, Grow Twitter Account, Develop and manage multiple businesses autonomously'  
Enter nothing to load defaults, enter nothing when finished.  
Goal 1:   
Using memory of type:  LocalCache
AI 代码解读

AutoGPT会告诉你可以最多拆解为五个任务,我们可以自己拆解,也可以让机器人帮助我们拆解,直接按回车,让AutoGPT自动拆解任务即可。

接着程序会自动爬取这篇文章的内容,然后使用gpt-3.5-turbo模型来进行分析:

Goal 1:   
Using memory of type:  LocalCache  
Using Browser:  chrome  
  Token limit: 4000  
  Memory Stats: (0, (0, 1536))  
  Token limit: 4000  
  Send Token Count: 936  
  Tokens remaining for response: 3064  
  ------------ CONTEXT SENT TO AI ---------------  
  System: The current time and date is Mon Apr 17 20:29:37 2023  
    
  System: This reminds you of these events from your past:  
  
  
  
    
  User: Determine which next command to use, and respond using the format specified above:  
    
  ----------- END OF CONTEXT ----------------  
Creating chat completion with model gpt-3.5-turbo, temperature 0.0, max_tokens 3064  
The JSON object is valid.  
 THOUGHTS:  Let's start by browsing the article at https://v3u.cn/a_id_303 to get a better understanding of its contents.  
REASONING:  Browsing the article will allow us to analyze its contents and determine the appropriate next steps.  
PLAN:   
-  Browse the article  
-  Analyze its contents  
-  Determine the appropriate next steps  
CRITICISM:  None  
NEXT ACTION:  COMMAND = browse_website ARGUMENTS = {'url': 'https://v3u.cn/a_id_303', 'question': 'analyze the contents of the article'}  
Enter 'y' to authorise command, 'y -N' to run N continuous commands, 'n' to exit program, or enter feedback for ...  
Input:y  
-=-=-=-=-=-=-= COMMAND AUTHORISED BY USER -=-=-=-=-=-=-=   
[WDM] - Downloading: 100%|████████████████████████████████████████████| 8.04M/8.04M [00:03<00:00, 2.42MB/s]  
Text length: 6977 characters  
Adding chunk 1 / 1 to memory  
Summarizing chunk 1 / 1  
Creating chat completion with model gpt-3.5-turbo, temperature 0.0, max_tokens 300  
SYSTEM:  Command browse_website returned: Error: This model's maximum context length is 4097 tokens. However, you requested 4339 tokens (4039 in the messages, 300 in the completion). Please reduce the length of the messages or completion.  
  Token limit: 4000  
  Memory Stats: (2, (2, 1536))  
  Token limit: 4000  
  Send Token Count: 1472  
  Tokens remaining for response: 2528  
  ------------ CONTEXT SENT TO AI ---------------  
  System: The current time and date is Mon Apr 17 20:30:19 2023  
    
  System: This reminds you of these events from your past:  
['Assistant Reply: {\n    "thoughts": {\n        "text": "Let\'s start by browsing the article at https://v3u.cn/a_id_303 to get a better understanding of its contents.",\n        "reasoning": "Browsing the article will allow us to analyze its contents and determine the appropriate next steps.",\n        "plan": "- Browse the article\\n- Analyze its contents\\n- Determine the appropriate next steps",\n        "criticism": "None",\n        "speak": "I suggest we start by browsing the article at the given URL to analyze its contents and determine the appropriate next steps."\n    },\n    "command": {\n        "name": "browse_website",\n        "args": {\n            "url": "https://v3u.cn/a_id_303",\n            "question": "analyze the contents of the article"\n        }\n    }\n} \nResult: Command browse_website returned: Error: This model\'s maximum context length is 4097 tokens. However, you requested 4339 tokens (4039 in the messages, 300 in the completion). Please reduce the length of the messages or completion. \nHuman Feedback: GENERATE NEXT COMMAND JSON ']  
  
  
    
  User: Determine which next command to use, and respond using the format specified above:  
    
  Assistant: {  
    "thoughts": {  
        "text": "Let's start by browsing the article at https://v3u.cn/a_id_303 to get a better understanding of its contents.",  
        "reasoning": "Browsing the article will allow us to analyze its contents and determine the appropriate next steps.",  
        "plan": "- Browse the article\n- Analyze its contents\n- Determine the appropriate next steps",  
        "criticism": "None",  
        "speak": "I suggest we start by browsing the article at the given URL to analyze its contents and determine the appropriate next steps."  
    },  
    "command": {  
        "name": "browse_website",  
        "args": {  
            "url": "https://v3u.cn/a_id_303",  
            "question": "analyze the contents of the article"  
        }  
    }  
}  
    
    
  User: Determine which next command to use, and respond using the format specified above:  
    
  ----------- END OF CONTEXT ----------------  
Creating chat completion with model gpt-3.5-turbo, temperature 0.0, max_tokens 2528
AI 代码解读

最后将分析结果写入goal.txt文件:

这篇文章主要阐释了苹果Mac电脑可以完成机器学习和深度学习任务,并且通过深度学习框架Tensorflow的安装和运行进行了佐证,同时也对Tensorflow的CPU和GPU的两种模型训练模式进行了深度对比和测试。
AI 代码解读

一气呵成,流畅丝滑。

结语

AutoGPT和其他 AI 程序的不同之处在于,它专门专注于在无需人工干预的情况下生成提示和自动执行多步骤任务。它还具有扫描互联网或在用户计算机上执行命令以获取信息的能力,这使其有别于可能仅依赖于预先存在的数据集的其他人工智能程序。

AutoGPT的底层逻辑并不复杂:先通过搜索引擎检索任务,然后把结果和目标丢给gpt让它给出序列化方案json,再把方案分段丢给gpt,最后用shell去创建Python文件+json.load并且执行,是一个反复递归的过程。

不能否认的是,虽然实现逻辑简单,但这无疑是一种“自我进化”的过程,相信随着时间的推移,AutoGPT可以更好地处理愈加复杂的任务。

目录
打赏
0
0
0
0
1681
分享
相关文章
【01】做一个精美的打飞机小游戏,浅尝阿里云通义灵码python小游戏开发AI编程-之飞机大战小游戏上手实践-优雅草央千澈-用ai开发小游戏尝试-分享源代码和游戏包
【01】做一个精美的打飞机小游戏,浅尝阿里云通义灵码python小游戏开发AI编程-之飞机大战小游戏上手实践-优雅草央千澈-用ai开发小游戏尝试-分享源代码和游戏包
406 48
【01】做一个精美的打飞机小游戏,浅尝阿里云通义灵码python小游戏开发AI编程-之飞机大战小游戏上手实践-优雅草央千澈-用ai开发小游戏尝试-分享源代码和游戏包
Omnitool:开发者桌面革命!开源神器一键整合ChatGPT+Stable Diffusion等主流AI平台,本地运行不联网
Omnitool 是一款开源的 AI 桌面环境,支持本地运行,提供统一交互界面,快速接入 OpenAI、Stable Diffusion、Hugging Face 等主流 AI 平台,具备高度扩展性。
602 94
Omnitool:开发者桌面革命!开源神器一键整合ChatGPT+Stable Diffusion等主流AI平台,本地运行不联网
哈佛推出全新类ChatGPT癌症诊断AI,登上Nature!准确率高达96%
哈佛大学研究团队开发的新型AI模型CHIEF,在《自然》期刊发表,癌症诊断准确率达96%。CHIEF基于深度学习,能自动识别、分类癌症并预测生存期,具高准确性、多任务能力和泛化性。它结合病理图像与基因组学等数据,显著提升诊断效率和个性化治疗水平,有望改善医疗资源不平等。但数据隐私和临床效果验证仍是挑战。论文见:https://www.nature.com/articles/s41586-024-07894-z
261 101
当ChatGPT能写情书、Sora会造电影:我们必须掌握的AI内容识别技能
随着AI技术迅猛发展,AI生成内容在文学、新闻、绘画等领域广泛应用,但其真假难辨、质量参差不齐,可能带来信息误导、知识产权侵犯及安全风险等问题。学会识别AI生成内容至关重要,包括通过逻辑漏洞排查、语言风格分析、生物特征异常检测等手段审核文本、图片和视频。人工审核在面对高隐蔽性内容时仍不可替代,需结合工具与上下文理解共同筑起防护屏障。守护真实信息、规避风险,是每个人在AI时代应尽的责任。
118 7
ChatGPT-on-WeChat:Star32.4k, DeepSeek加持!这款开源神器秒变AI助手,聊天体验直接起飞!
嗨,大家好,我是小华同学。今天为大家介绍一款结合DeepSeek引擎的开源项目——ChatGPT-on-WeChat,由开发者zhayujie打造。它将微信变成智能AI助手,支持文本、图片、语音对话,具备定时提醒、天气查询等扩展功能,完全开源且易于定制。项目地址:https://github.com/zhayujie/chatgpt-on-wechat。关注我们,获取更多优质开源项目和高效学习方法。
475 11
DeepSeek vs ChatGPT:AI对决中的赢家是……人类吗?
DeepSeek VS ChatGPT:DeepSeek以开源黑马姿态崛起,凭借低成本、高性能的「DeepSeek-V3」和专为深度推理设计的「DeepSeek-R1」,成为中小开发者的首选。而ChatGPT则较贵。 然而,AI依赖也带来隐忧,长期使用可能导致记忆衰退和“脑雾”现象。为此,推荐Neuriva解决方案,专注力提升30%,记忆留存率提升2.1倍,助力人类在AI时代保持脑力巅峰。 DeepSeek赢在技术普惠,ChatGPT胜于生态构建,人类的关键在于平衡AI与脑力健康,实现“双核驱动”突破极限!
446 7
Python实用技巧:轻松驾驭多线程与多进程,加速任务执行
在Python编程中,多线程和多进程是提升程序效率的关键工具。多线程适用于I/O密集型任务,如文件读写、网络请求;多进程则适合CPU密集型任务,如科学计算、图像处理。本文详细介绍这两种并发编程方式的基本用法及应用场景,并通过实例代码展示如何使用threading、multiprocessing模块及线程池、进程池来优化程序性能。结合实际案例,帮助读者掌握并发编程技巧,提高程序执行速度和资源利用率。
166 0
用Python实现简单的任务自动化
本文介绍如何使用Python实现任务自动化,提高效率和准确性。通过三个实用案例展示:1. 使用`smtplib`和`schedule`库自动发送邮件提醒;2. 利用`shutil`和`os`库自动备份文件;3. 借助`requests`库自动下载网页内容。每个案例包含详细代码和解释,并附带注意事项。掌握这些技能有助于个人和企业优化流程、节约成本。
215 3
Python量化投资实践:基于蒙特卡洛模拟的投资组合风险建模与分析
蒙特卡洛模拟是一种利用重复随机抽样解决确定性问题的计算方法,广泛应用于金融领域的不确定性建模和风险评估。本文介绍如何使用Python和EODHD API获取历史交易数据,通过模拟生成未来价格路径,分析投资风险与收益,包括VaR和CVaR计算,以辅助投资者制定合理决策。
353 15
OpenAI推出适用于iPhone的ChatGPT,与Apple实现具有里程碑意义的AI整合
OpenAI推出适用于iPhone的ChatGPT,与Apple实现具有里程碑意义的AI整合

推荐镜像

更多
AI助理

你好,我是AI助理

可以解答问题、推荐解决方案等