Ë
    tPêjÒ  ã                   ó`   — d dl Z d dlmZmZmZ d dlmZ erd dlmZ	 e	ez  ZneZ G d„ d«      Z
y)é    N)ÚTYPE_CHECKINGÚAnyÚFinal)ÚSpanAttributes)ÚSpanc                   óL   — e Zd ZdZdefd„Zdefd„Zdefd„Zdefd„Zdefd„Z	y)	ÚLangtraceAttributeszJ
    This class is used to save trace attributes to Langtrace's spans
    Úspanc                 óâ   — |j                  d«      j                  d«      }|j                  di «      }i |¥|¥}| j                  |||«       | j                  ||«       | j                  ||«       y)zE
        This function is used to log the event to Langtrace
        Úlitellm_paramsÚcustom_llm_providerÚoptional_paramsN)ÚgetÚset_request_attributesÚset_response_attributesÚset_usage_attributes)Úselfr
   ÚkwargsÚresponse_objÚvendorr   Úoptionss          úc/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/integrations/langtrace.pyÚset_langtrace_attributesz,LangtraceAttributes.set_langtrace_attributes   sq   € ð
 Ÿ
™
Ð#3Ó4×8Ñ8Ð9NÓOˆØ!'§¡Ð,=¸rÓ!BˆØ6˜FÐ6 oÐ6ˆØ×#Ñ# D¨'°6Ô:Ø×$Ñ$ T¨<Ô8Ø×!Ñ! $¨Õ5ó    c                 ó  — ddd|t         j                  j                  |j                  d«      t         j                  j                  |j                  d«      t         j
                  j                  |j                  d«      t         j                  j                  |j                  d«      t         j                  j                  |j                  d«      t         j                  j                  |j                  d	«      t         j                  j                  |j                  d
«      t         j                  j                  |j                  d«      t         j                  j                  |j                  d«      t         j                  j                  |j                  d«      i}|j                  d«      }|r@|j                  dt         j                  j                  t        j                   |«      i¬«       | j#                  ||«       y)zR
        This function is used to get span attributes for the LLM request
        zgen_ai.operation.nameÚchatzlangtrace.service.nameÚmodelÚstreamÚtemperatureÚtop_kÚtop_pÚuserÚ
max_tokensÚstopÚfrequency_penaltyÚpresence_penaltyÚmessageszgen_ai.content.prompt©ÚnameÚ
attributesN)r   ÚLLM_REQUEST_MODELÚvaluer   ÚLLM_IS_STREAMINGÚLLM_REQUEST_TEMPERATUREÚ	LLM_TOP_KÚLLM_REQUEST_TOP_PÚLLM_USERÚLLM_REQUEST_MAX_TOKENSÚLLM_RESPONSE_STOP_REASONÚLLM_FREQUENCY_PENALTYÚLLM_PRESENCE_PENALTYÚ	add_eventÚLLM_PROMPTSÚjsonÚdumpsÚset_span_attributes)r   r
   r   r   Úspan_attributesÚpromptss         r   r   z*LangtraceAttributes.set_request_attributes   sq  € ð
 $ VØ$ fÜ×,Ñ,×2Ñ2°F·J±J¸wÓ4GÜ×+Ñ+×1Ñ1°6·:±:¸hÓ3GÜ×2Ñ2×8Ñ8¸&¿*¹*À]Ó:SÜ×$Ñ$×*Ñ*¨F¯J©J°wÓ,?Ü×,Ñ,×2Ñ2°F·J±J¸wÓ4GÜ×#Ñ#×)Ñ)¨6¯:©:°fÓ+=Ü×1Ñ1×7Ñ7¸¿¹ÀLÓ9QÜ×3Ñ3×9Ñ9¸6¿:¹:ÀfÓ;MÜ×0Ñ0×6Ñ6¸¿
¹
ÐCVÓ8WÜ×/Ñ/×5Ñ5°v·z±zÐBTÓ7Uð"
ˆð  Ÿ™ JÓ/ˆáØ�N‰NØ,Ü*×6Ñ6×<Ñ<¼d¿j¹jÈÓ>QÐRð ô ð
 	× Ñ   Õ7r   c                 ó  — d|j                  d«      d|j                  d«      t        j                  j                  |j                  d«      i}g }|j                  dg «      D ]V  }|j                  d«      j                  d«      }|j                  d«      j                  d	«      }|j	                  ||d
œ«       ŒX |j                  dt        j                  t        j                  |«      i¬«       | j                  ||«       y)zS
        This function is used to get span attributes for the LLM response
        zgen_ai.response_idÚidzgen_ai.system_fingerprintÚsystem_fingerprintr   ÚchoicesÚmessageÚroleÚcontent)rB   rC   zgen_ai.content.completionr(   N)
r   r   ÚLLM_RESPONSE_MODELr,   Úappendr6   ÚLLM_COMPLETIONSr8   r9   r:   )r   r
   r   Úresponse_attributesÚcompletionsÚchoicerB   rC   s           r   r   z+LangtraceAttributes.set_response_attributes<   só   € ð
 ! ,×"2Ñ"2°4Ó"8Ø'¨×)9Ñ)9Ð:NÓ)OÜ×-Ñ-×3Ñ3°\×5EÑ5EÀgÓ5Nð&
Ðð
  ˆØ"×&Ñ& y°"Ó5ò 	CˆFØ—:‘:˜iÓ(×,Ñ,¨VÓ4ˆDØ—j‘j Ó+×/Ñ/°	Ó:ˆGØ×Ñ¨¸ÑAÕBð	Cð
 	�‰Ø,Ü&×6Ñ6¼¿
¹
À;Ó8OÐPð 	ô 	
ð
 	× Ñ  Ð':Õ;r   c                 óJ  — |j                  d«      }|r�t        j                  j                  |j                  d«      t        j                  j                  |j                  d«      t        j
                  j                  |j                  d«      i}| j                  ||«       yy)zP
        This function is used to get span attributes for the LLM usage
        ÚusageÚprompt_tokensÚcompletion_tokensÚtotal_tokensN)r   r   ÚLLM_USAGE_PROMPT_TOKENSr,   ÚLLM_USAGE_COMPLETION_TOKENSÚLLM_USAGE_TOTAL_TOKENSr:   )r   r
   r   rK   Úusage_attributess        r   r   z(LangtraceAttributes.set_usage_attributesR   s†   € ð $×'Ñ'¨Ó0ˆÙä×6Ñ6×<Ñ<¸e¿i¹iÈÓ>XÜ×:Ñ:×@Ñ@À%Ç)Á)ÐL_ÓB`Ü×5Ñ5×;Ñ;¸U¿Y¹YÀ~Ó=Vð'Ðð
 ×$Ñ$ TÐ+;Õ<ð r   c                 ó^   — |j                  «       D ]  \  }}|sŒ	|j                  ||«       Œ y)z>
        This function is used to set span attributes
        N)ÚitemsÚset_attribute)r   r
   r*   Úkeyr,   s        r   r:   z'LangtraceAttributes.set_span_attributes_   s6   € ð %×*Ñ*Ó,ò 	+‰JˆC�ÙØØ×Ñ˜s EÕ*ñ	+r   N)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r   r   r   r   r   r:   © r   r   r	   r	      sC   „ ñð
6¨Tó 
6ð8¨4ó 8ð:<¨Dó <ð,=¨ó =ð+¨ô +r   r	   )r8   Útypingr   r   r   Úlitellm.proxy._typesr   Úopentelemetry.tracer   Ú_Spanr	   r[   r   r   ú<module>r`      s1   ðÛ ß ,Ñ ,å /áÝ1à�3‰;�Dà€D÷X+ò X+r   