
    j                         d dl Z d dlZd dlZd dlmZmZmZmZmZ d dl	m
c mZ d dlmZ d dlmZmZ ddlmZ  ej&                  e      Z edd      Z e j.                  d	
       G d d             Zy)    N)AnyDictListOptionalTypeVar)ErrorInfoDictFeedbackScoreDict   )data_helpersObservationDataTObservationData)boundT)kw_onlyc                      e Zd ZU dZdZee   ed<    ej                  e
j                        Zeej                     ed<   dZeej                     ed<   dZeeeef      ed<   dZeeeef      ed<   dZeeeef      ed	<   dZeee      ed
<   dZeee      ed<   dZee   ed<   dZee   ed<   dZeeej:                        ed<   dededefdZdedefdZ deej:                     ddfdZ!y)r   a  
    Base class for TraceData and SpanData containing common attributes and methods.

    This class uses Python 3.10's kw_only=True feature to allow optional parameters
    to be defined in the parent class while child classes can have required parameters.
    Nname)default_factory
start_timeend_timemetadatainputoutputtagsfeedback_scoresproject_name
error_infoattachmentsselfnew_datareturnc                    |j                         D ]F  \  }}|
|| j                  vr|dk7  rt        j                  d|       4|dk(  r't	        j
                  | j                  |      | _        `|dk(  r't	        j                  | j                  |      | _        |dk(  r't	        j                  | j                  |      | _
        |d	k(  r| j                  |       |d
k(  r't	        j                  | j                  |      | _        |dk(  r8t	        j
                  | j                  |j                  d      |      | _        8|| j                  |<   I | S )a  
        Updates the attributes of the object with the provided key-value pairs. This method checks if
        an attribute exists before updating it and merges the data appropriately for specific
        keywords like metadata, output, input, attachments, and tags. If a key doesn't correspond
        to an attribute of the object or the provided value is None, the update is skipped.

        Args:
            **new_data: Key-value pairs of attributes to update. Keys should match existing
                attributes on the object, and values that are None will not update.

        Returns:
            The updated object instance (preserves the actual subclass type).
        promptszHAn attempt to update observation with parameter name it doesn't have: %sr   )new_metadatar   )new_outputsr   )
new_inputsr   r   )new_tags)r"   r!   )items__dict__LOGGERdebugr   merge_metadatar   merge_outputsr   merge_inputsr   _update_attachments
merge_tagsr   get)r   r   keyvalues       z/Users/manta/Documents/Projects/TheRoad-I1/backend/.venv/lib/python3.12/site-packages/opik/api_objects/observation_data.pyupdatezObservationData.update'   s>    #..*JC}$--'C9,<^ j  , ; ;MM! *88RWX)66tzzeT
%((/(33DIIN		! , ; ;MMZ0HRW! !&DMM#E +H     c                 8    t        j                         | _        | S )z1Initialize the end_time to the current timestamp.)datetime_helperslocal_timestampr   )r   s    r2   init_end_timezObservationData.init_end_time[   s    (88:r4   c                 b    | j                   || _         y| j                   j                  |       y)z)Merge new attachments with existing ones.N)r   extend)r   r   s     r2   r-   z#ObservationData._update_attachments`   s*    #*D##K0r4   )"__name__
__module____qualname____doc__r   r   str__annotations__dataclassesfieldr6   r7   r   datetimer   r   r   r   r   r   r   r   r   r	   r   r   r   r   
attachment
Attachmentr   r3   r8   r-    r4   r2   r   r      sO    D(3-.?k.?.?(88/J**+  -1Hhx(()0)-HhtCH~&-&*E8DcN#*'+FHT#s(^$+ $D(49
$9=OXd#456="&L(3-&*.J'.9=K$z4456=2% 23 2;K 2h, 1A 
1tJ4I4I/J 1t 1r4   )rA   rC   loggingtypingr   r   r   r   r   opik.api_objects.attachmentapi_objectsrD   opik.datetime_helpersr6   
opik.typesr   r	    r   	getLoggerr;   r(   r   	dataclassr   rF   r4   r2   <module>rP      sm       5 5 0 0 0 7 			8	$-5FG  t$T1 T1 %T1r4   