o
    i/                     @  s  d dl mZ d dlZd dlmZmZ d dlmZmZ d dl	m
Z
 d dlmZ d dlmZmZmZ d dlmZmZmZ d d	lmZ d
dlmZmZ ddlmZmZ ddlmZmZmZ e
G dd dZ e
G dd dZ!e
G dd dZ"e
G dd dZ#G dd deZ$e
G dd dZ%G dd de&Z'G dd dZ(ed Z)ed Z*e
G d!d" d"Z+e
G d#d$ d$Z,G d%d& d&eej-e)e*B  ee* Z.dS )'    )annotationsN)ABCabstractmethod)AsyncIterable	Awaitable)	dataclass)TracebackType)GenericLiteralTypeVar)	BaseModel
ConfigDictField)rtc   )	NOT_GIVEN
NotGivenOr   )ChatContextFunctionCall)Tool
ToolChoiceToolContextc                   @     e Zd ZdS )InputSpeechStartedEventN__name__
__module____qualname__ r   r   ]/var/www/html/livekit_bhavya/venv/lib/python3.10/site-packages/livekit/agents/llm/realtime.pyr          r   c                   @  s   e Zd ZU ded< dS )InputSpeechStoppedEventbooluser_transcription_enabledNr   r   r   __annotations__r   r   r   r    r"      s   
 r"   c                   @  s.   e Zd ZU ded< ded< ded< ded< d	S )
MessageGenerationstr
message_idzAsyncIterable[str]text_streamzAsyncIterable[rtc.AudioFrame]audio_streamz)Awaitable[list[Literal['text', 'audio']]]
modalitiesNr%   r   r   r   r    r'      s
   
 r'   c                   @  s4   e Zd ZU ded< ded< ded< 	 dZded	< dS )
GenerationCreatedEventz AsyncIterable[MessageGeneration]message_streamzAsyncIterable[FunctionCall]function_streamr#   user_initiatedNz
str | Noneresponse_id)r   r   r   r&   r1   r   r   r   r    r-   %   s   
 r-   c                   @  sP   e Zd ZU eddZdZded< ded< ded	< ed
ddZded< ded< dS )RealtimeModelErrorT)arbitrary_types_allowedrealtime_model_errorzLiteral['realtime_model_error']typefloat	timestampr(   label.)exclude	Exceptionerrorr#   recoverableN)	r   r   r   r   model_configr5   r&   r   r;   r   r   r   r    r2   /   s   
 
r2   c                   @  s>   e Zd ZU ded< ded< ded< ded< ded< ded< dS )	RealtimeCapabilitiesr#   message_truncationturn_detectionuser_transcriptionauto_tool_reply_generationaudio_outputmanual_function_callsNr%   r   r   r   r    r>   8   s   
 r>   c                      s   e Zd Zd fddZ  ZS )RealtimeErrormessager(   returnNonec                   s   t  | d S N)super__init__)selfrF   	__class__r   r    rK   C   s   zRealtimeError.__init__)rF   r(   rG   rH   )r   r   r   rK   __classcell__r   r   rM   r    rE   B   s    rE   c                   @  s~   e Zd Zd ddZed!dd	Zed!d
dZed"ddZed!ddZe	d#ddZ
e	d$ddZd%ddZd&ddZdS )'RealtimeModelcapabilitiesr>   rG   rH   c                C  s&   || _ t| j dt| j | _d S )N.)_capabilitiesr5   r   r   _label)rL   rQ   r   r   r    rK   H   s    zRealtimeModel.__init__r(   c                 C     dS Nunknownr   rL   r   r   r    modelL      zRealtimeModel.modelc                 C  rU   rV   r   rX   r   r   r    providerP   rZ   zRealtimeModel.providerc                 C     | j S rI   )rS   rX   r   r   r    rQ   T      zRealtimeModel.capabilitiesc                 C  r\   rI   )rT   rX   r   r   r    r8   X   r]   zRealtimeModel.labelRealtimeSessionc                 C     d S rI   r   rX   r   r   r    session\      zRealtimeModel.sessionc                      d S rI   r   rX   r   r   r    aclose_      zRealtimeModel.aclosec                   s   | S rI   r   rX   r   r   r    
__aenter__b   rd   zRealtimeModel.__aenter__exc_typetype[BaseException] | NoneexcBaseException | Noneexc_tbTracebackType | Nonec                   s   |   I d H  d S rI   )rc   )rL   rf   rh   rj   r   r   r    	__aexit__e   s   zRealtimeModel.__aexit__N)rQ   r>   rG   rH   )rG   r(   )rG   r>   )rG   r^   rG   rH   rG   rP   )rf   rg   rh   ri   rj   rk   rG   rH   )r   r   r   rK   propertyrY   r[   rQ   r8   r   r`   rc   re   rl   r   r   r   r    rP   G   s     

rP   )input_speech_startedinput_speech_stopped#input_audio_transcription_completedgeneration_createdsession_reconnectedmetrics_collectedr;   TEventc                   @  s*   e Zd ZU ded< 	 ded< 	 ded< dS )InputTranscriptionCompletedr(   item_id
transcriptr#   is_finalNr%   r   r   r   r    rw   {   s   
 rw   c                   @  r   )RealtimeSessionReconnectedEventNr   r   r   r   r    r{      r!   r{   c                      s  e Zd Zd> fddZed?ddZeed@d
dZeedAddZedBddZ	edCddZ
edDddZeeddEddZedFd!d"ZedGd$d%Zeed&dHd)d*ZedId+d,ZedId-d.ZedId/d0Zeed1dJd8d9ZedId:d;ZdId<d=Z  ZS )Kr^   realtime_modelrP   rG   rH   c                   s   t    || _d S rI   )rJ   rK   _realtime_model)rL   r|   rM   r   r    rK      s   

zRealtimeSession.__init__c                 C  r\   rI   )r}   rX   r   r   r    r|      r]   zRealtimeSession.realtime_modelr   c                 C  r_   rI   r   rX   r   r   r    chat_ctx   rZ   zRealtimeSession.chat_ctxr   c                 C  r_   rI   r   rX   r   r   r    tools   rZ   zRealtimeSession.toolsinstructionsr(   c                   rb   rI   r   rL   r   r   r   r    update_instructions   rd   z#RealtimeSession.update_instructionsr~   c                   rb   rI   r   )rL   r~   r   r   r    update_chat_ctx   s   zRealtimeSession.update_chat_ctxr   
list[Tool]c                   rb   rI   r   )rL   r   r   r   r    update_tools   rd   zRealtimeSession.update_tools)tool_choicer   NotGivenOr[ToolChoice | None]c                C  r_   rI   r   )rL   r   r   r   r    update_options   ra   zRealtimeSession.update_optionsframertc.AudioFramec                 C  r_   rI   r   rL   r   r   r   r    
push_audio   ra   zRealtimeSession.push_audiortc.VideoFramec                 C  r_   rI   r   r   r   r   r    
push_video   ra   zRealtimeSession.push_video)r   NotGivenOr[str]&asyncio.Future[GenerationCreatedEvent]c                C  r_   rI   r   r   r   r   r    generate_reply   s   zRealtimeSession.generate_replyc                 C  r_   rI   r   rX   r   r   r    commit_audio   ra   zRealtimeSession.commit_audioc                 C  r_   rI   r   rX   r   r   r    clear_audio   ra   zRealtimeSession.clear_audioc                 C  r_   rI   r   rX   r   r   r    	interrupt   ra   zRealtimeSession.interrupt)audio_transcriptr)   r,   list[Literal['text', 'audio']]audio_end_msintr   c                C  r_   rI   r   )rL   r)   r,   r   r   r   r   r    truncate   s   zRealtimeSession.truncatec                   rb   rI   r   rX   r   r   r    rc      rd   zRealtimeSession.aclosec                 C  rU   )z1notifies the model that user activity has startedNr   rX   r   r   r    start_user_activity   rZ   z#RealtimeSession.start_user_activity)r|   rP   rG   rH   rn   )rG   r   )rG   r   )r   r(   rG   rH   )r~   r   rG   rH   )r   r   rG   rH   )r   r   rG   rH   )r   r   rG   rH   )r   r   rG   rH   )r   r   rG   r   rm   )
r)   r(   r,   r   r   r   r   r   rG   rH   )r   r   r   rK   ro   r|   r   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   rc   r   rO   r   r   rM   r    r^      sJ    	r^   )/
__future__r   asyncioabcr   r   collections.abcr   r   dataclassesr   typesr   typingr	   r
   r   pydanticr   r   r   livekitr   r   r   chat_contextr   r   tool_contextr   r   r   r   r"   r'   r-   r2   r>   r:   rE   rP   
EventTypesrv   rw   r{   EventEmitterr^   r   r   r   r    <module>   sD    			'
&