code: import os
  import time
  from llama_index import ServiceContext, StorageContext, VectorStoreIndex, load_index_from_storage, set_global_service_context
  import llama_index
  from Models import Models
  from DocumentClass import DocumentClass
  
  
  class MediawikiLLM:
  
      service_context = None
      mediawiki_url = None
      api_url = None
  
      DocumentClass = None
      index = None
      index_filename = None
      query_engine = None
  
      def __init__(self, mediawiki_url, api_url):
  
          self.mediawiki_url = mediawiki_url
          self.DocumentClass = DocumentClass(api_url)
  
          llm = Models.CreateLlamaCCP(
              model_url=os.getenv("MODEL_URL"), model_path=os.getenv("MODEL_PATH"))
  
          # llm = Models.CreateHuggingFaceLLM(model_name="Writer/camel-5b-hf")
  
          self.service_context = ServiceContext.from_defaults(
              llm=llm,
              embed_model="local",
              chunk_size=1024,
          )
  
      def init_from_mediawiki(self):
          set_global_service_context(self.service_context)
  
          if os.path.isdir(str(os.getenv("PERSISTENT_STORAGE_DIR"))):
              storage_context = StorageContext.from_defaults(
                  persist_dir=os.getenv("PERSISTENT_STORAGE_DIR"))
              self.index = load_index_from_storage(storage_context)
          else:
              self.DocumentClass.mediawiki_get_all_pages(self.mediawiki_url)
  
              self.index = VectorStoreIndex.from_documents(
                  self.DocumentClass.documents, service_context=self.service_context)
              if os.getenv("PERSISTENT_STORAGE_DIR") is not None:
                  self.index.storage_context.persist(
                      os.getenv("PERSISTENT_STORAGE_DIR"))
  
          self.query_engine = self.index.as_query_engine()
  
      def init_no_documents(self):
          self.index = llama_index.indices.empty.EmptyIndex(
              service_context=self.service_context)
          self.query_engine = self.index.as_query_engine()
  
      def updateVectorStore(self, type: str, page_url: str):
          if type == 'edit' or type == 'create':
              print("create/edit " + page_url)
              self.DocumentClass.mediawiki_update_page(page_url)
  
          elif type == 'delete':
              print("delete " + page_url)
              self.DocumentClass.mediawiki_delete_page(page_url)
  
          self.index.refresh(self.DocumentClass.documents)
  
apis: llama_index.VectorStoreIndex.from_documents llama_index.ServiceContext.from_defaults llama_index.load_index_from_storage llama_index.set_global_service_context llama_index.indices.empty.EmptyIndex
extract_api: [((542, 564), 'DocumentClass.DocumentClass', 'DocumentClass', (['api_url'], {}), '(api_url)\n', (555, 564), False, 'from DocumentClass import DocumentClass\n'), ((795, 870), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'llm': 'llm', 'embed_model': '"""local"""', 'chunk_size': '(1024)'}), "(llm=llm, embed_model='local', chunk_size=1024)\n", (823, 870), False, 'from llama_index import ServiceContext, StorageContext, VectorStoreIndex, load_index_from_storage, set_global_service_context\n'), ((962, 1010), 'llama_index.set_global_service_context', 'set_global_service_context', (['self.service_context'], {}), '(self.service_context)\n', (988, 1010), False, 'from llama_index import ServiceContext, StorageContext, VectorStoreIndex, load_index_from_storage, set_global_service_context\n'), ((1789, 1863), 'llama_index.indices.empty.EmptyIndex', 'llama_index.indices.empty.EmptyIndex', ([], {'service_context': 'self.service_context'}), '(service_context=self.service_context)\n', (1825, 1863), False, 'import llama_index\n'), ((1230, 1270), 'llama_index.load_index_from_storage', 'load_index_from_storage', (['storage_context'], {}), '(storage_context)\n', (1253, 1270), False, 'from llama_index import ServiceContext, StorageContext, VectorStoreIndex, load_index_from_storage, set_global_service_context\n'), ((1386, 1489), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['self.DocumentClass.documents'], {'service_context': 'self.service_context'}), '(self.DocumentClass.documents,\n    service_context=self.service_context)\n', (1417, 1489), False, 'from llama_index import ServiceContext, StorageContext, VectorStoreIndex, load_index_from_storage, set_global_service_context\n'), ((625, 647), 'os.getenv', 'os.getenv', (['"""MODEL_URL"""'], {}), "('MODEL_URL')\n", (634, 647), False, 'import os\n'), ((660, 683), 'os.getenv', 'os.getenv', (['"""MODEL_PATH"""'], {}), "('MODEL_PATH')\n", (669, 683), False, 'import os\n'), ((1041, 1076), 'os.getenv', 'os.getenv', (['"""PERSISTENT_STORAGE_DIR"""'], {}), "('PERSISTENT_STORAGE_DIR')\n", (1050, 1076), False, 'import os\n'), ((1518, 1553), 'os.getenv', 'os.getenv', (['"""PERSISTENT_STORAGE_DIR"""'], {}), "('PERSISTENT_STORAGE_DIR')\n", (1527, 1553), False, 'import os\n'), ((1168, 1203), 'os.getenv', 'os.getenv', (['"""PERSISTENT_STORAGE_DIR"""'], {}), "('PERSISTENT_STORAGE_DIR')\n", (1177, 1203), False, 'import os\n'), ((1639, 1674), 'os.getenv', 'os.getenv', (['"""PERSISTENT_STORAGE_DIR"""'], {}), "('PERSISTENT_STORAGE_DIR')\n", (1648, 1674), False, 'import os\n')]