LlamaHub 演示¶
这里我们简单概述了如何在 LlamaHub 中使用数据加载器和工具(用于代理)。
注意事项:
- 你可以在 LlamaHub 中点击每个模块并查看代码片段,了解如何使用所有功能。
- 此外,你可以在这里找到完整的代理工具列表。
- 在本指南中,我们将演示如何使用
download_loader和download_tool。你还可以将llama-hub作为包进行安装。
In [ ]
已复制!
%pip install llama-index-agent-openai
%pip install llama-index-readers-web
%pip install llama-index-tools-google
%pip install llama-index-agent-openai %pip install llama-index-readers-web %pip install llama-index-tools-google
In [ ]
已复制!
from llama_index.readers.web import SimpleWebPageReader
from llama_index.readers.web import SimpleWebPageReader
In [ ]
已复制!
reader = SimpleWebPageReader(html_to_text=True)
reader = SimpleWebPageReader(html_to_text=True)
In [ ]
已复制!
docs = reader.load_data(urls=["https://eugeneyan.com/writing/llm-patterns/"])
docs = reader.load_data(urls=["https://eugeneyan.com/writing/llm-patterns/"])
In [ ]
已复制!
print(docs[0].get_content()[:400])
print(docs[0].get_content()[:400])
# [eugeneyan](/) * [Start Here](/start-here/ "Start Here") * [Writing](/writing/ "Writing") * [Speaking](/speaking/ "Speaking") * [Prototyping](/prototyping/ "Prototyping") * [About](/about/ "About") # Patterns for Building LLM-based Systems & Products [ [llm](/tag/llm/) [engineering](/tag/engineering/) [production](/tag/production/) ] · 66 min read > Discussions on [HackerNews](htt
现在你可以将这些文档插入到你的下游 LlamaIndex 管道中。
In [ ]
已复制!
from llama_index.core import VectorStoreIndex
index = VectorStoreIndex.from_documents(docs)
query_engine = index.as_query_engine()
from llama_index.core import VectorStoreIndex index = VectorStoreIndex.from_documents(docs) query_engine = index.as_query_engine()
In [ ]
已复制!
response = query_engine.query("What are ways to evaluate LLMs?")
print(str(response))
response = query_engine.query("What are ways to evaluate LLMs?") print(str(response))
使用代理工具规范¶
在这个例子中,我们将演示如何加载一个代理工具。
In [ ]
已复制!
from llama_index.tools.google import GmailToolSpec
from llama_index.tools.google import GmailToolSpec
In [ ]
已复制!
tool_spec = GmailToolSpec()
tool_spec = GmailToolSpec()
In [ ]
已复制!
# plug into your agent
from llama_index.agent.openai import OpenAIAgent
# plug into your agent from llama_index.agent.openai import OpenAIAgent
In [ ]
已复制!
agent = OpenAIAgent.from_tools(tool_spec.to_tool_list())
agent = OpenAIAgent.from_tools(tool_spec.to_tool_list())
In [ ]
已复制!
agent.chat("What is my most recent email")
agent.chat("What is my most recent email")