Skip to content

Instantly share code, notes, and snippets.

@DavidZirinsky
Last active September 8, 2023 21:52
Show Gist options
  • Save DavidZirinsky/5672a9a3437bc86e66567ed9ee090a8c to your computer and use it in GitHub Desktop.
Save DavidZirinsky/5672a9a3437bc86e66567ed9ee090a8c to your computer and use it in GitHub Desktop.
How to ask questions about a git repo using chatgbt's api
# call this script with the command: python3 ask_questions_on_codebase.py
from langchain.document_loaders import GitLoader
from langchain.indexes import VectorstoreIndexCreator
import os
# if this fails, just use the bash command export OPENAI_API_KEY=YOUR_KEY_HERE
os.environ['OPENAI_API_KEY'] = 'YOUR_KEY_HERE'
os.environ['OPENAI_MODEL'] = 'text-embedding-ada-002' # specify your model here
directory_path = './example_data/test_repo2/'
if os.path.exists(directory_path):
loader = GitLoader(repo_path="./example_data/test_repo2/", branch="master")
else:
loader = GitLoader(
clone_url="https://github.com/DavidZirinsky/brush",
repo_path="./example_data/test_repo2/",
branch="master",
)
index = VectorstoreIndexCreator().from_loaders([loader])
question = "can you show me examples where AlarmManager is used?"
answer = index.query(question)
print(f"question: {question}")
print(f"answer: {answer}")
breakpoint() # breakpoint is here to avoid running the script each time you have a question
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment