Back to Llama Index

change this to your email

llama-index-integrations/readers/llama-index-readers-openalex/examples/demo.ipynb

0.14.211.1 KB
Original Source
python
from llama_hub.openalex import OpenAlexReader
from llama_index.llms import OpenAI
from llama_index.query_engine import CitationQueryEngine
from llama_index import (
    VectorStoreIndex,
    ServiceContext,
)
from llama_index.response.notebook_utils import display_response
python
# change this to your email
openalex_reader = OpenAlexReader(email="[email protected]")
python
query = "biases in large language models"
python
works = openalex_reader.load_data(query, full_text=False)
service_context = ServiceContext.from_defaults(
    llm=OpenAI(model="gpt-3.5-turbo", temperature=0)
)
index = VectorStoreIndex.from_documents(works, service_context=service_context)

query_engine = CitationQueryEngine.from_args(
    index,
    similarity_top_k=10,
    citation_chunk_size=1024,
)
# query the index
response = query_engine.query(
    "list the biases in large language models in a markdown table"
)
python
# import mardown ipython
from IPython.display import Markdown

Markdown(response.response)
python
display_response(
    response, show_source=True, source_length=100, show_source_metadata=True
)