llm = OpenAI(model="gpt-4", temperature=0.1, max_tokens=256)
# editing prompt & building index
QA_PROMPT_TMPL = (
"XXX."
"---------------------\n"
"{context_str}"
"\n---------------------\n"
"Given this information, please answer the question: {query_str}\n"
)
QA_PROMPT = QuestionAnswerPrompt(QA_PROMPT_TMPL)
index = GPTVectorStoreIndex.from_documents(documents)
retriever = VectorIndexRetriever(
index=index,
similarity_top_k=5,
)
query_engine = RetrieverQueryEngine.from_args(
retriever,
response_mode="compact",
text_qa_template=QA_PROMPT,
)
from llama_index import ServiceContext, set_global_service_context llm = OpenAI(...) service_context = ServiceContext.from_defaults(llm=llm) set_global_service_context(service_context)