Original creator: Jesse Zhang (GH: emptycrown, Twitter: @thejessezhang), who courteously donated the repo to LlamaIndex!
This is a simple library of all the data loaders / readers / tools / llama-packs that have been created by the community. The goal is to make it extremely easy to connect large language models to a large variety of knowledge sources. These are general-purpose utilities that are meant to be used in LlamaIndex, LangChain and more!.
Loaders and readers allow you to easily ingest data for search and retrieval by a large language model, while tools allow the models to both read and write to third party data services and sources. Ultimately, this allows you to create your own customized data agent to intelligently work with you and your data to unlock the full capability of next level large language models.
For a variety of examples of data agents, see the notebooks directory. You can find example Jupyter notebooks for creating data agents that can load and parse data from Google Docs, SQL Databases, Notion, and Slack, and also manage your Google Calendar, and Gmail inbox, or read and use OpenAPI specs.
For an easier way to browse the integrations available, check out the website here: https://llamahub.ai/.
![Screenshot 2023-07-17 at 6 12 32 PM](https://private-user-images.githubusercontent.com/10040285/253985887-5e344de4-4aca-4f6c-9944-46c00baa5eb2.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3MjUwODE1ODUsIm5iZiI6MTcyNTA4MTI4NSwicGF0aCI6Ii8xMDA0MDI4NS8yNTM5ODU4ODctNWUzNDRkZTQtNGFjYS00ZjZjLTk5NDQtNDZjMDBiYWE1ZWIyLnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNDA4MzElMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjQwODMxVDA1MTQ0NVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRhOTE0ZmQ1NjhhZWFkMGRjMDBhZWNiN2IwNDM0ZGJiZTY0MGMyYmE1NmZhZDdjNzllYmU4OTczYTg5ZjM5YjEmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0JmFjdG9yX2lkPTAma2V5X2lkPTAmcmVwb19pZD0wIn0.-GDa_ravXFIYEP2VGRiFoOdAdmQ7vOIe6k1x9tj8q98)
These general-purpose loaders are designed to be used as a way to load data into LlamaIndex and/or subsequently used in LangChain.
pip install llama-hub
from llama_index import GPTVectorStoreIndex
from llama_hub.google_docs import GoogleDocsReader
gdoc_ids = ['1wf-y2pd9C878Oh-FmLH7Q_BQkljdm6TQal-c1pUfrec']
loader = GoogleDocsReader()
documents = loader.load_data(document_ids=gdoc_ids)
index = GPTVectorStoreIndex.from_documents(documents)
index.query('Where did the author go to school?')
from llama_index.agent import OpenAIAgent
import openai
openai.api_key = 'sk-api-key'
from llama_hub.tools.google_calendar import GoogleCalendarToolSpec
tool_spec = GoogleCalendarToolSpec()
agent = OpenAIAgent.from_tools(tool_spec.to_tool_list())
agent.chat('what is the first thing on my calendar today')
agent.chat("Please create an event for tomorrow at 4pm to review pull requests")
For a variety of examples of creating and using data agents, see the notebooks directory.
Note: Make sure you change the description of the Tool
to match your use case.
from llama_index import GPTVectorStoreIndex
from llama_hub.google_docs import GoogleDocsReader
from langchain.llms import OpenAI
from langchain.chains.question_answering import load_qa_chain
# load documents
gdoc_ids = ['1wf-y2pd9C878Oh-FmLH7Q_BQkljdm6TQal-c1pUfrec']
loader = GoogleDocsReader()
documents = loader.load_data(document_ids=gdoc_ids)
langchain_documents = [d.to_langchain_format() for d in documents]
# initialize sample QA chain
llm = OpenAI(temperature=0)
qa_chain = load_qa_chain(llm)
question="<query here>"
answer = qa_chain.run(input_documents=langchain_documents, question=question)
You can also use the loaders with download_loader
from LlamaIndex in a single line of code.
For example, see the code snippets below using the Google Docs Loader.
from llama_index import GPTVectorStoreIndex, download_loader
GoogleDocsReader = download_loader('GoogleDocsReader')
gdoc_ids = ['1wf-y2pd9C878Oh-FmLH7Q_BQkljdm6TQal-c1pUfrec']
loader = GoogleDocsReader()
documents = loader.load_data(document_ids=gdoc_ids)
index = GPTVectorStoreIndex.from_documents(documents)
index.query('Where did the author go to school?')
Llama-packs can be downloaded using the llamaindex-cli
tool that comes with llama-index
:
llamaindex-cli download-llamapack ZephyrQueryEnginePack --download-dir ./zephyr_pack
Or with the download_llama_pack
function directly:
from llama_index.llama_packs import download_llama_pack
# download and install dependencies
LlavaCompletionPack = download_llama_pack(
"LlavaCompletionPack", "./llava_pack"
)
Adding a loader/tool/llama-pack simply requires forking this repo and making a Pull Request. The Llama Hub website will update automatically when a new llama-hub
release is made. However, please keep in mind the following guidelines when making your PR.
Create a new Python virtual environment. The command below creates an environment in .venv
,
and activates it:
python -m venv .venv
source .venv/bin/activate
if you are in windows, use the following to activate your virtual environment:
.venv\scripts\activate
Install poetry:
pip install poetry
Install the required dependencies (this will also install llama_index
):
poetry install
This will create an editable install of llama-hub
in your venv.
For loaders, create a new directory in llama_hub
, for tools create a directory in llama_hub/tools
, and for llama-packs create a directory in llama_hub/llama_packs
It can be nested within another, but name it something unique because the name of the directory will become the identifier for your loader (e.g. google_docs
). Inside your new directory, create a __init__.py
file specifying the module's public interface with __all__
, a base.py
file which will contain your loader implementation, and, if needed, a requirements.txt
file to list the package dependencies of your loader. Those packages will automatically be installed when your loader is used, so no need to worry about that anymore!
If you'd like, you can create the new directory and files by running the following script in the llama_hub
directory. Just remember to put your dependencies into a requirements.txt
file.
./add_loader.sh [NAME_OF_NEW_DIRECTORY]
Inside your new directory, create a README.md
that mirrors that of the existing ones. It should have a summary of what your loader or tool does, its inputs, and how it is used in the context of LlamaIndex and LangChain.
Finally, add your loader to the llama_hub/library.json
file (or for the equivilant library.json
under tools/
or llama-packs/
) so that it may be used by others. As is exemplified by the current file, add the class name of your loader or tool, along with its ID, author, etc. This file is referenced by the Llama Hub website and the download function within LlamaIndex.
Create a PR against the main branch. We typically review the PR within a day. To help expedite the process, it may be helpful to provide screenshots (either in the PR or in the README directly) Show your data loader or tool in action!
python3.9 -m venv .venv
source .venv/bin/activate
pip3 install -r test_requirements.txt
poetry run pytest tests
If you want to track the latest version updates / see which loaders are added to each release, take a look at our full changelog here!
There is an argument called loader_hub_url
in download_loader
that defaults to the main branch of this repo. You can set it to your branch or fork to test your new loader.
If you have a data loader PR, by default let's try to create it against LlamaHub! We will make exceptions in certain cases (for instance, if we think the data loader should be core to the LlamaIndex repo).
For all other PR's relevant to LlamaIndex, let's create it directly against the LlamaIndex repo.
Feel free to hop into the community Discord or tag the official Twitter account!