I'm using the llama-index code below to create an index object from a saved text corpus. I'm then loading the saved index object and querying it to produce a response. I'm using an openai apikey so I can use a chatgpt model for the LLM. I'm wondering if I could use the same code or a modified version to use an open source LLM like for example llama-7b-chat that I have downloaded the model weights for on my local machine. does anyone know if that is possible and can you suggest how I would need to update the code below to use an opensource LLM hosted locally?
code:
# creating index from corpus
from config import api_key, old_api_key, personal_api_key
import os
os.environ['OPENAI_API_KEY'] = old_api_key
# Load you data into 'Documents' a custom type by LlamaIndex
# from typing_extensions import Protocol
from llama_index import SimpleDirectoryReader
documents = SimpleDirectoryReader('./data').load_data()
from llama_index import GPTVectorStoreIndex
index = GPTVectorStoreIndex.from_documents(documents)
# save storage context
storage_context_dict=index.storage_context.to_dict()
import json
# Serialize data into file:
json.dump( storage_context_dict, open( "general_attributes_storage_context_dict.json", 'w' ) )
# load saved context
import os
# plus
os.environ['OPENAI_API_KEY'] = old_api_key
# using previously saved index
import json
saved_context=json.load( open( "general_attributes_storage_context_dict.json" ) )
from llama_index import StorageContext, load_index_from_storage
# rebuild storage context
storage_context=StorageContext.from_dict(saved_context)
stored_index=load_index_from_storage(storage_context)
query_engine = stored_index.as_query_engine()
response = query_engine.query("some question")
print(response)