code: import os
  
  from dotenv import load_dotenv
  from llama_index.chat_engine.condense_plus_context import CondensePlusContextChatEngine
  from llama_index.llms.openai import OpenAI
  from llama_index.llms.types import ChatMessage, MessageRole
  from llama_index.query_engine import RetrieverQueryEngine
  from llama_index.retrievers import PathwayRetriever
  from traceloop.sdk import Traceloop
  
  from pathway.xpacks.llm.vector_store import VectorStoreClient
  
  load_dotenv()
  
  
  Traceloop.init(app_name=os.environ.get("APP_NAME", "PW - LlamaIndex (Streamlit)"))
  
  DEFAULT_PATHWAY_HOST = "demo-document-indexing.pathway.stream"
  
  PATHWAY_HOST = os.environ.get("PATHWAY_HOST", DEFAULT_PATHWAY_HOST)
  
  PATHWAY_PORT = int(os.environ.get("PATHWAY_PORT", "80"))
  
  
  def get_additional_headers():
      headers = {}
      key = os.environ.get("PATHWAY_API_KEY")
      if key is not None:
          headers = {"X-Pathway-API-Key": key}
      return headers
  
  
  vector_client = VectorStoreClient(
      PATHWAY_HOST,
      PATHWAY_PORT,
      # additional_headers=get_additional_headers(),
  )
  
  
  retriever = PathwayRetriever(host=PATHWAY_HOST, port=PATHWAY_PORT)
  retriever.client = VectorStoreClient(
      host=PATHWAY_HOST, 
      port=PATHWAY_PORT, 
      # additional_headers=get_additional_headers()
  )
  
  llm = OpenAI(model="gpt-3.5-turbo")
  
  query_engine = RetrieverQueryEngine.from_args(
      retriever,
  )
  
  pathway_explaination = "Pathway is a high-throughput, low-latency data processing framework that handles live data & streaming for you."
  DEFAULT_MESSAGES = [
      ChatMessage(role=MessageRole.USER, content="What is Pathway?"),
      ChatMessage(role=MessageRole.ASSISTANT, content=pathway_explaination),
  ]
  
  chat_engine = CondensePlusContextChatEngine.from_defaults(
      retriever=retriever,
      system_prompt="""You are RAG AI that answers users questions based on provided sources.
      IF QUESTION IS NOT RELATED TO ANY OF THE CONTEXT DOCUMENTS, SAY IT'S NOT POSSIBLE TO ANSWER USING PHRASE `The looked-up documents do not provde information about...`""",
      verbose=True,
      chat_history=DEFAULT_MESSAGES,
      llm=llm,
  )
  
apis: llama_index.llms.types.ChatMessage llama_index.chat_engine.condense_plus_context.CondensePlusContextChatEngine.from_defaults llama_index.retrievers.PathwayRetriever llama_index.query_engine.RetrieverQueryEngine.from_args llama_index.llms.openai.OpenAI
extract_api: [((443, 456), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (454, 456), False, 'from dotenv import load_dotenv\n'), ((622, 674), 'os.environ.get', 'os.environ.get', (['"""PATHWAY_HOST"""', 'DEFAULT_PATHWAY_HOST'], {}), "('PATHWAY_HOST', DEFAULT_PATHWAY_HOST)\n", (636, 674), False, 'import os\n'), ((932, 977), 'pathway.xpacks.llm.vector_store.VectorStoreClient', 'VectorStoreClient', (['PATHWAY_HOST', 'PATHWAY_PORT'], {}), '(PATHWAY_HOST, PATHWAY_PORT)\n', (949, 977), False, 'from pathway.xpacks.llm.vector_store import VectorStoreClient\n'), ((1054, 1108), 'llama_index.retrievers.PathwayRetriever', 'PathwayRetriever', ([], {'host': 'PATHWAY_HOST', 'port': 'PATHWAY_PORT'}), '(host=PATHWAY_HOST, port=PATHWAY_PORT)\n', (1070, 1108), False, 'from llama_index.retrievers import PathwayRetriever\n'), ((1128, 1183), 'pathway.xpacks.llm.vector_store.VectorStoreClient', 'VectorStoreClient', ([], {'host': 'PATHWAY_HOST', 'port': 'PATHWAY_PORT'}), '(host=PATHWAY_HOST, port=PATHWAY_PORT)\n', (1145, 1183), False, 'from pathway.xpacks.llm.vector_store import VectorStoreClient\n'), ((1254, 1283), 'llama_index.llms.openai.OpenAI', 'OpenAI', ([], {'model': '"""gpt-3.5-turbo"""'}), "(model='gpt-3.5-turbo')\n", (1260, 1283), False, 'from llama_index.llms.openai import OpenAI\n'), ((1300, 1341), 'llama_index.query_engine.RetrieverQueryEngine.from_args', 'RetrieverQueryEngine.from_args', (['retriever'], {}), '(retriever)\n', (1330, 1341), False, 'from llama_index.query_engine import RetrieverQueryEngine\n'), ((1668, 2062), 'llama_index.chat_engine.condense_plus_context.CondensePlusContextChatEngine.from_defaults', 'CondensePlusContextChatEngine.from_defaults', ([], {'retriever': 'retriever', 'system_prompt': '"""You are RAG AI that answers users questions based on provided sources.\n    IF QUESTION IS NOT RELATED TO ANY OF THE CONTEXT DOCUMENTS, SAY IT\'S NOT POSSIBLE TO ANSWER USING PHRASE `The looked-up documents do not provde information about...`"""', 'verbose': '(True)', 'chat_history': 'DEFAULT_MESSAGES', 'llm': 'llm'}), '(retriever=retriever,\n    system_prompt=\n    """You are RAG AI that answers users questions based on provided sources.\n    IF QUESTION IS NOT RELATED TO ANY OF THE CONTEXT DOCUMENTS, SAY IT\'S NOT POSSIBLE TO ANSWER USING PHRASE `The looked-up documents do not provde information about...`"""\n    , verbose=True, chat_history=DEFAULT_MESSAGES, llm=llm)\n', (1711, 2062), False, 'from llama_index.chat_engine.condense_plus_context import CondensePlusContextChatEngine\n'), ((695, 731), 'os.environ.get', 'os.environ.get', (['"""PATHWAY_PORT"""', '"""80"""'], {}), "('PATHWAY_PORT', '80')\n", (709, 731), False, 'import os\n'), ((792, 825), 'os.environ.get', 'os.environ.get', (['"""PATHWAY_API_KEY"""'], {}), "('PATHWAY_API_KEY')\n", (806, 825), False, 'import os\n'), ((1512, 1574), 'llama_index.llms.types.ChatMessage', 'ChatMessage', ([], {'role': 'MessageRole.USER', 'content': '"""What is Pathway?"""'}), "(role=MessageRole.USER, content='What is Pathway?')\n", (1523, 1574), False, 'from llama_index.llms.types import ChatMessage, MessageRole\n'), ((1580, 1649), 'llama_index.llms.types.ChatMessage', 'ChatMessage', ([], {'role': 'MessageRole.ASSISTANT', 'content': 'pathway_explaination'}), '(role=MessageRole.ASSISTANT, content=pathway_explaination)\n', (1591, 1649), False, 'from llama_index.llms.types import ChatMessage, MessageRole\n'), ((483, 540), 'os.environ.get', 'os.environ.get', (['"""APP_NAME"""', '"""PW - LlamaIndex (Streamlit)"""'], {}), "('APP_NAME', 'PW - LlamaIndex (Streamlit)')\n", (497, 540), False, 'import os\n')]