Package: llama-hub
LlamaHub 🦙[!CAUTION]
With the launch of LlamaIndex v0.10, we are deprecating thisllama_hubrepo - all integrations (data loaders, tools) and packs are now in the corellama-indexPython repository.
LlamaHub will continue to exist. We are revampingllamahub.aipoint to all integrations/packs/datasets available in thellama-indexrepo.Original creator: Jesse Zhang (GH:emptycrown, Twitter:@thejessezhang), who courteously donated the repo to LlamaIndex!👥ContributingInterested in contributing? Skip over to ourContribution Sectionbelow for more details.This is a simple library of all the data loaders / readers / tools / llama-packs / llama-datasets 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 inLlamaIndex,LangChainand 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 thenotebooks 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/.Usage (Usellama-hubas PyPI package)These general-purpose loaders are designed to be used as a way to load data intoLlamaIndexand/or subsequently used inLangChain.Installationpip install llama-hubLlamaIndexfromllama_indeximportVectorStoreIndexfromllama_hub.google_docsimportGoogleDocsReadergdoc_ids=['1wf-y2pd9C878Oh-FmLH7Q_BQkljdm6TQal-c1pUfrec']loader=GoogleDocsReader()documents=loader.load_data(document_ids=gdoc_ids)index=VectorStoreIndex.from_documents(documents)index.query('Where did the author go to school?')LlamaIndex Data Agentfromllama_index.agentimportOpenAIAgentimportopenaiopenai.api_key='sk-api-key'fromllama_hub.tools.google_calendarimportGoogleCalendarToolSpectool_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 thenotebooks directory.LangChainNote: Make sure you change the description of theToolto match your use case.fromllama_indeximportVectorStoreIndexfromllama_hub.google_docsimportGoogleDocsReaderfromlangchain.llmsimportOpenAIfromlangchain.chains.question_answeringimportload_qa_chain# load documentsgdoc_ids=['1wf-y2pd9C878Oh-FmLH7Q_BQkljdm6TQal-c1pUfrec']loader=GoogleDocsReader()documents=loader.load_data(document_ids=gdoc_ids)langchain_documents=[d.to_langchain_format()fordindocuments]# initialize sample QA chainllm=OpenAI(temperature=0)qa_chain=load_qa_chain(llm)question="<query here>"answer=qa_chain.run(input_documents=langchain_documents,question=question)Loader Usage (Usedownload_loaderfrom LlamaIndex)You can also use the loaders withdownload_loaderfrom LlamaIndex in a single line of code.For example, see the code snippets below using the Google Docs Loader.fromllama_indeximportVectorStoreIndex,download_loaderGoogleDocsReader=download_loader('GoogleDocsReader')gdoc_ids=['1wf-y2pd9C878Oh-FmLH7Q_BQkljdm6TQal-c1pUfrec']loader=GoogleDocsReader()documents=loader.load_data(document_ids=gdoc_ids)index=VectorStoreIndex.from_documents(documents)index.query('Where did the author go to school?')Llama-Pack UsageLlama-packs can be downloaded using thellamaindex-clitool that comes withllama-index:llamaindex-clidownload-llamapackZephyrQueryEnginePack--download-dir./zephyr_packOr with thedownload_llama_packfunction directly:fromllama_index.llama_packimportdownload_llama_pack# download and install dependenciesLlavaCompletionPack=download_llama_pack("LlavaCompletionPack","./llava_pack")Llama-Dataset Usage(NOTE: in what follows we present the pattern for producing a RAG benchmark with
theRagEvaluatorPackover aLabelledRagDataset. However, there are also other
types of llama-datasets such asLabelledEvaluatorDatasetand corresponding llama-packs
for producing benchmarks on their respective tasks. They all follow the similar
usage pattern. Please refer to the README's to learn more on each type of
llama-dataset.)The primary use of llama-dataset is for evaluating the performance of a RAG system.
In particular, it serves as a new test set (in traditional machine learning speak)
for one to build a RAG over, predict on, and subsequently perform evaluations
comparing the predicted response versus the reference response. To perform the
evaluation, the recommended usage pattern involves the application of theRagEvaluatorPack. We recommend reading thedocsfor the "Evaluation" module for
more information on all of our llama-dataset's.fromllama_index.llama_datasetimportdownload_llama_datasetfromllama_index.llama_packimportdownload_llama_packfromllama_indeximportVectorStoreIndex# download and install dependencies for benchmark datasetrag_dataset,documents=download_llama_dataset("PaulGrahamEssayDataset","./data")# build basic RAG systemindex=VectorStoreIndex.from_documents(documents=documents)query_engine=VectorStoreIndex.as_query_engine()# evaluate using the RagEvaluatorPackRagEvaluatorPack=download_llama_pack("RagEvaluatorPack","./rag_evaluator_pack")rag_evaluator_pack=RagEvaluatorPack(rag_dataset=rag_dataset,query_engine=query_engine)benchmark_df=rag_evaluate_pack.run()# async arun() supported as wellLlama-datasets can also be downloaded directly usingllamaindex-cli, which comes installed with thellama-indexpython package:llamaindex-clidownload-llamadatasetPaulGrahamEssayDataset--download-dir./dataAfter downloading them fromllamaindex-cli, you can inspect the dataset and
it source files (stored in a directory/source_files) then load them into python:fromllama_indeximportSimpleDirectoryReaderfromllama_index.llama_datasetimportLabelledRagDatasetrag_dataset=LabelledRagDataset.from_json("./data/rag_dataset.json")documents=SimpleDirectoryReader(input_dir="./data/source_files").load_data()How to add a loader/tool/llama-packAdding a loader/tool/llama-pack simply requires forking this repo and making a Pull Request. The Llama Hub website will update automatically when a newllama-hubrelease is made. However, please keep in mind the following guidelines when making your PR.Step 0: Setup virtual environment, install Poetry and dependenciesCreate a new Python virtual environment. The command below creates an environment in.venv,
and activates it:python-mvenv.venvsource.venv/bin/activateif you are in windows, use the following to activate your virtual environment:.venv\scripts\activateInstall poetry:pipinstallpoetryInstall the required dependencies (this will also installllama_index):poetryinstallThis will create an editable install ofllama-hubin your venv.Step 1: Create a new directoryFor loaders, create a new directory inllama_hub, for tools create a directory inllama_hub/tools, and for llama-packs create a directory inllama_hub/llama_packsIt 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__.pyfile specifying the module's public interface with__all__, abase.pyfile which will contain your loader implementation, and, if needed, arequirements.txtfile 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 thellama_hubdirectory. Just remember to put your dependencies into arequirements.txtfile../add_loader.sh [NAME_OF_NEW_DIRECTORY]Step 2: Write your READMEInside your new directory, create aREADME.mdthat 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.Step 3: Add your loader to the library.json fileFinally, add your loader to thellama_hub/library.jsonfile (or for the equivalentlibrary.jsonundertools/orllama-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.Step 4: Make a Pull Request!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!How to add a llama-datasetSimilar to the process of adding a tool / loader / llama-pack, adding a llama-
datset also requires forking this repo and making a Pull Request. However, for a
llama-dataset, only its metadata is checked into this repo. The actual dataset
and it's source files are instead checked into another Github repo, that is thellama-datasets repository. You will need to fork and clone that repo in addition to forking and cloning this one.Please ensure that when you clone the llama-datasets repository, that you set
the environment variableGIT_LFS_SKIP_SMUDGEprior to calling thegit clonecommand:# for bashGIT_LFS_SKIP_SMUDGE=1gitclonegit@github.com:<your-github-user-name>/llama-datasets.git# for sshGIT_LFS_SKIP_SMUDGE=1gitclonehttps://github.com/<your-github-user-name>/llama-datasets.git# for https# for windows its done in two commandssetGIT_LFS_SKIP_SMUDGE=1gitclonegit@github.com:<your-github-user-name>/llama-datasets.git# for sshsetGIT_LFS_SKIP_SMUDGE=1gitclonehttps://github.com/<your-github-user-name>/llama-datasets.git# for httpsThe high-level steps for adding a llama-dataset are as follows:Create aLabelledRagDataset(the initial class of llama-dataset made available on llama-hub)Generate a baseline result with a RAG system of your own choosing on theLabelledRagDatasetPrepare the dataset's metadata (card.jsonandREADME.md)Submit a Pull Request to this repo to check in the metadataSubmit a Pull Request to thellama-datasets repositoryto check in theLabelledRagDatasetand the source filesTo assist with the submission process, we have prepared asubmission template
notebookthat walks you through the above-listed steps. We highly recommend
that you use this template notebook.(NOTE: you can use the above process for submitting any of our other supported
types of llama-datasets such as theLabelledEvaluatorDataset.)Running testspython3.9-mvenv.venvsource.venv/bin/activatepip3install-rtest_requirements.txt

poetryrunmaketestChangelogIf you want to track the latest version updates / see which loaders are added to each release, take a look at ourfull changelog here!FAQHow do I test my loader before it's merged?There is an argument calledloader_hub_urlindownload_loaderthat defaults to the main branch of this repo. You can set it to your branch or fork to test your new loader.Should I create a PR against LlamaHub or the LlamaIndex repo directly?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 theLlamaIndex repo.How can I get a verified badge on LlamaHub?We have just started offering badges to our contributors. At the moment, we're focused on our early adopters and official partners, but we're gradually opening up badge consideration to all submissions. If you're interested in being considered, please review the criteria below and if everything aligns, feel free to contact us viacommunity Discord.We are still refining our criteria but here are some aspects we consider:QualityCode Quality illustrated by the use of coding standards and style guidelines.Code readability and proper documentation.UsabilitySelf-contained module with no external links or libraries, and it is easy to run.Module should not break any existing unit tests.SafetySafety considerations, such as proper input validation, avoiding SQL injection, and secure handling of user data.Community Engagement & FeedbackThe module's usefulness to the library's users as gauged by the number of likes, downloads, etc.Positive feedback from module users.Note:It's possible that we decide to award a badge to a subset of your submissions based on the above criteria.Being a regular contributor doesn't guarantee a badge, we will still look at each submission individually.Other questions?Feel free to hop into thecommunity Discordor tag the officialTwitter account!