
    .h                        d dl mZ d dl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 dd	lmZ  G d
 dej                  Z G d d          Z G d d          Z G d de          ZdS )    )annotationsN)AsyncIterator)Any   )Agent)TResponseInputItem)RunResultStreaming)Runnerc                  4    e Zd ZdZej        dd            ZdS )	VoiceWorkflowBaseal  
    A base class for a voice workflow. You must implement the `run` method. A "workflow" is any
    code you want, that receives a transcription and yields text that will be turned into speech
    by a text-to-speech model.
    In most cases, you'll create `Agent`s and use `Runner.run_streamed()` to run them, returning
    some or all of the text events from the stream. You can use the `VoiceWorkflowHelper` class to
    help with extracting text events from the stream.
    If you have a simple workflow that has a single starting agent and no custom logic, you can
    use `SingleAgentVoiceWorkflow` directly.
    transcriptionstrreturnAsyncIterator[str]c                    dS )aC  
        Run the voice workflow. You will receive an input transcription, and must yield text that
        will be spoken to the user. You can run whatever logic you want here. In most cases, the
        final logic will involve calling `Runner.run_streamed()` and yielding any text events from
        the stream.
        N )selfr   s     R/var/www/FlaskApp/flask-venv/lib/python3.11/site-packages/agents/voice/workflow.pyrunzVoiceWorkflowBase.run   s	     	    Nr   r   r   r   )__name__
__module____qualname____doc__abcabstractmethodr   r   r   r   r   r      sB        	 	 	     r   r   c                  &    e Zd Zedd            ZdS )VoiceWorkflowHelperresultr	   r   r   c                  K   |                                 2 3 d{V }|j        dk    r|j        j        dk    r|j        j        W V  26 dS )zKWraps a `RunResultStreaming` object and yields text events from the stream.Nraw_response_eventzresponse.output_text.delta)stream_eventstypedatadelta)clsr    events      r   stream_text_fromz$VoiceWorkflowHelper.stream_text_from%   sz       "//11 	' 	' 	' 	' 	' 	' 	'%
222JO'CCCj&&&&& 211s   A	N)r    r	   r   r   )r   r   r   classmethodr)   r   r   r   r   r   $   s2        ' ' ' [' ' 'r   r   c                      e Zd Zd	dZdS )
SingleAgentWorkflowCallbacksworkflowSingleAgentVoiceWorkflowr   r   r   Nonec                    dS )z Called when the workflow is run.Nr   )r   r-   r   s      r   on_runz#SingleAgentWorkflowCallbacks.on_run1   s    r   N)r-   r.   r   r   r   r/   )r   r   r   r1   r   r   r   r,   r,   0   s(             r   r,   c                  $    e Zd ZdZdddZddZdS )r.   a)  A simple voice workflow that runs a single agent. Each transcription and result is added to
    the input history.
    For more complex workflows (e.g. multiple Runner calls, custom message history, custom logic,
    custom configs), subclass `VoiceWorkflowBase` and implement your own logic.
    Nagent
Agent[Any]	callbacks#SingleAgentWorkflowCallbacks | Nonec                0    g | _         || _        || _        dS )zCreate a new single agent voice workflow.

        Args:
            agent: The agent to run.
            callbacks: Optional callbacks to call during the workflow.
        N)_input_history_current_agent
_callbacks)r   r3   r5   s      r   __init__z!SingleAgentVoiceWorkflow.__init__=   s     9;##r   r   r   r   r   c               `  K   | j         r| j                             | |           | j                            d|d           t	          j        | j        | j                  }t                              |          2 3 d {V }|W V  6 |	                                | _        |j
        | _        d S )Nuser)rolecontent)r:   r1   r8   appendr
   run_streamedr9   r   r)   to_input_list
last_agent)r   r   r    chunks       r   r   zSingleAgentVoiceWorkflow.runH   s      ? 	8O""4777 	""( 	
 	
 	
 $T%8$:MNN /??GG 	 	 	 	 	 	 	%KKKKK H %2244$/s   ;B)N)r3   r4   r5   r6   r   )r   r   r   r   r;   r   r   r   r   r.   r.   6   sK         	$ 	$ 	$ 	$ 	$0 0 0 0 0 0r   r.   )
__future__r   r   collections.abcr   typingr   r3   r   itemsr   r    r	   r   r
   ABCr   r   r,   r.   r   r   r   <module>rJ      s=   " " " " " " 



 ) ) ) ) ) )             & & & & & & ' ' ' ' ' '             .	' 	' 	' 	' 	' 	' 	' 	'       '0 '0 '0 '0 '00 '0 '0 '0 '0 '0r   