o
    i                      @   s*  d Z ddlZddlZddlmZmZmZ ddlZddl	Zddl
Zddl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 ddlmZmZ d	d
lmZ d	dlmZmZmZmZ d	dl m!Z! d	dl"m#Z#m$Z$ d	dl%m&Z& ddddZ'de(de)e(e(f fddZ*G dd deZ+G dd deZ,dS )zACode generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.    N)AnyOptionalcast)models)BeforeRequestHookSDKHooks)Chat)Fim)UNSETOptionalNullable   )BaseSDK)AsyncHttpClientClientOwner
HttpClientclose_clients)SDKConfiguration)Loggerget_default_logger)RetryConfigzcodestral@2405zmistral-large@2407zmistral-nemo@2407)zcodestral-2405zmistral-large-2407zmistral-nemo-2407modelreturnc                 C   s0   | t v rd| dd d t |  fS | | fS )N-)LEGACY_MODEL_ID_FORMATjoinsplit)r    r   W/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/mistralai_gcp/sdk.pyget_model_info    s    r   c                   @   s   e Zd ZU dZeed< 	 eed< 	 dddddeddfdede	e de	e d	e	e
 d
e	e dee de	e de	e ddfddZdd Zdd Zdd Zdd Zdd ZdS )MistralGoogleCloudzMistral AI API: Our Chat Completion and Embeddings APIs specification. Create your account on [La Plateforme](https://console.mistral.ai) to get access and read the [docs](https://docs.mistral.ai) to learn how to use it.chatfimzeurope-west4Nregion
project_idaccess_tokenclientasync_clientretry_config
timeout_msdebug_loggerr   c	                    s   s't jjdgd\}	t jjj  tt jjj	s#t
d|p&|	}|du r0t
ddtf fddd	}
|du rFt }d
}
tt|tsQJ dd	}|du r]t }d
}|du rdt }tt|tsoJ dd}tr|fdd}nt
jd}t| t||
|||d| dd|||d
 t }t||}|| | j ^}}|||\}| j_ ||kr|| j_!|| jj"d< t#$| t%t&t'| j| jj | jj(| jj)| jj* | +  dS )a  Instantiates the SDK configuring it with the provided parameters.

        :param api_key: The api_key required for authentication
        :param server: The server by name to use for all methods
        :param server_url: The server URL to use for all methods
        :param url_params: Parameters to optionally template the server URL with
        :param client: The HTTP client to use for all synchronous methods
        :param async_client: The Async HTTP client to use for all asynchronous methods
        :param retry_config: The retry configuration to use for all supported methods
        :param timeout_ms: Optional request timeout applied to each operation in milliseconds
        z.https://www.googleapis.com/auth/cloud-platform)scopeszFcredentials must be an instance of google.auth.credentials.CredentialsNzproject_id must be providedr   c                     s4    r S  tjjj  j} | std| S )Nz$Failed to get token from credentials)	refreshgoogleauth	transportrequestsRequesttokenr   SDKError)r2   )r%   credentialsr   r   
auth_tokenV   s   
z/MistralGoogleCloud.__init__.<locals>.auth_tokenTFz;The provided client must implement the HttpClient protocol.zFThe provided async_client must implement the AsyncHttpClient protocol.c                      s   t j  dS )Napi_key)r   Securityr   )r5   r   r   <lambda>w   s    z-MistralGoogleCloud.__init__.<locals>.<lambda>r6   zhttps://z-aiplatform.googleapis.com)
r&   client_suppliedr'   async_client_suppliedsecurity
server_urlserverr(   r)   r*   _hooks),r-   r.   defaultr,   r/   r0   r1   
isinstancer4   Credentialsr   r3   strhttpxClient
issubclasstyper   AsyncClientr   r   callabler8   r   __init__r   r   GoogleCloudBeforeRequestHookregister_before_request_hooksdk_configurationget_server_detailssdk_initr&   r=   __dict__weakreffinalizer   r   r   r:   r'   r;   
_init_sdks)selfr#   r$   r%   r&   r'   r(   r)   r*   loaded_project_idr:   r;   r<   hookshookcurrent_server_url_r=   r   )r%   r5   r4   r   rJ   /   s   







zMistralGoogleCloud.__init__c                 C   s   t | j| _t| j| _d S N)r   rM   r!   r	   r"   rT   r   r   r   rS      s   zMistralGoogleCloud._init_sdksc                 C   s   | S rZ   r   r[   r   r   r   	__enter__   s   zMistralGoogleCloud.__enter__c                    s   | S rZ   r   r[   r   r   r   
__aenter__   s   zMistralGoogleCloud.__aenter__c                 C   s,   | j jd ur| j js| j j  d | j _d S rZ   )rM   r&   r:   closerT   exc_typeexc_valexc_tbr   r   r   __exit__   s
   zMistralGoogleCloud.__exit__c                    s4   | j jd ur| j js| j j I d H  d | j _d S rZ   )rM   r'   r;   acloser_   r   r   r   	__aexit__   s   zMistralGoogleCloud.__aexit__)__name__
__module____qualname____doc__r   __annotations__r	   r
   rC   r   r   r   r   r   intr   rJ   rS   r\   r]   rc   re   r   r   r   r   r    '   sL   
 	

wr    c                   @   s8   e Zd ZdedefddZdejdejeB fddZd	S )
rK   r#   r$   c                 C   s   || _ || _d S rZ   )r#   r$   )rT   r#   r$   r   r   r   rJ      s   
z%GoogleCloudBeforeRequestHook.__init__requestr   c                 C   s   d }d }|j r't|j d}|d}t|\}}||d< t|d}|dkr0t	dd|j
jv }|r:dnd}	d| j d| j d	| d
|	 }
t|j}|dd  tj|j|j
j|
d||d d}|S )Nzutf-8r    zmodel must be providedstreamRawPredict
rawPredictz/v1/projects/z/locations/z/publishers/mistralai/models/:zcontent-length)path)methodurlheaderscontentstream)ru   jsonloadsdecodegetr   dumpsencoder   r3   rs   rq   r$   r#   dictrt   poprD   r1   rr   	copy_with)rT   hook_ctxrl   model_idnew_contentparsed	model_raw
model_namerv   	specifierrs   rt   next_requestr   r   r   before_request   s.   

 
z+GoogleCloudBeforeRequestHook.before_requestN)	rf   rg   rh   rC   rJ   rD   r1   	Exceptionr   r   r   r   r   rK      s    rK   )-ri   rw   rQ   typingr   r   r   google.authr-   google.auth.credentialsgoogle.auth.transportgoogle.auth.transport.requestsrD   mistralai_gcpr   mistralai_gcp._hooksr   r   mistralai_gcp.chatr   mistralai_gcp.fimr	   mistralai_gcp.typesr
   r   basesdkr   
httpclientr   r   r   r   sdkconfigurationr   utils.loggerr   r   utils.retriesr   r   rC   tupler   r    rK   r   r   r   r   <module>   s6     