Home  >  Article  >  Technology peripherals  >  AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

PHPz
PHPzforward
2023-05-22 23:04:041125browse

Some time ago, HuggingGPT proposed by the Microsoft team of Zhejiang University became popular in the entire technology circle.

This large model collaboration system uses ChatGPT as the controller to call various models in HuggingFace at will to achieve multi-modal tasks.

Letting ChatGPT be the “boss” has become a direction that many people are optimistic about.

No, what is supposed to come is coming...

"Transformers" is officially produced by HuggingFace, the world's most popular AI community Agent" can also achieve magic by controlling more than 100,000 AIs.

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

Nvidia scientist Jim Fan praised this as the first step towards the Everything App, and as the ecosystem expands, its capabilities Also growing.

He continued that HuggingGPT is the first large-scale demonstration of this idea. It uses GPT as a controller to dynamically select tools (models) to solve multi-stage tasks.

ChatGPT’s “App Store” is of course an example of an AI tool ecosystem application. The new Transformers Agent allows you to have super buffs and quickly build AI agents.

Transformers, omnipotent

Using Transformers Agent, you can open your mouth to draw pictures, and you can also have it read out for you.

Let’s take a look at a few examples~

<code>agent.run("Caption the following image", image=image)</code>

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

The first one starts with the simple one . Enter a picture and add a description, a cute beaver swimming in the water (super cute, think rua).

<code>agent.run("Read the following text out loud", text=text)</code>

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

The second one is not difficult, just convert text to speech.

<code>agent.run("In the following `document`, where will the TRRF Scientific Advisory Council Meeting take place?",document=document,)</code>

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

This is a bit more difficult. The requirement for input is to say where the Scientific Advisory Committee meetings will be held.

Of course, for AI, retrieving the last line also finds the answer.

Before using agent.run, users need to instantiate an agent, which is a large language model (LLM).

Researchers provide support for OpenAI models, as well as open source alternatives from BigCode and OpenAssistant.

Although OpenAI's model performance is better, users must have an OpenAI API key, so it is not free to use.

Hugging Face said it is providing free access endpoints for models such as BigCode and OpenAssistant.

First, users need to install the agent add-on.

<code>pip install transformers[agents]</code>

To use the OpenAI model, the user needs to instantiate an OpenAiAgent after installing the OpenAI dependency:

<code>pip install openaifrom transformers import OpenAiAgentagent = OpenAiAgent(model="text-davinci-003", api_key="<your_api_key>")</your_api_key></code>

The user needs to use BigCode Or OpenAssistant, you must log in first to be able to access the API:

<code>from huggingface_hub import loginlogin("<your_token>")</your_token></code>

Then, instantiate the agent:

<code>from transformers import HfAgent# Starcoderagent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoder")# StarcoderBase# agent = HfAgent("https://api-inference.huggingface.co/models/bigcode/starcoderbase")# OpenAssistant# agent = HfAgent(url_endpoint="https://api-inference.huggingface.co/models/OpenAssistant/oasst-sft-4-pythia-12b-epoch-3.5")</code>

This is Use the inference API currently provided by Hugging Face for free. If the user has their own inference endpoint, they can replace the above URL.

StarCoder and OpenAssistant are free to use and perform well on simple tasks.

然而,在处理更复杂的提示时,检查点就不成立了。如果用户面临这样的问题,可以尝试一下OpenAI模型,虽然很遗憾它不是开源的,但胜在表现不错。

单一执行方法是在使用代理的run()方法时使用的:

<code>agent.run("Draw me a picture of rivers and lakes.")</code>

它自动选择适合你要执行的任务的工具(或工具)并适当地运行它们。它可以在同一指令中执行一个或几个任务(你的指令越复杂,就越有可能失败)。

<code>agent.run("Draw me a picture of the sea then transform the picture to add an island")</code>

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

每个run()操作都是独立的,所以你可以用不同的任务连续运行几次。

请注意,用户的智能体只是一个大语言模型,所以prompt中的小变化可能产生完全不同的结果。尽可能清楚地解释要执行的任务是很重要的。

研究人员深入地讨论了如何写出更好的prompt。

如果你想在整个执行过程中保持一个状态,或者向智能体传递非文本对象,你可以通过指定变量来做到这一点。

例如,你可以生成第一张河流和湖泊的图片,并要求模型通过以下方式更新该图片以增加一个岛屿:

<code>picture = agent.run("Generate a picture of rivers and lakes.")updated_picture = agent.run("Transform the image in `picture` to add an island to it.", picture=picture)agent.chat("Generate a picture of rivers and lakes")</code>

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

这里让系统生成一张河流湖泊的照片。

<code>agent.chat("Transform the picture so that there is a rock in there")</code>

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

下一步,研究人员又让系统给原图中加一个岛屿。

当用户想保持跨指令的状态时,这是一个很有趣的方法。

它更适合于实验,但往往在单条指令而不是复杂指令方面会好很多。

如果你想传递非文本类型或特定的提示,这个方法也可以接受参数。

要了解如何自己设置远程执行器工具,研究人员建议用户阅读自定义工具指南。

为了与远程工具一起运行,在run()或chat()中指定remote=True就可以了。

例如,以下命令可以在任何设备上有效地运行,不需要大量的RAM或GPU:

<code>agent.run("Draw me a picture of rivers and lakes", remote=True)</code>

对chat()来说也是一样的:

<code>agent.chat("Draw me a picture of rivers and lakes", remote=True)</code>

网友表示,Transformers Agent就像AutoGPT一样。

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

还有人表示,Transformers Agent打开了自然语言编程的大门,可以想象,未来的操作系统就是智能模型,人类通过自然语言编排任务,越来越多的非开发者可以自己实现各种计算机应用。

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

什么是工具?什么是智能体?

Transformers Agents整体的运作流程简单分为四步:

设定目标、提供工具、展示示例、下达任务。

智能体会使用链式思考推理来确定其任务,并用提供的工具输出Python代码。

如何安装和使用,官方给出了具体步骤。

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

https://www.php.cn/link/e4f67a0e4293245fba713c412fc63e28

其中,这里的「智能体」指的是,一个大型语言模型。通过提示LLM,让其访问特定的一组工具。

因为LLM非常擅长生成较小的代码样本,所以API利用了这一点优势。

你可以用抱抱脸自家的OpenAssistant、StarCoder,甚至还可以用OpenAI的模型。

提示LLM给出一个小的代码样本,并用一组工具执行一个任务。这个提示包括,给智能体的任务,以及工具的描述。

这样,「智能体」就可以找到所使用工具的文档,特别是预期的输入和输出,并可以生成相关的代码。

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

而「工具」就非常好理解,是一个单独的函数,带有名称和描述。

然后,使用这些工具的描述来提示「智能体」,作用就在于可以像智能体展示如何用工具来执行查询中的请求内容。

再之后,通过利用Python解释器在与工具一起上传的一组输入中执行代码。

如果唯一调用的函数是你自己提供的工具和print函数,那么,开发者会在可执行内容上受到限制。当然了,抱抱脸社区的工具,是比较安全的。

除此之外,HuggingFace在Transformers Agents中还集成了以下工具:

- 文档问答:给定一个图像格式的文档(PDF),回答文档的问题(Donut) 

- 文本问答:给定一个长文本和一个问题,回答文本中的问题(Flan-T5) 

- 无条件给图像加标题:(BLIP) 

- 图像问答:给定一个图像,回答关于这个图像的问题(VILT) 

- 图像分割:给定一个图像和一个提示,输出该提示的分割掩码(CLIPSeg) 

- 语音转文本:给定一个音频记录,将语音转录为文本(Whisper) 

- 文本到语音:将文本转换为语音(SpeechT5) 

- 零样本文本分类:给定一个文本和一列标签,确定该文本与哪个标签最对应(BART) 

- 文本总结:用一个或几个句子来总结一个长文本(BART) 

- 翻译:将文本翻译成一种语言(NLLB)

这些工具都内置在Transformers中,也可以手动使用,比如:

<code>from transformers import load_tooltool = load_tool("text-to-speech")audio = tool("This is a text to speech tool")</code>

此外,还有一些定制的工具集成在Transformers Agents中,其中包括文本下载器、文本到图像的扩散模型stable diffusion、图像变换instruct pix2pix stable diffusion,以及文本到视频damo-vilab。

官方给出了一个自定义工具和提示的教程:

AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace

https://www.php.cn/link/735a8b95123648555736192cd3978bc1

代码生成

如上,已经展示了如何使用Transformers Agents流程。

但是,智能体只生成代码,通过使用非常受限的Python解释器执行这些代码。

如果你希望使用在不同设置中生成的代码,可以提示智能体返回代码,对工具定义,并准确导入。

比如,根据以下步骤实现:

<code>agent.run("Draw me a picture of rivers and lakes", return_code=True)</code>

返回以下代码:

<code>from transformers import load_toolimage_generator = load_tool("huggingface-tools/text-to-image")image = image_generator(prompt="rivers and lakes")</code>

然后,你就可以修改和执行自己的工具了。

The above is the detailed content of AutoGPT by hand! Let ChatGPT choose 100,000+ AI models, officially produced by HuggingFace. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:51cto.com. If there is any infringement, please contact admin@php.cn delete