Ë
    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 Audio Transcription Handler for Unified Guardrails

This module provides guardrail translation support for OpenAI's audio transcription endpoint.
The handler processes the output transcribed text (input is audio, so no text to guardrail).
é    )ÚTYPE_CHECKINGÚAnyÚFinal)Úverbose_proxy_logger)ÚBaseTranslation)ÚGenericGuardrailAPIInputs)ÚCustomGuardrail)ÚLogging)ÚTranscriptionResponsec                   ó`   — 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)ÚOpenAIAudioTranscriptionHandleraB  
    Handler for processing OpenAI audio transcription responses with guardrails.

    This class provides methods to:
    1. Process output transcription text (post-call hook)

    Note: Input processing is not applicable since the input is an audio file,
    not text. Only the transcribed text output is processed.
    NÚdataÚguardrail_to_applyr	   Úlitellm_logging_objzLiteLLMLoggingObj | NoneÚreturnc              ƒ   ó8   K  — t        j                  d«       |S ­w)a¹  
        Process input - not applicable for audio transcription.

        The input is an audio file, not text, so there's nothing to apply
        guardrails to. This method returns the data unchanged.

        Args:
            data: Request data dictionary containing audio file
            guardrail_to_apply: The guardrail instance (unused)

        Returns:
            Unmodified data (audio files don't need text guardrails)
        z[OpenAI Audio Transcription: Input processing not applicable (input is audio file, not text))r   Údebug)Úselfr   r   r   s       ú…/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/openai/transcriptions/guardrail_translation/handler.pyÚprocess_input_messagesz6OpenAIAudioTranscriptionHandler.process_input_messages   s    è ø€ ô& 	×"Ñ"Øiô	
ð ˆùs   ‚Úresponser   Úuser_api_key_dictÚrequest_datac              ƒ   ó²  K  — t        |d«      r|j                  €t        j                  d«       |S t	        |j                  t
        «      rÞ|j                  }|€d|i}n	d|vr||d<   d|vr| j                  |«      }|r||d<   t        |g¬«      }t        |d«      r|j                  r|j                  |d<   |j                  ||d|¬«      ƒ d{  –—† }	|	j                  d	g «      }
|
r|
d
   n||_        t        j                  dt        |«      t        |j                  «      «       |S t        j                  dt        |j                  «      «       |S 7 Œ„­w)aÙ  
        Process output transcription by applying guardrails to transcribed text.

        Args:
            response: Transcription response object containing transcribed text
            guardrail_to_apply: The guardrail instance to apply
            litellm_logging_obj: Optional logging object
            user_api_key_dict: User API key metadata to pass to guardrails

        Returns:
            Modified response with guardrails applied to transcribed text
        ÚtextNz:OpenAI Audio Transcription: No text in response to processr   Úlitellm_metadata)ÚtextsÚmodel)Úinputsr   Ú
input_typeÚlogging_objr   r   zfOpenAI Audio Transcription: Applied guardrail to transcribed text. Original length: %d, New length: %dzFOpenAI Audio Transcription: Unexpected text type: %s. Expected string.)Úhasattrr   r   r   Ú
isinstanceÚstrÚ'transform_user_api_key_dict_to_metadatar   r   Úapply_guardrailÚgetÚlenÚtype)r   r   r   r   r   r   Úoriginal_textÚuser_metadatar   Úguardrailed_inputsÚguardrailed_textss              r   Úprocess_output_responsez7OpenAIAudioTranscriptionHandler.process_output_response7   sc  è ø€ ô( �x Ô(¨H¯M©MÐ,AÜ ×&Ñ&Ð'cÔdØˆOä�h—m‘m¤SÔ)Ø#+§=¡=ˆMð Ð#Ø *¨HÐ5‘à \Ñ1Ø/7�L Ñ,ð "¨Ñ5Ø'+×'SÑ'SÐTeÓ'f�Ù Ø7D�LÐ!3Ñ4ä5¸]¸OÔLˆFä�x Ô)¨h¯nªnØ"*§.¡.��w‘Ø.@×.PÑ.PØØ)Ø%Ø/ð	 /Qó /÷ )Ðð (:×'=Ñ'=¸gÀrÓ'JÐÙ4EÐ-¨aÒ0È=ˆHŒMä ×&Ñ&ð6ä�MÓ"Ü�H—M‘MÓ"ô	ð ˆô !×&Ñ&ØXÜ�X—]‘]Ó#ôð
 ˆð+)ús   ‚CEÃEÃBE)N)NNN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Údictr   r   r.   © ó    r   r   r      s�   „ ñð ;?ñ	àðð .ðð 8ð	ð
 
óð8 ;?Ø(,Ø$(ñAà)ðAð .ðAð 8ð	Að
  ™:ðAð ˜T‘kðAð 
ôAr5   r   N)r2   Ú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.utilsr   r   r4   r5   r   ú<module>r>      s5   ðñ÷ -Ñ ,å 1Ý XÝ 9áÝEÝWÝ3ôd oõ dr5   