
    ge                     ~    d 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 ddlmZ ddlmZmZmZmZ  G d	 d
e      Zy)zACode generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.   )BaseSDK    )modelsutils)HookContext)NullableOptionalNullableUNSET)eventstreaming)AnyMappingOptionalUnionc            !          e Zd ZdZededdeeeedddddee   dedee   d	e	e   d
ee
   de	e   de	eej                  ej                  f      dee
   dee   dee
   deej"                     de	e   de	e
   de	eeef      de	ej(                  ej*                        fdZededdeeeedddddee   dedee   d	e	e   d
ee
   de	e   de	eej                  ej                  f      dee
   dee   dee
   deej"                     de	e   de	e
   de	eeef      de	ej.                  ej*                        fdZededdeeeedddddee   dedee   d	e	e   d
ee
   de	e   de	eej2                  ej4                  f      dee
   dee   dee
   deej"                     de	e   de	e
   de	eeef      de	ej6                     fdZededdeeeedddddee   dedee   d	e	e   d
ee
   de	e   de	eej2                  ej4                  f      dee
   dee   dee
   deej"                     de	e   de	e
   de	eeef      de	ej6                     fdZy)FimzFill-in-the-middle API.r   TN)temperaturetop_p
max_tokensstreamstoprandom_seedsuffix
min_tokensretries
server_url
timeout_mshttp_headersmodelpromptr   r   r   r   r   r   r   r   r   r   r   r   returnc                   d}d}|| j                   j                  }||}t        j                  |||||||||	|

      | j	                  dd||ddddd|| j                   j
                  fd	|
      }|t        k(  r2| j                   j                  t        ur| j                   j                  }d}t        |t        j                        r|g df}| j                  t        dg | j                   j
                        |g dd|      }d}t        j                  |dd      rt        j                  |d d      S t        j                  |dd      rOt        j                   |      }t        j"                  |t        j$                        }t        j&                  |      t        j                  |ddgd      r7t        j                   |      }t        j(                  d|j*                  ||      |j,                  j/                  d      }t        j                   |      }t        j(                  d|j*                   d| d|j*                  ||      )	  Stream fim completion

        Mistral AI provides the ability to stream responses back to a client in order to allow partial results for certain requests. Tokens will be sent as data-only server-sent events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.

        :param model: ID of the model to use. Only compatible for now with:   - `codestral-2405`   - `codestral-latest`
        :param prompt: The text/code to complete.
        :param temperature: What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.
        :param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
        :param max_tokens: The maximum number of tokens to generate in the completion. The token count of your prompt plus `max_tokens` cannot exceed the model's context length.
        :param stream:
        :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
        :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
        :param suffix: Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
        :param min_tokens: The minimum number of tokens to generate in the completion.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        N
r   r   r   r   r   r   r   r   r   r   POST/streamRawPredict#fimTF
user-agenttext/event-streamc                  R    t        j                   dddt        j                        S NFjsonr   serialize_request_bodyr   FIMCompletionStreamRequestrequests   F/var/www/openai/venv/lib/python3.12/site-packages/mistralai_gcp/fim.py<lambda>zFim.stream.<locals>.<lambda>Z   !    (D(Dvv/P/P)    methodpathbase_urlurl_variablesr/   request_body_requiredrequest_has_path_paramsrequest_has_query_paramsuser_agent_headeraccept_header_valuer   securityget_serialized_bodyr   429500502503504
stream_fimoperation_idoauth2_scopessecurity_source4224XX5XXhook_ctxr/   error_status_codesr   retry_config200c                 J    t        j                  | t        j                        S Nr   unmarshal_jsonr   CompletionEventraws    r0   r1   zFim.stream.<locals>.<lambda>x       E00f6L6LMr3   [DONE]sentinelrL   application/jsondatarM   rN   *API error occurredContent-Type$Unexpected response received (code: , type: ))sdk_configurationr   r   r-   _build_requestr>   r
   rR   
isinstancer   RetryConfig
do_requestr   match_responser   EventStreamstream_to_textrW   HTTPValidationErrorDataHTTPValidationErrorSDKErrorstatus_codeheadersgetselfr   r   r   r   r   r   r   r   r   r   r   r   r   r   r7   r8   reqrR   http_resra   http_res_textcontent_typer/   s                          @r0   r   z
Fim.stream   sl   T //::J!!H33#!#!
 !!('"&$)%)* 3%++44! "! " 
& e%%22%?00==gu001#%HIL?? )  $ 6 6 ? ?
 4% # 

 %1DE!--M! 
 %1CD!00:M''v7U7UVD,,$775%.#>!00:M//$h&:&:M8   ''++N;,,X6oo283G3G2HQ]P^^_`  	
 	
r3   c                
  K   d}d}|| j                   j                  }||}t        j                  |||||||||	|

      | j	                  dd||ddddd|| j                   j
                  fd	|
      }|t        k(  r2| j                   j                  t        ur| j                   j                  }d}t        |t        j                        r|g df}| j                  t        dg | j                   j
                        |g dd|       d{   }d}t        j                  |dd      rt        j                  |d d      S t        j                  |dd      rWt        j                   |       d{   }t        j"                  |t        j$                        }t        j&                  |      t        j                  |ddgd      r?t        j                   |       d{   }t        j(                  d|j*                  ||      |j,                  j/                  d      }t        j                   |       d{   }t        j(                  d|j*                   d| d|j*                  ||      7 h7 7 7 ?w)r"   Nr#   r$   r%   TFr&   r'   c                  R    t        j                   dddt        j                        S r)   r+   r.   s   r0   r1   z"Fim.stream_async.<locals>.<lambda>   r2   r3   r4   r@   rF   rG   rK   rO   rS   c                 J    t        j                  | t        j                        S rU   rV   rY   s    r0   r1   z"Fim.stream_async.<locals>.<lambda>   r[   r3   r\   r]   rL   r_   r`   rM   rN   rb   rc   rd   re   rf   rg   )rh   r   r   r-   _build_request_asyncr>   r
   rR   rj   r   rk   do_request_asyncr   rm   r   EventStreamAsyncstream_to_text_asyncrW   rp   rq   rr   rs   rt   ru   rv   s                          @r0   stream_asynczFim.stream_async   s    T //::J!!H33#!#!
 ''('"&$)%)* 3%++44! "! ( 
& e%%22%?00==gu001#%HIL.. )  $ 6 6 ? ?
 4% / 

 

 %1DE!22M! 
 %1CD"'"<"<X"FFM''v7U7UVD,,$775%.#>"'"<"<X"FFM//$h&:&:M8   ''++N;#88BBoo283G3G2HQ]P^^_`  	
 	
?

( G G CsK   DJI9A%J7I<8A/J'I?(AJJ8J<J?JJFc                   d}d}|| j                   j                  }||}t        j                  |||||||||	|

      | j	                  dd||ddddd|| j                   j
                  fd	|
      }|t        k(  r2| j                   j                  t        ur| j                   j                  }d}t        |t        j                        r|g df}| j                  t        dg | j                   j
                        |g d|      }d}t        j                  |dd      r5t        j                  |j                  t         t        j"                           S t        j                  |dd      rDt        j                  |j                  t        j$                        }t        j&                  |      t        j                  |ddgd      r7t        j(                  |      }t        j*                  d|j,                  ||      |j.                  j1                  d      }t        j(                  |      }t        j*                  d|j,                   d| d|j,                  ||      )H	  Fim Completion

        FIM completion.

        :param model: ID of the model to use. Only compatible for now with:   - `codestral-2405`   - `codestral-latest`
        :param prompt: The text/code to complete.
        :param temperature: What sampling temperature to use, we recommend between 0.0 and 0.7. Higher values like 0.7 will make the output more random, while lower values like 0.2 will make it more focused and deterministic. We generally recommend altering this or `top_p` but not both. The default value varies depending on the model you are targeting. Call the `/models` endpoint to retrieve the appropriate value.
        :param top_p: Nucleus sampling, where the model considers the results of the tokens with `top_p` probability mass. So 0.1 means only the tokens comprising the top 10% probability mass are considered. We generally recommend altering this or `temperature` but not both.
        :param max_tokens: The maximum number of tokens to generate in the completion. The token count of your prompt plus `max_tokens` cannot exceed the model's context length.
        :param stream: Whether to stream back partial progress. If set, tokens will be sent as data-only server-side events as they become available, with the stream terminated by a data: [DONE] message. Otherwise, the server will hold the request open until the timeout or until completion, with the response containing the full result as JSON.
        :param stop: Stop generation if this token is detected. Or if one of these tokens is detected when providing an array
        :param random_seed: The seed to use for random sampling. If set, different calls will generate deterministic results.
        :param suffix: Optional text/code that adds more context for the model. When given a `prompt` and a `suffix` the model will fill what is between them. When `suffix` is not provided, the model will simply execute completion starting with `prompt`.
        :param min_tokens: The minimum number of tokens to generate in the completion.
        :param retries: Override the default retry configuration for this method
        :param server_url: Override the default server URL for this method
        :param timeout_ms: Override the default request timeout configuration for this method in milliseconds
        :param http_headers: Additional headers to set or replace on requests.
        Nr#   r$   /rawPredict#fimTFr&   r_   c                  R    t        j                   dddt        j                        S r)   r   r,   r   FIMCompletionRequestr.   s   r0   r1   zFim.complete.<locals>.<lambda>Z  !    (D(Dvv/J/J)r3   r4   r@   &fim_completion_v1_fim_completions_postrG   rK   rP   r/   rQ   rR   rS   rL   r`   rM   rN   rb   rc   rd   re   rf   rg   )rh   r   r   r   ri   r>   r
   rR   rj   r   rk   rl   r   rm   rW   textr   FIMCompletionResponserp   rq   ro   rr   rs   rt   ru   rv   s                          @r0   completezFim.complete  sh   T //::J!!H--#!#!
 !!"'"&$)%)* 2%++44! "! " 
& e%%22%?00==gu001#%HIL?? E  $ 6 6 ? ?
 4% # 	
 %1CD''x(D(DE  %1CD''v7U7UVD,,$775%.#>!00:M//$h&:&:M8   ''++N;,,X6oo283G3G2HQ]P^^_`  	
 	
r3   c                  K   d}d}|| j                   j                  }||}t        j                  |||||||||	|

      | j	                  dd||ddddd|| j                   j
                  fd	|
      }|t        k(  r2| j                   j                  t        ur| j                   j                  }d}t        |t        j                        r|g df}| j                  t        dg | j                   j
                        |g d|       d{   }d}t        j                  |dd      r5t        j                  |j                  t         t        j"                           S t        j                  |dd      rDt        j                  |j                  t        j$                        }t        j&                  |      t        j                  |ddgd      r?t        j(                  |       d{   }t        j*                  d|j,                  ||      |j.                  j1                  d      }t        j(                  |       d{   }t        j*                  d|j,                   d| d|j,                  ||      7 q7 7 <w)r   Nr#   r$   r   TFr&   r_   c                  R    t        j                   dddt        j                        S r)   r   r.   s   r0   r1   z$Fim.complete_async.<locals>.<lambda>  r   r3   r4   r@   r   rG   rK   r   rS   rL   r`   rM   rN   rb   rc   rd   re   rf   rg   )rh   r   r   r   r   r>   r
   rR   rj   r   rk   r   r   rm   rW   r   r   r   rp   rq   r   rr   rs   rt   ru   rv   s                          @r0   complete_asynczFim.complete_async  s    T //::J!!H--#!#!
 ''"'"&$)%)* 2%++44! "! ( 
& e%%22%?00==gu001#%HIL.. E  $ 6 6 ? ?
 4% / 	
 	
 %1CD''x(D(DE  %1CD''v7U7UVD,,$775%.#>"'"<"<X"FFM//$h&:&:M8   ''++N;#88BBoo283G3G2HQ]P^^_`  	
 	
7	
( G Cs8   DJJCJ/J0AJ	J
8JJJ)__name__
__module____qualname____doc__r
   r   strr	   floatr   intboolr   r   FIMCompletionStreamRequestStop'FIMCompletionStreamRequestStopTypedDictr   rk   r   r   rn   rX   r   r   r   FIMCompletionRequestStop!FIMCompletionRequestStopTypedDictr   r   r    r3   r0   r   r      s@   " 05!",1!% -2(-,17<$($(48+~
 }~
 	~

 &e,~
 ~
 %S)~
 ~
 55>>@
~
 &c*~
  !%!~
" %S)#~
$ "%"3"34%~
& SM'~
( SM)~
* wsCx01+~
, 
.,,V-C-CD	E-~
J 05!",1!% -2(-,17<$($(48+~
 }~
 	~

 &e,~
 ~
 %S)~
 ~
 55>>@
~
 &c*~
  !%!~
" %S)#~
$ "%"3"34%~
& SM'~
( SM)~
* wsCx01+~
, 
.11&2H2HI	J-~
J 05!",1!& -2(-,17<$($(48+z
 }z
 	z

 &e,z
 z
 %S)z
 z
 //88:
z
 &c*z
  !%!z
" %S)#z
$ "%"3"34%z
& SM'z
( SM)z
* wsCx01+z
, 
&..	/-z
B 05!",1!& -2(-,17<$($(48+z
 }z
 	z

 &e,z
 z
 %S)z
 z
 //88:
z
 &c*z
  !%!z
" %S)#z
$ "%"3"34%z
& SM'z
( SM)z
* wsCx01+z
, 
&..	/-z
r3   r   N)r   basesdkr   mistralai_gcpr   r   mistralai_gcp._hooksr   mistralai_gcp.typesr   r	   r
   mistralai_gcp.utilsr   typingr   r   r   r   r   r   r3   r0   <module>r      s.    G  ' , A A . 0 0y
' y
r3   