Skip to content

Instantly share code, notes, and snippets.

@hlwhl
Created March 26, 2023 08:18
Show Gist options
  • Save hlwhl/42691d8b960b402adde7b12b3d7e7b37 to your computer and use it in GitHub Desktop.
Save hlwhl/42691d8b960b402adde7b12b3d7e7b37 to your computer and use it in GitHub Desktop.
talk to github repo using llama_index
from llama_index.readers.llamahub_modules.github_repo import GithubClient, GithubRepositoryReader
from llama_index import download_loader
import pickle
import os
from llama_index import GPTSimpleVectorIndex, LLMPredictor
from langchain.chat_models import ChatOpenAI
from langchain import OpenAI
download_loader("GithubRepositoryReader")
docs = None
if os.path.exists("docs.pkl"):
with open("docs.pkl", "rb") as f:
docs = pickle.load(f)
if docs is None:
github_client = GithubClient("GITHUB KEY")
loader = GithubRepositoryReader(
github_client,
owner="hlwhl",
repo="webview_cef",
# filter_directories = (["gpt_index", "docs"], GithubRepositoryReader.FilterType.INCLUDE),
filter_file_extensions=(
[".dart"], GithubRepositoryReader.FilterType.INCLUDE),
verbose=True,
concurrent_requests=10,
)
docs = loader.load_data(branch="main")
with open("docs.pkl", "wb") as f:
pickle.dump(docs, f)
OpenAI()
llm_predictor = LLMPredictor(llm=ChatOpenAI(
openai_api_key="OPENAI_KEY",
temperature=0,
model_name="gpt-3.5-turbo",
streaming=True,
))
index = GPTSimpleVectorIndex(docs, llm_predictor=llm_predictor)
response = index.query("请用中文回答这些代码是干什么用的?")
print(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment