{ "cells": [ { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "\"Open" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "# Github Repo Reader" ] }, { "attachments": {}, "cell_type": "markdown", "metadata": {}, "source": [ "If you're opening this Notebook on colab, you will probably need to install LlamaIndex 🦙." ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%pip install llama-index-readers-github" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "!pip install llama-index" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "# This is due to the fact that we use asyncio.loop_until_complete in\n", "# the DiscordReader. Since the Jupyter kernel itself runs on\n", "# an event loop, we need to add some help with nesting\n", "import nest_asyncio\n", "\n", "nest_asyncio.apply()" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "env: OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n" ] } ], "source": [ "%env OPENAI_API_KEY=sk-xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", "from llama_index.core import VectorStoreIndex\n", "from llama_index.readers.github import GithubRepositoryReader, GithubClient\n", "from IPython.display import Markdown, display\n", "import os" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "%env GITHUB_TOKEN=github_pat_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx\n", "github_token = os.environ.get(\"GITHUB_TOKEN\")\n", "owner = \"jerryjliu\"\n", "repo = \"llama_index\"\n", "branch = \"main\"\n", "\n", "github_client = GithubClient(github_token=github_token, verbose=True)\n", "\n", "documents = GithubRepositoryReader(\n", " github_client=github_client,\n", " owner=owner,\n", " repo=repo,\n", " use_parser=False,\n", " verbose=False,\n", " filter_directories=(\n", " [\"docs\"],\n", " GithubRepositoryReader.FilterType.INCLUDE,\n", " ),\n", " filter_file_extensions=(\n", " [\n", " \".png\",\n", " \".jpg\",\n", " \".jpeg\",\n", " \".gif\",\n", " \".svg\",\n", " \".ico\",\n", " \"json\",\n", " \".ipynb\",\n", " ],\n", " GithubRepositoryReader.FilterType.EXCLUDE,\n", " ),\n", ").load_data(branch=branch)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "index = VectorStoreIndex.from_documents(documents)" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "query_engine = index.as_query_engine()\n", "response = query_engine.query(\n", " \"What is the difference between VectorStoreIndex and SummaryIndex?\",\n", " verbose=True,\n", ")" ] }, { "cell_type": "code", "execution_count": null, "metadata": {}, "outputs": [], "source": [ "display(Markdown(f\"{response}\"))" ] } ], "metadata": { "kernelspec": { "display_name": "llama_index-github-reader", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3" }, "vscode": { "interpreter": { "hash": "5bc2ab08ee48b6366504a28e3231c27a37c154a347ee8ac6184b716eff7bdbcd" } } }, "nbformat": 4, "nbformat_minor": 2 }