
    nh                         d dl mZmZ d dlmZ d dlmZmZmZ d dl	m
Z
 d dlZe
defd       Z ee      Z G d	 d
e      Zej                  d      defd       Zej#                  d      d        Zedk(  r ej(                  dddd       yy)    )FastAPIRequest)	BaseModel)embedder	retriever	responder)asynccontextmanagerNappc                   K   	 t        j                          t        d       d  y #  t        d       t        j                          t        d       Y 4xY ww)NzFAISS index loaded.z)FAISS index not found. Building it now...zFAISS index built and saved.)r   load_index_and_metaprintbuild_and_save_index)r
   s    #/var/www/html/axiom-chatbot/main.pylifespanr   	   sI     .$$&#$
 
	.9:%%',-s   A) A,AA)r   c                       e Zd ZU eed<   y)ChatRequestqueryN)__name__
__module____qualname__str__annotations__     r   r   r      s    Jr   r   z/chatrequestc                 x    | j                   }t        j                  |      }t        j                  ||      }d|iS )Nresponse)r   r   retriever   generate_answer)r   r   chunksr   s       r   chatr!      s8    MME&F((7H!!r   z/healthc                  
    ddiS )Nstatusokr   r   r   r   healthr%       s    dr   __main__zmain:appz0.0.0.0i@  T)hostportreload)fastapir   r   pydanticr   chatbotr   r   r   
contextlibr	   uvicornr   r
   r   postr!   getr%   r   runr   r   r   <module>r2      s    $  2 2 *  
 
 
 x )  '"+ " "   zGKK
dC r   