Spaces:
Sleeping
Sleeping
File size: 1,313 Bytes
db694c4 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
import utils
import os
import openai
from llama_index import SimpleDirectoryReader
from llama_index import Document
from llama_index import VectorStoreIndex
from llama_index import ServiceContext
from llama_index.llms import OpenAI
from llama_index.embeddings import HuggingFaceEmbedding
openai.api_key = utils.get_openai_api_key()
if __name__ == "__main__":
documents = SimpleDirectoryReader(
input_files=["./raw_documents/HI_knowledge_base.pdf"]
).load_data()
document = Document(text="\n\n".join([doc.text for doc in documents]))
### gpt-4-1106-preview
### gpt-3.5-turbo-1106 / gpt-3.5-turbo
llm = OpenAI(model="gpt-3.5-turbo-1106", temperature=0.1)
embed_model = HuggingFaceEmbedding(model_name="BAAI/bge-small-en-v1.5")
service_context = ServiceContext.from_defaults(llm=llm, embed_model=embed_model)
index = VectorStoreIndex.from_documents([document], service_context=service_context)
query_engine = index.as_query_engine()
response = query_engine.query(
("Intermediate and Long Term Care (ILTC) services are for those who need further care and"
"treatment after discharge from the hospital, who may need assistance with their activities of"
"daily living. This can be through"
)
)
print(str(response)) |