Skip to content

Instantly share code, notes, and snippets.

@EnkrateiaLucca
Created May 9, 2023 12:29
Show Gist options
  • Save EnkrateiaLucca/5730c38f6cacf88c05d6e564a11c2219 to your computer and use it in GitHub Desktop.
Save EnkrateiaLucca/5730c38f6cacf88c05d6e564a11c2219 to your computer and use it in GitHub Desktop.
CLI tool to query any YouTube video using langchain
import argparse
from langchain.document_loaders import YoutubeLoader
from langchain.indexes import VectorstoreIndexCreator
def main():
parser = argparse.ArgumentParser(description='Query YouTube videos using ChatGPT with langchain package.')
parser.add_argument('url', help='YouTube video URL')
parser.add_argument('query', help='The query you want to ask about the video')
parser.add_argument('-a', '--add_video_info', action='store_true', help='Add video information (default: False)')
args = parser.parse_args()
loader = YoutubeLoader.from_youtube_url(args.url, add_video_info=args.add_video_info)
docs = loader.load()
index = VectorstoreIndexCreator()
index = index.from_documents(docs)
response = index.query(args.query)
print("Response:", response)
if __name__ == "__main__":
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment