o
    3Ih                     @   s^   d dl mZmZ d dlZd dlmZ d dlmZmZ d dl	m
Z
 d dlmZ G dd dZdS )	    )ClassVarDictN)	ServerAPI)SettingsSystem)ProductTelemetryClient)ClientStartEventc                   @   s   e Zd ZU i Zeeeef  ed< eed< e	 fde	ddfddZ
edede	defd	d
Zede	defddZededefddZededd fddZedddZedefddZdddZdS )SharedSystemClient_identifier_to_system_identifiersettingsreturnNc                 C   s   t || _t | j| d S N)r	   _get_identifier_from_settingsr   _create_system_if_not_exists)selfr    r   a/home/air/sanwanet/gpt-api/venv/lib/python3.10/site-packages/chromadb/api/shared_system_client.py__init__   s   zSharedSystemClient.__init__
identifierc                 C   sh   || j vrt|}|| j |< |t |t |  n| j | }|j|kr/td| d| j | S )Nz)An instance of Chroma already exists for z with different settings)r
   r   instancer   r   startr   
ValueError)clsr   r   
new_systemprevious_systemr   r   r   r      s   








z/SharedSystemClient._create_system_if_not_existsc                 C   s`   d}| j }|d u rtd|dv r| jr| j}|S d}|S |dv r)tt }|S td| )N z1Chroma API implementation must be set in settings)zchromadb.api.segment.SegmentAPIz!chromadb.api.rust.RustBindingsAPI	ephemeral)zchromadb.api.fastapi.FastAPIz'chromadb.api.async_fastapi.AsyncFastAPIz&Unsupported Chroma API implementation )chroma_api_implr   is_persistentpersist_directorystruuiduuid4)r   r   api_implr   r   r   r   ,   s   z0SharedSystemClient._get_identifier_from_settingssystemc                 C   s   t | j}| t j|< |S r   )r	   r   r   r
   )r%   r   r   r   r   _populate_data_from_systemH   s   
z-SharedSystemClient._populate_data_from_systemc                 C   s   t | | |j}|S )zRCreate a client from an existing system. This is useful for testing and debugging.)r	   r&   r   )r   r%   r   r   r   r   from_systemN   s   

zSharedSystemClient.from_systemc                   C   s
   i t _d S r   )r	   r
   r   r   r   r   clear_system_cacheV   s   
z%SharedSystemClient.clear_system_cachec                 C   s   t j| j S r   )r	   r
   r   )r   r   r   r   _systemZ   s   zSharedSystemClient._systemc                 C   s   | j t}|t  d S r   )r)   r   r   capturer   )r   telemetry_clientr   r   r   _submit_client_start_event^   s   z-SharedSystemClient._submit_client_start_event)r   N)__name__
__module____qualname__r
   r   r   r!   r   __annotations__r   r   classmethodr   staticmethodr   r&   r'   r(   propertyr)   r,   r   r   r   r   r	   
   s8   
 
r	   )typingr   r   r"   chromadb.apir   chromadb.configr   r   chromadb.telemetry.productr   !chromadb.telemetry.product.eventsr   r	   r   r   r   r   <module>   s    