Ë
    uPêj¡  ã                   ó~   — 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
 erddlmZ ddlmZ ddlmZ  G d	„ d
e«      Zy)zí
OpenAI Text-to-Speech Handler for Unified Guardrails

This module provides guardrail translation support for OpenAI's text-to-speech endpoint.
The handler processes the 'input' text parameter (output is audio, so no text to guardrail).
é    )ÚTYPE_CHECKINGÚAnyÚFinal)Úverbose_proxy_logger)ÚBaseTranslation)ÚGenericGuardrailAPIInputs)ÚCustomGuardrail)ÚLogging)ÚHttpxBinaryResponseContentc                   ó`   — e Zd ZdZ	 ddedddddefd	„Z	 	 	 dd
ddddddedz  dedz  defd„Zy)ÚOpenAITextToSpeechHandlera"  
    Handler for processing OpenAI text-to-speech requests with guardrails.

    This class provides methods to:
    1. Process input text (pre-call hook)

    Note: Output processing is not applicable since the output is audio (binary),
    not text. Only the input text is processed.
    NÚdataÚguardrail_to_applyr	   Úlitellm_logging_objzLiteLLMLoggingObj | NoneÚreturnc              ƒ   óà  K  — |j                  d«      }|€t        j                  d«       |S t        |t        «      rŽt        |g¬«      }|j                  d«      }|r||d<   |j                  ||d|¬«      ƒ d{  –—† }|j                  dg «      }|r|d	   n||d<   t        j                  d
t        |«      t        |d   «      «       |S t        j                  dt        |«      «       |S 7 Œq­w)a$  
        Process input text by applying guardrails.

        Args:
            data: Request data dictionary containing 'input' parameter
            guardrail_to_apply: The guardrail instance to apply

        Returns:
            Modified data with guardrails applied to input text
        ÚinputNz:OpenAI Text-to-Speech: No input text found in request data)ÚtextsÚmodelÚrequest)ÚinputsÚrequest_dataÚ
input_typeÚlogging_objr   r   z[OpenAI Text-to-Speech: Applied guardrail to input text. Original length: %d, New length: %dzBOpenAI Text-to-Speech: Unexpected input type: %s. Expected string.)	Úgetr   ÚdebugÚ
isinstanceÚstrr   Úapply_guardrailÚlenÚtype)	Úselfr   r   r   Ú
input_textr   r   Úguardrailed_inputsÚguardrailed_textss	            ú}/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/openai/speech/guardrail_translation/handler.pyÚprocess_input_messagesz0OpenAITextToSpeechHandler.process_input_messages   s  è ø€ ð  !ŸH™H WÓ-ˆ
ØÐÜ ×&Ñ&Ð'cÔdØˆKä�j¤#Ô&Ü5¸Z¸LÔIˆFàŸ8™8 GÓ,ˆEÙØ"'��w‘Ø.@×.PÑ.PØØ!Ø$Ø/ð	 /Qó /÷ )Ðð (:×'=Ñ'=¸gÀrÓ'JÐÙ4EÐ-¨aÒ0È:ˆD�‰Mä ×&Ñ&ØmÜ�J“Ü�D˜‘MÓ"ôð ˆô !×&Ñ&ØTÜ�ZÓ ôð
 ˆð))ús   ‚A8C.Á:C,Á;A2C.Úresponser   Úuser_api_key_dictr   c              ƒ   ó8   K  — t        j                  d«       |S ­w)a1  
        Process output - not applicable for text-to-speech.

        The output is audio (binary data), not text, so there's nothing to apply
        guardrails to. This method returns the response unchanged.

        Args:
            response: Binary audio response
            guardrail_to_apply: The guardrail instance (unused)
            litellm_logging_obj: Optional logging object (unused)
            user_api_key_dict: User API key metadata (unused)

        Returns:
            Unmodified response (audio data doesn't need text guardrails)
        zXOpenAI Text-to-Speech: Output processing not applicable (output is audio data, not text))r   r   )r"   r(   r   r   r)   r   s         r&   Úprocess_output_responsez1OpenAITextToSpeechHandler.process_output_responseP   s    è ø€ ô. 	×"Ñ"Øfô	
ð ˆùs   ‚)N)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údictr   r'   r+   © ó    r&   r   r      sŠ   „ ñð ;?ñ	/àð/ð .ð/ð 8ð	/ð
 
ó/ðj ;?Ø(,Ø$(ñà.ðð .ðð 8ð	ð
  ™:ðð ˜T‘kðð 
ôr2   r   N)r/   Útypingr   r   r   Úlitellm._loggingr   Ú<litellm.llms.base_llm.guardrail_translation.base_translationr   Úlitellm.types.utilsr   Ú%litellm.integrations.custom_guardrailr	   Ú*litellm.litellm_core_utils.litellm_loggingr
   ÚLiteLLMLoggingObjÚlitellm.types.llms.openair   r   r1   r2   r&   ú<module>r;      s5   ðñ÷ -Ñ ,å 1Ý XÝ 9áÝEÝWÝDôV õ Vr2   