code: from fastapi import FastAPI, File, UploadFile, HTTPException
  import openai
  from dotenv import load_dotenv
  import os
  import json
  from llama_index.core import SimpleDirectoryReader
  from llama_index.core.node_parser import SimpleFileNodeParser
  from llama_index.vector_stores.weaviate import WeaviateVectorStore
  from llama_index.core import VectorStoreIndex, StorageContext
  import weaviate
  import uvicorn
  
  load_dotenv()
  
  app = FastAPI()
  
  api_key = os.environ.get('OPENAI_API_KEY')
  openai.api_key = api_key
  OPENAI_API_KEY = os.getenv("OPENAI_API_KEY")
  os.environ['OPENAI_API_KEY'] = OPENAI_API_KEY
  WEAVIATE_API_KEY = os.getenv("WEAVIATE_API_KEY")
  WEAVIATE_URL = os.getenv("WEAVIATE_URL")
  auth_config = weaviate.AuthApiKey(api_key=WEAVIATE_API_KEY)
  
  client = weaviate.Client(
    url=WEAVIATE_URL,
    auth_client_secret=auth_config
  )
  
  
  def search_and_query():
      blogs = SimpleDirectoryReader("./Data").load_data()
      vector_store = WeaviateVectorStore(weaviate_client=client, index_name="DCPR")
      storage_context = StorageContext.from_defaults(vector_store=vector_store)
      VectorStoreIndex.from_documents(blogs, storage_context=storage_context)
      return "Done Embeddings"
  
  def Quert(ask):
      vector_store = WeaviateVectorStore(weaviate_client=client, index_name="DCPR")
      loaded_index = VectorStoreIndex.from_vector_store(vector_store)
      query_engine = loaded_index.as_query_engine()
      response = query_engine.query(ask)
      return response
  
  
  def contract_analysis_w_fact_checking(text):
  
      if not text:
          raise HTTPException(
              status_code=400, detail="Text field is required in the input data.")
      print("done 1")
      # Perform contract analysis using Quert (assuming Quert is a class or function)
      quert_instance = Quert(text)
      
      # Extract relevant information from the Quert response
      if quert_instance.response:
          contract_results = [{
              "LLM Response": quert_instance.response,
              "Source_node": [{
                  "Page_number": key_point.node.metadata.get('page_label', ''),
                  "File_Name": key_point.node.metadata.get('file_name', ''),
                  "Text": key_point.node.text,
                  "Start_Char": key_point.node.start_char_idx,
                  "End_Char": key_point.node.end_char_idx,
                  "Score_Matching": key_point.score
              } for key_point in quert_instance.source_nodes]
          }]
      else:
          contract_results = []
      
      # Return a standardized response
      return {"status": "success", "message": "Contract analysis successful", "model_response": contract_results}
  
  
  @app.post("/embedd")
  async def predict():
      try: 
          dor = search_and_query()
          return {"user_content": dor}
      except Exception as e:
          raise HTTPException(status_code=500, detail=str(e))
  
  
  @app.post("/predict")
  async def predict(data: dict):
      try:
          messages = data.get("messages", [])
          user_message = next((msg["content"] for msg in messages if msg["role"] == "user"), None)
          out = contract_analysis_w_fact_checking(user_message)
          if user_message:
              return {"user_content": out}
          else:
              raise HTTPException(
                  status_code=400, detail="User message not found in input.")
      except Exception as e:
          raise HTTPException(status_code=500, detail=str(e))
  
  
  
  
  @app.get("/")
  def read_root():
      return {"Hello": "World"}
  
apis: llama_index.core.StorageContext.from_defaults llama_index.core.VectorStoreIndex.from_vector_store llama_index.core.VectorStoreIndex.from_documents llama_index.core.SimpleDirectoryReader llama_index.vector_stores.weaviate.WeaviateVectorStore
extract_api: [((402, 415), 'dotenv.load_dotenv', 'load_dotenv', ([], {}), '()\n', (413, 415), False, 'from dotenv import load_dotenv\n'), ((423, 432), 'fastapi.FastAPI', 'FastAPI', ([], {}), '()\n', (430, 432), False, 'from fastapi import FastAPI, File, UploadFile, HTTPException\n'), ((444, 476), 'os.environ.get', 'os.environ.get', (['"""OPENAI_API_KEY"""'], {}), "('OPENAI_API_KEY')\n", (458, 476), False, 'import os\n'), ((519, 546), 'os.getenv', 'os.getenv', (['"""OPENAI_API_KEY"""'], {}), "('OPENAI_API_KEY')\n", (528, 546), False, 'import os\n'), ((612, 641), 'os.getenv', 'os.getenv', (['"""WEAVIATE_API_KEY"""'], {}), "('WEAVIATE_API_KEY')\n", (621, 641), False, 'import os\n'), ((657, 682), 'os.getenv', 'os.getenv', (['"""WEAVIATE_URL"""'], {}), "('WEAVIATE_URL')\n", (666, 682), False, 'import os\n'), ((697, 742), 'weaviate.AuthApiKey', 'weaviate.AuthApiKey', ([], {'api_key': 'WEAVIATE_API_KEY'}), '(api_key=WEAVIATE_API_KEY)\n', (716, 742), False, 'import weaviate\n'), ((753, 818), 'weaviate.Client', 'weaviate.Client', ([], {'url': 'WEAVIATE_URL', 'auth_client_secret': 'auth_config'}), '(url=WEAVIATE_URL, auth_client_secret=auth_config)\n', (768, 818), False, 'import weaviate\n'), ((926, 988), 'llama_index.vector_stores.weaviate.WeaviateVectorStore', 'WeaviateVectorStore', ([], {'weaviate_client': 'client', 'index_name': '"""DCPR"""'}), "(weaviate_client=client, index_name='DCPR')\n", (945, 988), False, 'from llama_index.vector_stores.weaviate import WeaviateVectorStore\n'), ((1011, 1066), 'llama_index.core.StorageContext.from_defaults', 'StorageContext.from_defaults', ([], {'vector_store': 'vector_store'}), '(vector_store=vector_store)\n', (1039, 1066), False, 'from llama_index.core import VectorStoreIndex, StorageContext\n'), ((1071, 1142), 'llama_index.core.VectorStoreIndex.from_documents', 'VectorStoreIndex.from_documents', (['blogs'], {'storage_context': 'storage_context'}), '(blogs, storage_context=storage_context)\n', (1102, 1142), False, 'from llama_index.core import VectorStoreIndex, StorageContext\n'), ((1208, 1270), 'llama_index.vector_stores.weaviate.WeaviateVectorStore', 'WeaviateVectorStore', ([], {'weaviate_client': 'client', 'index_name': '"""DCPR"""'}), "(weaviate_client=client, index_name='DCPR')\n", (1227, 1270), False, 'from llama_index.vector_stores.weaviate import WeaviateVectorStore\n'), ((1290, 1338), 'llama_index.core.VectorStoreIndex.from_vector_store', 'VectorStoreIndex.from_vector_store', (['vector_store'], {}), '(vector_store)\n', (1324, 1338), False, 'from llama_index.core import VectorStoreIndex, StorageContext\n'), ((1527, 1614), 'fastapi.HTTPException', 'HTTPException', ([], {'status_code': '(400)', 'detail': '"""Text field is required in the input data."""'}), "(status_code=400, detail=\n    'Text field is required in the input data.')\n", (1540, 1614), False, 'from fastapi import FastAPI, File, UploadFile, HTTPException\n'), ((863, 894), 'llama_index.core.SimpleDirectoryReader', 'SimpleDirectoryReader', (['"""./Data"""'], {}), "('./Data')\n", (884, 894), False, 'from llama_index.core import SimpleDirectoryReader\n'), ((3176, 3249), 'fastapi.HTTPException', 'HTTPException', ([], {'status_code': '(400)', 'detail': '"""User message not found in input."""'}), "(status_code=400, detail='User message not found in input.')\n", (3189, 3249), False, 'from fastapi import FastAPI, File, UploadFile, HTTPException\n')]