o
    xi                     @  sr   d Z ddlmZ ddlZddlZddlZddlZddlZe	 Z
dZdZg dZdddZdddZdddZdS )a:  Integration module for automatic Weave initialization with W&B.

This module provides automatic initialization of Weave when:
1. Weave is installed
2. A W&B run is active with a project
3. Weave is imported (init-on-import)

The integration can be disabled by setting the WANDB_DISABLE_WEAVE environment variable.
    )annotationsNWANDB_DISABLE_WEAVEweave)	anthropicautogencoherecrewaidspyzgoogle.genaigroqzhuggingface_hub.inference
instructor	langchainlitellmllama_indexmcpmistral
notdiamondopenaiagents
smolagentsverdict	verifiersvertexaientity
str | NoneprojectreturnNonec              
   C  s   t trdS |sdS | r|  d| }n|}ttjvr!t  dS td zt	| W dS  t
yH } ztd|  W Y d}~dS d}~ww )zSet up automatic Weave initialization for the current W&B run.

    Args:
        project: The W&B project name to use for Weave initialization.
    N/zInitializing weave.z*Failed to automatically initialize weave: )osgetenv_DISABLE_WEAVE_WEAVE_PACKAGE_NAMEsysmodules!_maybe_suggest_weave_installationwandbtermlog_weave_init	Exceptiontermwarn)r   r   project_pathe r,   Q/home/ubuntu/.local/lib/python3.10/site-packages/wandb/integration/weave/weave.pysetup3   s"   


r.   c                  C  sp   dd t D } | sdS tjt}|du rd}nd}tjdd|  dd	d
 tj|d	d
 tjdd	d
 dS )zGSuggest Weave installation or import if any target library is imported.c                 S  s   g | ]	}|t jv r|qS r,   )r"   r#   ).0libr,   r,   r-   
<listcomp>U   s    z5_maybe_suggest_weave_installation.<locals>.<listcomp>NzUse W&B Weave for improved LLM call tracing. Install Weave with `pip install weave` then add `import weave` to the top of your script.zUse W&B Weave for improved LLM call tracing. Weave is installed but not imported. Add `import weave` to the top of your script.z
Detected [z, z	] in use.F)repeatzIFor more information, check out the docs at: https://weave-docs.wandb.ai/)_AVAILABLE_WEAVE_INTEGRATIONS	importlibutil	find_specr!   r%   r&   join)imported_libs
weave_specmsgr,   r,   r-   r$   S   s   
r$   r*   strc                 C  s<   t  ddl}||  W d   dS 1 sw   Y  dS )zPCall weave.init(), assuming weave has been imported.

    Patched in tests.
    r   N)_weave_init_lockr   init)r*   r   r,   r,   r-   r'   o   s   "r'   )r   r   r   r   r   r   )r   r   )r*   r;   r   r   )__doc__
__future__r   importlib.utilr4   r   r"   	threadingr%   Lockr<   r    r!   r3   r.   r$   r'   r,   r,   r,   r-   <module>   s    


 