Skip to content

Instantly share code, notes, and snippets.

@igaiga
Last active November 3, 2023 02:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save igaiga/9a38e557aef1e0f1925a48958ef2ec44 to your computer and use it in GitHub Desktop.
Save igaiga/9a38e557aef1e0f1925a48958ef2ec44 to your computer and use it in GitHub Desktop.
# $ pip install openai llama_index pypdf
from llama_index import GPTVectorStoreIndex, SimpleDirectoryReader
import openai
# APIキーを取得: https://platform.openai.com/account/api-keys
openai.api_key = "API KEYを書く"
# dataフォルダ以下のPDFファイルの読み込み
documents = SimpleDirectoryReader("data").load_data()
index = GPTVectorStoreIndex.from_documents(documents)
query_engine = index.as_query_engine()
question = "〇〇について教えてください"
response = query_engine.query(question)
print(response)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment