Skip to main content

HuggingGPT

HuggingGPT的实现。HuggingGPT是将LLMs(ChatGPT)与ML社区(Hugging Face)连接起来的系统。

设置工具

我们设置了来自Transformers Agent的可用工具。它包括Transformers支持的一系列工具库,以及一些定制工具,如图像生成器、视频生成器、文本下载器和其他工具。

from transformers import load_tool
hf_tools = [
load_tool(tool_name)
for tool_name in [
"document-question-answering",
"image-captioning",
"image-question-answering",
"image-segmentation",
"speech-to-text",
"summarization",
"text-classification",
"text-question-answering",
"translation",
"huggingface-tools/text-to-image",
"huggingface-tools/text-to-video",
"text-to-speech",
"huggingface-tools/text-download",
"huggingface-tools/image-transformation",
]
]

设置模型和HuggingGPT

我们创建了一个HuggingGPT的实例,并使用ChatGPT作为控制器来管理上述工具。

from langchain.llms import OpenAI
from langchain_experimental.autonomous_agents import HuggingGPT
# %env OPENAI_API_BASE=http://localhost:8000/v1
llm = OpenAI(model_name="gpt-3.5-turbo")
agent = HuggingGPT(llm, hf_tools)

运行示例

给定一段文本,展示相关的图像和视频。

agent.run("please show me a video and an image of 'a boy is running'")