o
    Æ°iz  ã                   @   sä   d Z ddlZddlmZmZmZmZmZ ddl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mZmZmZ erHdd	lmZ 	dd
edeeeeeeeeeef deeeef  defdd„ZG dd„ deƒZdS )zŸ
If the LLM Obs has any specific attributes to log request or response, we can add them here.

Relevant Issue: https://github.com/BerriAI/litellm/issues/13764
é    N)ÚTYPE_CHECKINGÚAnyÚDictÚOptionalÚUnion)Ú	BaseModel)Úoverride)ÚBaseLLMObsOTELAttributesÚsafe_set_attribute)ÚHttpxBinaryResponseContentÚResponsesAPIResponse)ÚEmbeddingResponseÚImageResponseÚModelResponseÚRerankResponseÚTextCompletionResponseÚTranscriptionResponse)ÚSpanÚresponse_objÚkwargsÚreturnc                 C   s|   | du rdS |p	i }|  dd¡}|dkst| tƒrdS t| tƒr"dS t| tƒr+|  ¡ S | r<t| tƒs7t| tƒr<t 	| ¡S dS )aã  
    Extract output content from response objects based on their type.

    This utility function handles the type-specific logic for converting
    various response objects into appropriate output formats for Langfuse logging.

    Args:
        response_obj: The response object returned by the function
        kwargs: Optional keyword arguments containing call_type and other metadata

    Returns:
        The formatted output content suitable for Langfuse logging, or None
    NÚ Ú	call_typeZ	embeddingzembedding-outputzspeech-output)
ÚgetÚ
isinstancer   r   r   Zmodel_dump_jsonÚdictÚlistÚjsonÚdumps)r   r   r   © r   úm/home/app/Keep/.python/lib/python3.10/site-packages/litellm/integrations/langfuse/langfuse_otel_attributes.pyÚget_output_content_by_type   s"   

ÿÿ
r!   c                   @   s@   e Zd Zeedddeeef fdd„ƒƒZeed	dd„ƒƒZ	dS )
ÚLangfuseLLMObsOTELAttributesÚspanr   r   c                 C   sh   d|  d¡i}|  di ¡}|  d¡}|  d¡}|d ur||d< |d ur'||d< |}t| dt |¡ƒ d S )NÚmessagesÚoptional_paramsÚ	functionsÚtoolszlangfuse.observation.input)r   r
   r   r   )r#   r   Úpromptr%   r&   r'   Úinputr   r   r    Úset_messagesV   s   

z)LangfuseLLMObsOTELAttributes.set_messagesc                 C   s   t | dt|ƒƒ d S )Nzlangfuse.observation.output)r
   r!   )r#   r   r   r   r    Úset_response_output_messagese   s
   ýz9LangfuseLLMObsOTELAttributes.set_response_output_messagesN)r#   r   )
Ú__name__Ú
__module__Ú__qualname__Ústaticmethodr   r   Ústrr   r*   r+   r   r   r   r    r"   U   s    r"   )N) Ú__doc__r   Útypingr   r   r   r   r   Zpydanticr   Ztyping_extensionsr   ZElitellm.integrations.opentelemetry_utils.base_otel_llm_obs_attributesr	   r
   Zlitellm.types.llms.openair   r   Zlitellm.types.utilsr   r   r   r   r   r   Zopentelemetry.tracer   r   r   r0   r!   r"   r   r   r   r    Ú<module>   s@     	òöÿÿò
ñ6