Last active
August 25, 2023 14:02
-
-
Save donvito/8aa6dd23bbb4f81d928ed1d9cf6b898b to your computer and use it in GitHub Desktop.
llama_index examples
This file contains hidden or 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 logging | |
import sys | |
import openai | |
logging.basicConfig(stream=sys.stdout, level=logging.INFO) | |
logging.getLogger().addHandler(logging.StreamHandler(stream=sys.stdout)) | |
from llama_index.llms import OpenAI | |
from llama_index import ListIndex, NotionPageReader, ServiceContext | |
import os | |
os.environ["OPENAI_API_KEY"] = "" | |
openai.api_key = os.environ["OPENAI_API_KEY"] | |
chatgpt = OpenAI(temperature=0, model="gpt-3.5-turbo") | |
service_context = ServiceContext.from_defaults(llm=chatgpt, chunk_size=1024) | |
integration_token = "" | |
page_ids = [""] | |
documents = NotionPageReader(integration_token=integration_token).load_data( | |
page_ids=page_ids | |
) | |
index = ListIndex.from_documents(documents) | |
# set Logging to DEBUG for more detailed outputs | |
query_engine = index.as_query_engine() | |
response = query_engine.query("query here") | |
print(response) |
This file contains hidden or 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 os | |
import logging | |
import sys | |
import openai | |
os.environ["OPENAI_API_KEY"] = '' | |
openai.api_key = os.environ["OPENAI_API_KEY"] | |
from llama_index.llms import OpenAI | |
from llama_index import ( | |
SimpleDirectoryReader, | |
ListIndex, | |
ServiceContext, | |
) | |
chatgpt = OpenAI(temperature=0, model="gpt-3.5-turbo") | |
service_context = ServiceContext.from_defaults(llm=chatgpt, chunk_size=1024) | |
documents = SimpleDirectoryReader("./data").load_data() | |
index = ListIndex.from_documents(documents) | |
prompt = "Summarize..." | |
response = index.as_query_engine(response_mode="tree_summarize").query(prompt) | |
print(response) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment