
    i              
           d Z ddlmZmZmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ  edd	g
      Z G d de      Z G d de      Zej%                  de       ee
       ee      fdedededefd       Zy)z&Router for AI Chat Assistant endpoint.    )	APIRouterDependsHTTPException)	BaseModel)AsyncSession)get_db)get_current_user)Userz
/assistant	assistant)prefixtagsc                   <    e Zd ZU eed<   eed<   dZee   dz  ed<   y)ChatRequestmessagespbu_idNconversation_history)	__name__
__module____qualname__str__annotations__intr   listdict     7/var/www/html/spbu.com/backend/app/routers/assistant.pyr   r      s     LL.2$t*t+2r   r   c                   :    e Zd ZU eed<   g Zee   ed<   dZeed<   y)ChatResponseresponse
tools_used providerN)r   r   r   r   r   r!   r   r#   r   r   r   r   r      s    MJS	Hcr   r   r"   )response_modeldatadbcurrent_userreturnc                    K   ddl m} 	  ||| j                  | j                  | j                         d{   }t        di |S 7 # t
        $ r}t        dt        |            d}~ww xY ww)z6Send a message to the AI assistant and get a response.r   )chat)r   user_messager   Ni  )status_codedetailr   )	app.assistant.servicer*   r   r   r   
ValueErrorr   r   r   )r%   r&   r'   assistant_chatresultes         r   r*   r*      sp      =<%LL!%!:!:	
 
 !&!!
  <CF;;<s7   A0-A	 AA	 A0A	 		A-A((A--A0N)__doc__fastapir   r   r   pydanticr   sqlalchemy.ext.asyncior   app.core.databaser   app.dependenciesr	   app.models.userr
   routerr   r   postr*   r   r   r   <module>r<      s    , 5 5  / $ -  	,k]	;3) 39  R- v !12"
"" " 	" ."r   