LlamaIndex: Adding Personal Data to LLMs
  • AI Chat
  • Code
  • Report
  • Beta
    Spinner
    %%capture
    %pip install llama-index openai pypdf

    Loading Data and Creating the Index

    from llama_index import TreeIndex, SimpleDirectoryReader
    
    resume = SimpleDirectoryReader("Private-Data").load_data()
    new_index = TreeIndex.from_documents(resume)

    Running Query on text-davinci-003

    query_engine = new_index.as_query_engine()
    response = query_engine.query("When did Abid graduated?")
    print(response)
    response = query_engine.query("What is the name of certification that Abid received?")
    print(response)

    Saving and Loading the Context

    new_index.storage_context.persist()
    from llama_index import StorageContext, load_index_from_storage
    
    storage_context = StorageContext.from_defaults(persist_dir="./storage")
    index = load_index_from_storage(storage_context)
    
    query_engine = index.as_query_engine()
    response = query_engine.query("What is Abid's job title?")
    print(response)

    Chatbot

    query_engine = index.as_chat_engine()
    response = query_engine.chat("What is the job title of Abid in 2021?")
    print(response)
    response = query_engine.chat("What else he do during that time?")
    print(response)