
    gh                     "   d 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 d	d
lmZ d	dl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Z% G d de      Z& G d de      Z'y)zDCode generated by Speakeasy (https://speakeasyapi.dev). DO NOT EDIT.    N)OptionalTupleUnion)models)BeforeRequestHookSDKHooks)Chat)Fim)Nullable   )BaseSDK)AsyncHttpClient
HttpClient)SDKConfiguration)Logger
NoOpLogger)RetryConfigzcodestral@2405zmistral-large@2407zmistral-nemo@2407)zcodestral-2405zmistral-large-2407zmistral-nemo-2407modelreturnc                 r    | t         v r,dj                  | j                  d      d d       t         |    fS | | fS )N-)LEGACY_MODEL_ID_FORMATjoinsplit)r   s    F/var/www/openai/venv/lib/python3.12/site-packages/mistralai_gcp/sdk.pyget_model_infor      s?    &&xxC("-.0Fu0MMMe|    c                       e Zd ZU dZeed<   eed<   	 	 	 	 	 	 	 	 ddedee   dee   dee	   d	ee
   d
eee      dee   ddfdZd Zy)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fimNregion
project_idaccess_tokenclientasync_clientretry_configdebug_loggerr   c                    st         j                  j                  dg      \  }j                  t         j                  j                  j
                  j                                t        t         j                  j                  j                        st        j                  d      |xs |}|t        j                  d      dt        ffd|t        j                         }t        t!        |      t"              sJ d       |t        j$                         }|
t'               }t        t!        |      t(              sJ d	       d}	t+              rfd
}	nt        j,                        }	t/        j0                  | t3        |||	d| dd||             t5               }
t7        ||      }|
j9                  |       | j:                  j=                         ^}}|
j?                  || j:                  j@                        \  }| j:                  _         ||k7  r|| j:                  _!        |
| j:                  jD                  d<   | jG                          y)a  Instantiates the SDK configuring it with the provided parameters.

        :param region: The Google Cloud region to use for all methods
        :param project_id: The project ID to use for all methods
        :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
        z.https://www.googleapis.com/auth/cloud-platform)scopeszFcredentials must be an instance of google.auth.credentials.CredentialsNzproject_id must be providedr   c                      rS j                  t        j                  j                  j                  j                                j                  } | st        j                  d      | S )Nz$Failed to get token from credentials)	refreshgoogleauth	transportrequestsRequesttokenr   SDKError)r3   r%   credentialss    r   
auth_tokenz/MistralGoogleCloud.__init__.<locals>.auth_tokenO   sV    ## 5 5 > > F F HI%%Eoo&LMMLr   z;The provided client must implement the HttpClient protocol.zFThe provided async_client must implement the AsyncHttpClient protocol.c                  :    t        j                                 S )Napi_key)r   Security)r6   s   r   <lambda>z-MistralGoogleCloud.__init__.<locals>.<lambda>k   s    v" r   r8   zhttps://z-aiplatform.googleapis.com)r&   r'   security
server_urlserverr(   r)   _hooks)$r.   r/   defaultr-   r0   r1   r2   
isinstancer5   Credentialsr   r4   strhttpxClient
issubclasstyper   AsyncClientr   r   callabler:   r   __init__r   r   GoogleCloudBeforeRequestHookregister_before_request_hooksdk_configurationget_server_detailssdk_initr&   r=   __dict__
_init_sdks)selfr#   r$   r%   r&   r'   r(   r)   loaded_project_idr<   hookshookcurrent_server_url_r=   r6   r5   s      `           @@r   rJ   zMistralGoogleCloud.__init__-   s6   & -3[[-@-@HI .A .*K*  5 5 > > F F HIk6;;+B+B+N+NOoo\  $8'8J//"?@@	C 	 >\\^FL*
 	IH	I 
  ,,.L%<L
 	TS	T 
 JH z:H)!%fX-GH))	
 
+FJ?**40!%!7!7!J!J!LQ49NN 6 6 = =5
1
D**1 +0:D""- 5:''1r   c                 l    t        | j                        | _        t        | j                        | _        y N)r	   rM   r!   r
   r"   )rR   s    r   rQ   zMistralGoogleCloud._init_sdks   s&    //0	t--.r   )zeurope-west4NNNNNN)__name__
__module____qualname____doc__r	   __annotations__r
   rC   r   r   r   r   r   r   rJ   rQ    r   r   r    r    &   s     h
J	H %$(&*'+268<)-`` SM` sm	`
 $` /` x45` v&` 
`D/r   r    c                   ^    e Zd ZdedefdZdej                  deej                  ef   fdZ	y)rK   r#   r$   c                      || _         || _        y rY   )r#   r$   )rR   r#   r$   s      r   rJ   z%GoogleCloudBeforeRequestHook.__init__   s    $r   requestr   c                    d }d }|j                   rvt        j                  |j                   j                  d            }|j	                  d      }t        |      \  }}||d<   t        j                  |      j                  d      }|dk(  rt        j                  d      d|j                  j                  v }|rdnd}	d| j                   d| j                   d	| d
|	 }
t        |j                        }|j!                  dd        t#        j$                  |j&                  |j                  j)                  |
      ||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)rl   jsonloadsdecodegetr   dumpsencoder   r4   rj   rh   r$   r#   dictrk   poprD   r2   ri   	copy_with)rR   hook_ctxrb   model_idnew_contentparsed	model_raw
model_namerm   	specifierrj   rk   next_requests                r   before_requestz+GoogleCloudBeforeRequestHook.before_request   s-   
 ??ZZ 6 6w ?@F

7+I#1)#< J(F7O**V,33G<Kr>//":;; $w{{'7'77*0&l	doo.k$++Fcdlcmmnoxnyzw'$d+}}>>%%3%/
 r   N)
rZ   r[   r\   rC   rJ   rD   r2   r   	Exceptionr   r_   r   r   rK   rK      s<    %s % %"!&"	u}}i'	("r   rK   )(r]   rn   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   basesdkr   
httpclientr   r   sdkconfigurationr   utils.loggerr   r   utils.retriesr   r   rC   r   r    rK   r_   r   r   <module>r      s    J  ) )    %    < # ! (  3 . , & '., # %S/ k/ k/\(#4 (r   