Created
May 9, 2023 12:29
-
-
Save EnkrateiaLucca/5730c38f6cacf88c05d6e564a11c2219 to your computer and use it in GitHub Desktop.
CLI tool to query any YouTube video using langchain
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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