§
    šŠtj¥G  ã                  ó   — d Z ddlmZ ddlZddlmZmZmZmZm	Z	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 ddlmZ erdd	lmZ dd
lmZ ddlmZ ddlmZ dZ d#d„Z!d$d„Z"	 d%d&d„Z#	 	 d'd(d„Z$d)d„Z% G d„ d e¦  «        Z& G d!„ d"e¦  «        Z'dS )*zBA Tracer Implementation that records activity to Weights & Biases.é    )ÚannotationsN)
ÚTYPE_CHECKINGÚAnyÚCallableÚDictÚListÚOptionalÚSequenceÚTupleÚ	TypedDictÚUnion)Úwarn_deprecated)ÚPydanticBaseModel)Ú
BaseTracer)ÚRun)ÚSettings)ÚTrace)ÚStrPathTÚrun_ioúOptional[dict]ÚreturnÚdictc                ó®  — | si S ddl m} ddlm} i }|                      ¦   «         D ]­\  }}t          ||¦  «        r ||¦  «        ||<   Œ$t          |t          ¦  «        r<t          |d¦  «        r|                     ¦   «         n| 	                    ¦   «         ||<   Œu|dk    r-| 
                    d„ t          |¦  «        D ¦   «         ¦  «         Œ¨|||<   Œ®|S )zþUtility to serialize the input and output of a run to store in wandb.
    Currently, supports serializing pydantic models and protobuf messages.

    :param run_io: The inputs and outputs of the run.
    :return: The serialized inputs and outputs.


    r   )ÚMessageToJson)ÚMessageÚmodel_dump_jsonÚinput_documentsc                óD   — i | ]\  }}d |› �|                      ¦   «         “ŒS )Úinput_document_)Újson)Ú.0ÚiÚdocs      úi/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/langchain_community/callbacks/tracers/wandb.pyú
<dictcomp>z!_serialize_io.<locals>.<dictcomp>=   s/   € ÐRÐRÐR±v°q¸#Ð& 1Ð&Ð&¨¯ª©
¬
ÐRÐRÐRó    )Úgoogle.protobuf.json_formatr   Úgoogle.protobuf.messager   ÚitemsÚ
isinstancer   Úhasattrr   r    ÚupdateÚ	enumerate)r   r   r   Úserialized_inputsÚkeyÚvalues         r$   Ú_serialize_ior1   !   s+  € ð ð Øˆ	Ø9Ð9Ð9Ð9Ð9Ð9Ø/Ð/Ð/Ð/Ð/Ð/àÐØ—l’l‘n”nð +ð +‰
ˆˆUÝ�e˜WÑ%Ô%ð 	+Ø%2 ]°5Ñ%9Ô%9Ð˜cÑ"Ð"å˜Õ0Ñ1Ô1ð 	+õ ˜5Ð"3Ñ4Ô4ð"�×%Ò%Ñ'Ô'Ð'à—Z’Z‘\”\ð ˜cÑ"Ð"ð Ð%Ò%Ð%Ø×$Ò$ØRÐRÅÈ5ÑAQÔAQÐRÑRÔRñô ð ð ð &+Ð˜cÑ"Ð"ØÐr&   ÚrunúDict[str, Any]úList[Dict[str, Any]]c                ó(   ‡— dˆfd„Š ‰| g¦  «        S )z�Utility to flatten a nest run object into a list of runs.
    :param run: The base run to flatten.
    :return: The flattened list of runs.
    Ú
child_runsr4   r   c                ó°   •— | €g S g }| D ]K}|                      dg ¦  «        } |                     |¦  «         |                      ‰| ¦  «        ¦  «         ŒL|S )z±Utility to recursively flatten a list of child runs in a run.
        :param child_runs: The list of child runs to flatten.
        :return: The flattened list of runs.
        Nr6   )ÚpopÚappendÚextend)r6   ÚresultÚitemÚflattens      €r$   r=   zflatten_run.<locals>.flattenJ   sm   ø€ ð
 ÐØˆIàˆØð 	/ð 	/ˆDØŸš ,°Ñ3Ô3ˆJØ�MŠM˜$ÑÔÐØ�MŠM˜'˜' *Ñ-Ô-Ñ.Ô.Ð.Ð.àˆr&   )r6   r4   r   r4   © )r2   r=   s    @r$   Úflatten_runr?   D   s3   ø€ ðð ð ð ð ð ð  ˆ7�C�5‰>Œ>Ðr&   r>   ÚrunsÚ	keep_keysúTuple[str, ...]c                óJ   ‡— dˆfd„}t          t          || ¦  «        ¦  «        S )zõUtility to truncate a list of runs dictionaries to only keep the specified
        keys in each run.
    :param runs: The list of runs to truncate.
    :param keep_keys: The keys to keep in each run.
    :return: The truncated list of runs.
    r2   r3   r   c                óN   •— i }| D ]}|‰v r|                       |¦  «        ||<   Œ|S )zÃUtility to truncate a single run dictionary to only keep the specified
            keys.
        :param run: The run dictionary to truncate.
        :return: The truncated run dictionary
        )Úget)r2   Únew_dictr/   rA   s      €r$   Útruncate_singlez/truncate_run_iterative.<locals>.truncate_singleg   s=   ø€ ð ˆØð 	-ð 	-ˆCØ�iÐÐØ #§¢¨¡¤�˜‘øØˆr&   ©r2   r3   r   r3   ©ÚlistÚmap)r@   rA   rG   s    ` r$   Útruncate_run_iterativerL   ]   s;   ø€ ð
ð 
ð 
ð 
ð 
ð 
õ •�O TÑ*Ô*Ñ+Ô+Ð+r&   Ú
exact_keysÚpartial_keysc                ó~   ‡‡‡‡‡— dˆˆˆfd„Šddˆfd„Šdˆˆfd
„Šdˆfd„}t          t          || ¦  «        ¦  «        S )aš  Utility to modify the serialized field of a list of runs dictionaries.
    removes any keys that match the exact_keys and any keys that contain any of the
    partial_keys.
    recursively moves the dictionaries under the kwargs key to the top level.
    changes the "id" field to a string "_kind" field that tells WBTraceTree how to
    visualize the run. promotes the "serialized" field to the top level.
    :param runs: The list of runs to modify.
    :param exact_keys: A tuple of keys to remove from the serialized field.
    :param partial_keys: A tuple of partial keys to remove from the serialized
        field.
    :return: The modified list of runs.
    Úobjr3   r   c                ó  •— t          | t          ¦  «        rJˆˆfd„|                      ¦   «         D ¦   «         } |                      ¦   «         D ]\  }} ‰|¦  «        | |<   Œn#t          | t          ¦  «        rˆfd„| D ¦   «         } | S )z¨Recursively removes exact and partial keys from a dictionary.
        :param obj: The dictionary to remove keys from.
        :return: The modified dictionary.
        c                ó\   •‡— i | ]'\  Š}‰‰v¯	t          ˆfd „‰D ¦   «         ¦  «        °$‰|“Œ(S )c              3  ó    •K  — | ]}|‰v V — Œ	d S ©Nr>   )r!   ÚpartialÚks     €r$   ú	<genexpr>z`modify_serialized_iterative.<locals>.remove_exact_and_partial_keys.<locals>.<dictcomp>.<genexpr>’   s'   øè è € ÐEÐE¨W˜G q˜LÐEÐEÐEÐEÐEÐEr&   )Úany)r!   ÚvrV   rM   rN   s     @€€r$   r%   zVmodify_serialized_iterative.<locals>.remove_exact_and_partial_keys.<locals>.<dictcomp>Ž   sZ   øø€ ð ð ð á�A�qØ˜JÐ&Ð&ÝÐEÐEÐEÐE¸ÐEÑEÔEÑEÔEð 'ð �1à&Ð&Ð&r&   c                ó&   •— g | ]} ‰|¦  «        ‘ŒS r>   r>   )r!   ÚxÚremove_exact_and_partial_keyss     €r$   ú
<listcomp>zVmodify_serialized_iterative.<locals>.remove_exact_and_partial_keys.<locals>.<listcomp>—   s%   ø€ ÐAÐAÐA¸Ð0Ð0°Ñ3Ô3ÐAÐAÐAr&   )r*   r   r)   rJ   )rP   rV   rY   rM   rN   r\   s      €€€r$   r\   zBmodify_serialized_iterative.<locals>.remove_exact_and_partial_keysˆ   s¶   ø€ õ
 �c�4Ñ Ô ð 
	Bðð ð ð ð àŸIšI™KœKðñ ô ˆCð Ÿ	š	™œð :ð :‘��1Ø6Ð6°qÑ9Ô9��A‘�ð:å˜�TÑ"Ô"ð 	BØAÐAÐAÐA¸SÐAÑAÔAˆCØˆ
r&   FÚrootÚboolc                ó�  •— t          | t          ¦  «        �rd| v r#t          | d         t          ¦  «        r| d         } d| v sd| v r³|s±|                      d¦  «        }|s|                      d¦  «        g}t          |t          ¦  «        r7|d         | d<   |                      dd¦  «         |                      dd¦  «         d| v r4|                      d¦  «        }|                     ¦   «         D ]
\  }}|| |<   Œ|                      ¦   «         D ]\  }} ‰|¦  «        | |<   Œn#t          | t          ¦  «        rˆfd„| D ¦   «         } | S )	aÕ  Recursively handles the id and kwargs fields of a dictionary.
        changes the id field to a string "_kind" field that tells WBTraceTree how
        to visualize the run. recursively moves the dictionaries under the kwargs
        key to the top level.
        :param obj: a run dictionary with id and kwargs fields.
        :param root: whether this is the root dictionary or the serialized
            dictionary.
        :return: The modified dictionary.
        ÚdataÚidÚnameéÿÿÿÿÚ_kindNÚkwargsc                ó&   •— g | ]} ‰|¦  «        ‘ŒS r>   r>   )r!   r[   Úhandle_id_and_kwargss     €r$   r]   zMmodify_serialized_iterative.<locals>.handle_id_and_kwargs.<locals>.<listcomp>¶   s%   ø€ Ð8Ð8Ð8¨qÐ'Ð'¨Ñ*Ô*Ð8Ð8Ð8r&   )r*   r   rE   rJ   r8   r)   )rP   r^   re   rf   rV   rY   rh   s         €r$   rh   z9modify_serialized_iterative.<locals>.handle_id_and_kwargsš   sf  ø€ õ �c�4Ñ Ô ñ 	9Ø˜ˆ}ˆ}¥¨C°¬K½Ñ!>Ô!>ˆ}Ø˜&”k�Ø˜��˜v¨˜}˜}°d˜}ØŸš ™œ�Øð .Ø ŸWšW V™_œ_Ð-�EÝ˜e¥TÑ*Ô*ð *Ø#(¨¤9�C˜‘LØ—G’G˜D $Ñ'Ô'Ð'Ø—G’G˜F DÑ)Ô)Ð)Ø˜s�?�?Ø ŸWšW XÑ.Ô.�FØ &§¢¡¤ð #ð #™˜˜1Ø!"˜˜A™˜ØŸ	š	™œð 1ð 1‘��1Ø-Ð-¨aÑ0Ô0��A‘�ð1å˜�TÑ"Ô"ð 	9Ø8Ð8Ð8Ð8°CÐ8Ñ8Ô8ˆCØˆ
r&   Ú
serializedc                ó8   •—  ‰| d¬¦  «        }  ‰| ¦  «        } | S )zãTransforms the serialized field of a run dictionary to be compatible
            with WBTraceTree.
        :param serialized: The serialized field of a run dictionary.
        :return: The transformed serialized field.
        T)r^   r>   )ri   rh   r\   s    €€r$   Útransform_serializedz9modify_serialized_iterative.<locals>.transform_serialized¹   s0   ø€ ð *Ð)¨*¸4Ð@Ñ@Ô@ˆ
Ø2Ð2°:Ñ>Ô>ˆ
ØÐr&   r2   c                óð   •—  ‰| ¦  «        }|                      d¦  «        }|                     ¦   «         D ]
\  }}|||<   Œ|                     dd¦  «        }|                      dd¦  «        }|s|}|› |i}|S )z­Transforms a run dictionary to be compatible with WBTraceTree.
        :param run: The run dictionary to transform.
        :return: The transformed run dictionary.
        ri   re   Nrc   )r8   r)   rE   )	r2   Útransformed_dictri   rV   rY   re   rc   Úoutput_dictrk   s	           €r$   Útransform_runz2modify_serialized_iterative.<locals>.transform_runÃ   s¦   ø€ ð
 0Ð/°Ñ4Ô4Ðà%×)Ò)¨,Ñ7Ô7ˆ
Ø×$Ò$Ñ&Ô&ð 	$ð 	$‰DˆAˆqØ"#Ð˜QÑÐà ×$Ò$ W¨dÑ3Ô3ˆØ×#Ò# F¨DÑ1Ô1ˆàð 	ØˆDð ˆIÐ'ð
ˆð Ðr&   )rP   r3   r   r3   ©F)rP   r3   r^   r_   r   r3   )ri   r3   r   r3   rH   rI   )r@   rM   rN   ro   rh   r\   rk   s    `` @@@r$   Úmodify_serialized_iterativerq   v   s­   øøøøø€ ð$ð ð ð ð ð ð ð ð$ð ð ð ð ð ð ð>ð ð ð ð ð ð ðð ð ð ð ð õ, •�M 4Ñ(Ô(Ñ)Ô)Ð)r&   c           	     óB  ‡— i }i Š| D ]V}|                      ¦   «         D ]?\  }}|                     dd¦  «        }|                     dd¦  «        }||i||<   |r|‰|<   Œ@ŒW‰                      ¦   «         D ]~\  }}||         }	||         t          t          ||         ¦  «        ¦  «                 |	t          t          |	¦  «        ¦  «                 t          t          ||         ¦  «        ¦  «        <   Œt          ˆfd„|                      ¦   «         D ¦   «         ¦  «        }
|
S )zéBuilds a nested dictionary from a list of runs.
    :param runs: The list of runs to build the tree from.
    :return: The nested dictionary representing the langchain Run in a tree
        structure compatible with WBTraceTree.
    rb   NÚparent_run_idc              3  ó*   •K  — | ]\  }}|‰v¯	|V — Œd S rT   r>   )r!   Úid_valra   Úchild_to_parents      €r$   rW   zbuild_tree.<locals>.<genexpr>ó   s:   øè è € ð ð Ù�˜°vÀ_Ð7TÐ7TˆÐ7TÐ7TÐ7TÐ7Tðð r&   )r)   r8   ÚnextÚiter)r@   Ú
id_to_dataÚentityr/   ra   ru   rs   Úchild_idÚ	parent_idÚparent_dictÚ	root_dictrv   s              @r$   Ú
build_treer   Ü   sU  ø€ ð €JØ€Oàð 8ð 8ˆØŸš™œð 	8ð 	8‰IˆC�Ø—X’X˜d DÑ)Ô)ˆFØ ŸHšH _°dÑ;Ô;ˆMØ"% t ˆJ�vÑØð 8Ø*7� Ñ'øð	8ð  /×4Ò4Ñ6Ô6ð 
ð 
Ñˆ�)Ø  Ô+ˆà�xÔ ¥¥d¨:°hÔ+?Ñ&@Ô&@Ñ!AÔ!AÔBð 	•D�˜kÑ*Ô*Ñ+Ô+Ô,­Tµ$°zÀ(Ô7KÑ2LÔ2LÑ-MÔ-MÑNÐNõ ð ð ð ð Ø!+×!1Ò!1Ñ!3Ô!3ðñ ô ñ ô €Ið Ðr&   c                  ó  — e Zd ZU dZded<   ded<   ded<   ded<   ded	<   d
ed<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   ded<   d
ed<   ded<   d
ed<   d
ed<   d
ed<   d
ed<   d
ed<   ded <   d!ed"<   d#S )$ÚWandbRunArgszArguments for the WandbTracer.zOptional[str]Újob_typezOptional[StrPath]ÚdirzUnion[Dict, str, None]ÚconfigÚprojectrz   zOptional[bool]ÚreinitzOptional[Sequence]ÚtagsÚgrouprc   Únotesz Optional[Union[dict, str, bool]]ÚmagiczOptional[List[str]]Úconfig_exclude_keysÚconfig_include_keysÚ	anonymousÚmodeÚallow_val_changezOptional[Union[bool, str]]ÚresumeÚforceÚtensorboardÚsync_tensorboardÚmonitor_gymÚ	save_coderb   z'Union[WBSettings, Dict[str, Any], None]ÚsettingsN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Ú__annotations__r>   r&   r$   r�   r�   ú   s8  € € € € € € Ø(Ð(àÐÐÑØÐÐÑØ"Ð"Ð"Ñ"ØÐÐÑØÐÐÑØÐÐÑØÐÐÑØÐÐÑØÐÐÑØÐÐÑØ+Ð+Ð+Ñ+Ø,Ð,Ð,Ñ,Ø,Ð,Ð,Ñ,ØÐÐÑØÐÐÑØ$Ð$Ð$Ñ$Ø&Ð&Ð&Ñ&ØÐÐÑØÐÐÑØ$Ð$Ð$Ñ$ØÐÐÑØÐÐÑØÐÐÑØ5Ð5Ð5Ñ5Ð5Ð5r&   r�   c                  ór   ‡ — e Zd ZU dZdZded<   dZded<   defdˆ fd„Zdd„Z	ddd„Z
dd„Zd d„Zd!d„Zˆ xZS )"ÚWandbTracerzÑCallback Handler that logs to Weights and Biases.

    This handler will log the model architecture and run traces to Weights and Biases.
    This will ensure that all LangChain activity is logged to W&B.
    NzOptional[WBRun]Ú_runúOptional[WandbRunArgs]Ú	_run_argsÚrun_argsÚio_serializerr   rf   r   r   ÚNonec                ó.  •—  t          ¦   «         j        di |¤Ž 	 ddl}ddlm} n"# t
          $ r}t          d¦  «        |‚d}~ww xY w|| _        || _        || _        |  	                    |j
        du ¬¦  «         || _        t          dddd	¬
¦  «         dS )a  Initializes the WandbTracer.

        Parameters:
            run_args: (dict, optional) Arguments to pass to `wandb.init()`. If not
                provided, `wandb.init()` will be called with no arguments. Please
                refer to the `wandb.init` for more details.
            io_serializer: callable A function that serializes the input and outputs
             of a run to store in wandb. Defaults to "_serialize_io"

        To use W&B to monitor all LangChain activity, add this tracer like any other
        LangChain callback:
        ```
        from wandb.integration.langchain import WandbTracer

        tracer = WandbTracer()
        chain = LLMChain(llm, callbacks=[tracer])
        # ...end of notebook / script:
        tracer.finish()
        ```
        r   N)Ú
trace_treezTCould not import wandb python package.Please install it with `pip install -U wandb`.)Úshould_print_urlz0.3.8Fa   Please use the `WeaveTracer` from the `weave` package instead of this.The `WeaveTracer` is a more flexible and powerful tool for logging and tracing your LangChain callables.Find more information at https://weave-docs.wandb.ai/guides/integrations/langchainz¶Please instantiate the WeaveTracer from `weave.integrations.langchain import WeaveTracer` .For autologging simply use `weave.init()` and log all traces from your LangChain callables.)ÚpendingÚmessageÚalternativer>   )ÚsuperÚ__init__ÚwandbÚwandb.sdk.data_typesr¥   ÚImportErrorÚ_wandbÚ_trace_treer    Ú_ensure_runr2   Ú_io_serializerr   )Úselfr¡   r¢   rf   r¬   r¥   ÚeÚ	__class__s          €r$   r«   zWandbTracer.__init__!  sñ   ø€ ð4 	�‰ŒÔÐ"Ð"˜6Ð"Ð"Ð"ð	ØˆLˆLˆLØ7Ð7Ð7Ð7Ð7Ð7Ð7øÝð 	ð 	ð 	ÝðAñô ð ðøøøøð	øøøð
 ˆŒØ%ˆÔØ!ˆŒØ×Ò¨5¬9¸Ð+<ÐÑ>Ô>Ð>Ø+ˆÔÝØØðeð1ð	
ñ 	
ô 	
ð 	
ð 	
ð 	
s   œ
' §
A±AÁAc                ó8   — | j                              ¦   «          dS )zpWaits for all asynchronous processes to finish and data to upload.

        Proxy for `wandb.finish()`.
        N)r¯   Úfinish)r³   s    r$   r·   zWandbTracer.finishZ  s   € ð
 	Œ×ÒÑÔÐÐÐr&   Fr¦   r_   c                ó6  — | j         j        €(i | j        pi ¥}d|vrddi|d<    | j         j        d	i |¤Ž | j         j        �X|r4| j         j        j        j        }| j                              d|› d�¦  «         | j         j                             d¬¦  «         dS dS )
zlEnsures an active W&B run exists.

        If not, will start a new run with the provided run_args.
        Nr–   ÚsilentTz'Streaming LangChain activity to W&B at z€
`WandbTracer` is currently in beta.
Please report any issues to https://github.com/wandb/wandb/issues with the tag `langchain`.Ú	langchain)Úrepor>   )r¯   r2   r    Úinitr–   Úrun_urlÚtermlogÚ_label)r³   r¦   r¡   r½   s       r$   r±   zWandbTracer._ensure_runa  sÐ   € ð
 Œ;Œ?Ð"Ø7 ¤Ð!5°2Ð7ˆHà Ð)Ð)Ø(0°$Ð'7�˜Ñ$àˆDŒKÔÐ(Ð(˜xÐ(Ð(Ð(ØŒ;Œ?Ð&Øð Øœ+œ/Ô2Ô:�Ø”×#Ò#ð#¸gð #ð #ð #ñô ð ð ŒKŒO×"Ò"¨Ð"Ñ4Ô4Ð4Ð4Ð4ð 'Ð&r&   r2   r   úOptional[Dict[str, Any]]c                ó\  — 	 t          j        |                      ¦   «         ¦  «        }t          |¦  «        }d}t          ||¬¦  «        }d\  }}t	          |||¬¦  «        }t          |¦  «        }|S # t          $ r/}t          r| j         	                    d|› �¦  «         Y d}~dS d}~ww xY w)z­Utility to process a run for wandb model_dict serialization.
        :param run: The run to process.
        :return: The convert model_dict to pass to WBTraceTree.
        )rb   rc   ri   rs   )rA   ))ÚlcÚtypeÚgraph)Úapi_keyÚinputÚoutput)rM   rN   z$WARNING: Failed to serialize model: N)
r    Úloadsr?   rL   rq   r   Ú	ExceptionÚPRINT_WARNINGSr¯   Ú	termerror)	r³   r2   ra   Ú	processedrA   rM   rN   rÇ   r´   s	            r$   Úprocess_model_dictzWandbTracer.process_model_dictz  s×   € ð
	Ý”:˜cŸhšh™jœjÑ)Ô)ˆDÝ# DÑ)Ô)ˆIðˆIõ /¨yÀIÐNÑNÔNˆIð(Ñ$ˆJ˜õ 4Ø j¸|ðñ ô ˆIõ   	Ñ*Ô*ˆFØˆMøÝð 	ð 	ð 	Ýð RØ”×%Ò%Ð&PÈQÐ&PÐ&PÑQÔQÐQØ�4�4�4�4�4øøøøð	øøøs   ‚A/A2 Á2
B+Á<$B&Â&B+c                óè   ‡ ‡— ‰                       ¦   «          	 d	d
ˆˆ fd„Š ‰|¦  «        }‰                      |¦  «        }|�	|�||_        ‰ j        j        �|�|                     d¦  «         dS dS dS )z+Logs a LangChain Run to W*B as a W&B Trace.Nr2   ú'Run'ÚparentúOptional['Trace']r   c                óú  •— dd„}	 | j         dv r| j         }n-| j         dk    r d| j                             ¦   «         v rdnd}nd	} || ¦  «        }‰	j                             | j        || j        rd
nd| j        �)t          | j                             ¦   «         dz  ¦  «        nd	| j	        �)t          | j	                             ¦   «         dz  ¦  «        nd	|‰	 
                    | j        ¦  «        ‰	 
                    | j        ¦  «        ¬¦  «        }| j        D ]} ‰||¦  «         Œ|€|S |                     |¦  «         |S # t          $ r/}t           r‰	j                             d|› �¦  «         Y d	}~d	S d	}~ww xY w)am  
            Create a trace for a given run and its child runs.

            Args:
                run (Run): The run for which to create a trace.
                parent (Optional[Trace]): The parent trace.
                If provided, the created trace is added as a child to the parent trace.

            Returns:
                The created trace. If an error occurs during the creation of the trace,
                    None is returned.

            Raises:
                Exception: If an error occurs during the creation of the trace,
                no exception is raised and a warning is printed.
            ÚrrÏ   r   r3   c                óf  — t          j        |                       ¦   «         ¦  «        }|                     di ¦  «        }|                     d¦  «        |d<   |                     d¦  «        |d<   |                     d¦  «        |d<   |                     dd¦  «                             d¦  «        |d	<   |S )
aj  
                Extract metadata from a given run.

                This function extracts metadata from a given run
                and returns it as a dictionary.

                Args:
                    r (Run): The run from which to extract metadata.

                Returns:
                    `dict` containing the extracted metadata.
                Úmetadatarb   Úrun_idrs   r‡   Údotted_orderÚ ú.Úexecution_order)r    rÈ   rE   Úcount)rÓ   Úrun_dictÚmetadata_dicts      r$   Úget_metadata_dictzPWandbTracer._log_trace_from_run.<locals>.create_trace.<locals>.get_metadata_dict³  s¤   € õ  œ: a§f¢f¡h¤hÑ/Ô/�Ø (§¢¨Z¸Ñ <Ô <�Ø*2¯,ª,°tÑ*<Ô*<�˜hÑ'Ø19·²¸oÑ1NÔ1N�˜oÑ.Ø(0¯ª°VÑ(<Ô(<�˜fÑ%Ø3;·<²<Ø" Bñ4ô 4ç’%˜‘*”*ð Ð/Ñ0ð %Ð$r&   )ÚllmÚtoolÚchainÚagentNÚerrorÚsuccessiè  )rc   ÚkindÚstatus_codeÚstart_time_msÚend_time_msrÕ   ÚinputsÚoutputsz3WARNING: Failed to serialize trace for run due to: )rÓ   rÏ   r   r3   )Úrun_typerc   Úlowerr°   r   rã   Ú
start_timeÚintÚ	timestampÚend_timer²   ré   rê   r6   Ú	add_childrÉ   rÊ   r¯   Útermwarn)
r2   rÐ   rÞ   rë   rÕ   r¥   Ú	child_runr´   Úcreate_tracer³   s
           €€r$   rô   z5WandbTracer._log_trace_from_run.<locals>.create_traceŸ  sÔ  ø€ ð(%ð %ð %ð %ð.&Ø”< ?Ð2Ð2Ø"œ|�H�HØ”\ WÒ,Ð,Ø*1°S´X·^²^Ñ5EÔ5EÐ*EÐ*E˜w˜wÈ7�H�Hà#�Hà,Ð,¨SÑ1Ô1�Ø!Ô-×3Ò3ØœØ!Ø+.¬9Ð C  ¸)à”~Ð1õ #& c¤n×&>Ò&>Ñ&@Ô&@À4Ñ&GÑ"HÔ"HÐ"Hàà”|Ð/õ !$ C¤L×$:Ò$:Ñ$<Ô$<¸tÑ$CÑ DÔ DÐ DàØ%Ø×.Ò.¨s¬zÑ:Ô:Ø ×/Ò/°´Ñ<Ô<ð 4ñ ô �
ð  "%¤ð 8ð 8�IØ �L ¨JÑ7Ô7Ð7Ð7à�>Ø%Ð%à×$Ò$ ZÑ0Ô0Ð0Ø!�MøÝð ð ð Ý!ð Ø”K×(Ò(ØQÈaÐQÐQñô ð ð �t�t�t�t�tøøøøðøøøs   ‡D"E Ä*E Å
E:Å$E5Å5E:Úlangchain_tracerT   )r2   rÏ   rÐ   rÑ   r   rÑ   )r±   rÍ   Ú_model_dictr¯   r2   Úlog)r³   r2   Ú	run_traceÚ
model_dictrô   s   `   @r$   Ú_log_trace_from_runzWandbTracer._log_trace_from_run›  s¹   øø€ à×ÒÑÔÐð 59ðQ	ð Q	ð Q	ð Q	ð Q	ð Q	ð Q	ð Q	ðf !�L Ñ%Ô%ˆ	Ø×,Ò,¨SÑ1Ô1ˆ
ØÐ! iÐ&;Ø$.ˆIÔ!ØŒ;Œ?Ð&¨9Ð+@Ø�MŠMÐ+Ñ,Ô,Ð,Ð,Ð,ð 'Ð&Ð+@Ð+@r&   rÏ   c                ó0   — |                       |¦  «         dS )zPersist a run.N)rú   )r³   r2   s     r$   Ú_persist_runzWandbTracer._persist_runù  s   € à× Ò  Ñ%Ô%Ð%Ð%Ð%r&   )r¡   rŸ   r¢   r   rf   r   r   r£   )r   r£   rp   )r¦   r_   r   r£   )r2   r   r   rÀ   )r2   r   r   r£   )r2   rÏ   r   r£   )r—   r˜   r™   rš   rž   r›   r    r1   r«   r·   r±   rÍ   rú   rü   Ú__classcell__)rµ   s   @r$   r�   r�     sê   ø€ € € € € € ðð ð !€DÐ Ð Ð Ñ Ø(,€IÐ,Ð,Ð,Ñ,ð ,0Ø"/ð7
ð 7
ð 7
ð 7
ð 7
ð 7
ð 7
ðrð ð ð ð5ð 5ð 5ð 5ð 5ð2ð ð ð ðB\-ð \-ð \-ð \-ð|&ð &ð &ð &ð &ð &ð &ð &r&   r�   )r   r   r   r   )r2   r3   r   r4   )r>   )r@   r4   rA   rB   r   r4   )r>   r>   )r@   r4   rM   rB   rN   rB   r   r4   )r@   r4   r   r3   )(rš   Ú
__future__r   r    Útypingr   r   r   r   r   r	   r
   r   r   r   Úlangchain_core._apir   Ú&langchain_core.output_parsers.pydanticr   Úlangchain_core.tracers.baser   Úlangchain_core.tracers.schemasr   r¬   r   Ú
WBSettingsÚwandb.sdk.data_types.trace_treer   Úwandb.sdk.lib.pathsr   Úwandb.wandb_runÚWBRunrÊ   r1   r?   rL   rq   r   r�   r�   r>   r&   r$   ú<module>r	     s(  ðØ HÐ Hà "Ð "Ð "Ð "Ð "Ð "à €€€ðð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð ð 0Ð /Ð /Ð /Ð /Ð /Ø DÐ DÐ DÐ DÐ DÐ DØ 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø .Ð .Ð .Ð .Ð .Ð .àð -Ø,Ð,Ð,Ð,Ð,Ð,Ø5Ð5Ð5Ð5Ð5Ð5Ø+Ð+Ð+Ð+Ð+Ð+Ø,Ð,Ð,Ð,Ð,Ð,à€ð ð  ð  ð  ðFð ð ð ð4 >@ð,ð ,ð ,ð ,ð ,ð6 #%Ø$&ðc*ð c*ð c*ð c*ð c*ðLð ð ð ð<6ð 6ð 6ð 6ð 6�9ñ 6ô 6ð 6ð:d&ð d&ð d&ð d&ð d&�*ñ d&ô d&ð d&ð d&ð d&r&   