code: from llama_index import SimpleDirectoryReader, ServiceContext, VectorStoreIndex
  from llama_index.llms import OpenAI, ChatMessage, MessageRole
  from llama_index.chat_engine.condense_plus_context import CondensePlusContextChatEngine
  from dotenv import load_dotenv
  import os
  load_dotenv()
  
  vector_index = None
  history = []
  
  def initializeService():
      global vector_index
      llm = OpenAI(model="gpt-3.5-turbo", temperature=0.5)
  
      promptFile = open('./data/prompt.txt')
      prompt = promptFile.read()
      #print("Using the following system prompt: ", prompt, sep='\n')
  
      service_context = ServiceContext.from_defaults(
          llm=llm, system_prompt=prompt)
      try:
          reader = SimpleDirectoryReader(
              input_dir='./data/context', recursive=False)
          docs = reader.load_data()
      except ValueError:
          print(
              f"Context directory is empty, using only prompt")
          docs = []
  
      vector_index = VectorStoreIndex.from_documents(
          docs, service_context=service_context)
  
  
  def loadChat():
      global vector_index
      global history
      query_engine = vector_index.as_query_engine()
  
      chat_history = list(map(lambda item: ChatMessage(
          role=item['source'], content=item['message']),
          history
      ))
  
      chat_engine = CondensePlusContextChatEngine.from_defaults(
          query_engine,
          chat_history=chat_history
      )
  
      return chat_engine
  
  def chat(message):
      global history
  
      history.append({'source': MessageRole.USER, 'message': message})
      chat_engine = loadChat()
      response = chat_engine.chat(message)
      history.append({'source': MessageRole.SYSTEM, 'message': response.response})
      return response.response
  
  if __name__ == "__main__":
      initializeService()
  
      question = input("Ask me anything: ")
      while question != "exit":
          print(chat(question))
          question = input("Ask me anything: ")
apis: llama_index.VectorStoreIndex.from_documents llama_index.ServiceContext.from_defaults llama_index.chat_engine.condense_plus_context.CondensePlusContextChatEngine.from_defaults llama_index.SimpleDirectoryReader llama_index.llms.OpenAI llama_index.llms.ChatMessage
extract_api: [((271, 284), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (282, 284), False, 'from dotenv import load_dotenv\n'), ((379, 425), 'llama_index.llms.OpenAI', 'OpenAI', ([], {'model': '"""gpt-3.5-turbo"""', 'temperature': '(0.5)'}), "(model='gpt-3.5-turbo', temperature=0.5)\n", (385, 425), False, 'from llama_index.llms import OpenAI, ChatMessage, MessageRole\n'), ((592, 651), 'llama_index.ServiceContext.from_defaults', 'ServiceContext.from_defaults', ([], {'llm': 'llm', 'system_prompt': 'prompt'}), '(llm=llm, system_prompt=prompt)\n', (620, 651), False, 'from llama_index import SimpleDirectoryReader, ServiceContext, VectorStoreIndex\n'), ((939, 1009), 'llama_index.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['docs'], {'service_context': 'service_context'}), '(docs, service_context=service_context)\n', (970, 1009), False, 'from llama_index import SimpleDirectoryReader, ServiceContext, VectorStoreIndex\n'), ((1282, 1371), 'llama_index.chat_engine.condense_plus_context.CondensePlusContextChatEngine.from_defaults', 'CondensePlusContextChatEngine.from_defaults', (['query_engine'], {'chat_history': 'chat_history'}), '(query_engine, chat_history=\n    chat_history)\n', (1325, 1371), False, 'from llama_index.chat_engine.condense_plus_context import CondensePlusContextChatEngine\n'), ((687, 753), 'llama_index.SimpleDirectoryReader', 'SimpleDirectoryReader', ([], {'input_dir': '"""./data/context"""', 'recursive': '(False)'}), "(input_dir='./data/context', recursive=False)\n", (708, 753), False, 'from llama_index import SimpleDirectoryReader, ServiceContext, VectorStoreIndex\n'), ((1172, 1229), 'llama_index.llms.ChatMessage', 'ChatMessage', ([], {'role': "item['source']", 'content': "item['message']"}), "(role=item['source'], content=item['message'])\n", (1183, 1229), False, 'from llama_index.llms import OpenAI, ChatMessage, MessageRole\n')]