
    g                     ~    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
 ddlmZ ddlmZ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)OptionalNullableUNSET)eventstreaming)AnyListMappingOptionalUnionc            +       	   e Zd ZdZdededdededddededddddeeej                     eej                     f   de
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ej$                  ej&                  f      de
eeej(                     eej*                     f      deeej,                  ej.                  f      dee   dee   de
e   dee   de
ej2                     dee   dee   deeeef      deej8                  ej:                        f(dZdededdededddededddddeeej                     eej                     f   de
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ej$                  ej&                  f      de
eeej(                     eej*                     f      deeej,                  ej.                  f      dee   dee   de
e   dee   de
ej2                     dee   dee   deeeef      deej>                  ej:                        f(dZ dededdededddededddddeeejB                     eejD                     f   de
e   de
e   d	ee   d
e
e   dee   deeejF                  ejH                  f      de
e   deeej$                  ej&                  f      de
eeej(                     eej*                     f      deeejJ                  ejL                  f      dee   dee   de
e   dee   de
ej2                     dee   dee   deeeef      deejN                     f(dZ(dededdededddededddddeeejB                     eejD                     f   de
e   de
e   d	ee   d
e
e   dee   deeejF                  ejH                  f      de
e   deeej$                  ej&                  f      de
eeej(                     eej*                     f      deeejJ                  ejL                  f      dee   dee   de
e   dee   de
ej2                     dee   dee   deeeef      deejN                     f(dZ)y)ChatzChat Completion API.azureaiNT)modeltemperaturetop_p
max_tokensstreamstoprandom_seedresponse_formattoolstool_choicepresence_penaltyfrequency_penaltynsafe_promptretries
server_url
timeout_mshttp_headersmessagesr   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   returnc                   d}d}|| j                   j                  }||}t        j                  |||||||t	        j
                  |t        t        j                           t	        j
                  |	t        t        j                           t	        j
                  |
t        t        t        j                              t	        j
                  |t        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	        j0                  |      }t	        j2                  |t        j4                        }t        j6                  |      t	        j*                  |ddgd      r7t	        j0                  |      }t        j8                  d|j:                  ||      |j<                  j?                  d      }t	        j0                  |      }t        j8                  d|j:                   d| d|j:                  ||      )  Stream chat 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 messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
        :param model: The ID of the model to use for this request.
        :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 response_format:
        :param tools:
        :param tool_choice:
        :param presence_penalty: presence_penalty determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
        :param frequency_penalty: frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
        :param n: Number of completions to return for each request, input tokens are only billed once.
        :param safe_prompt: Whether to inject a safety prompt before all conversations.
        :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   r   r   r   r   r    POST/chat/completions#streamTF
user-agenttext/event-streamc                  R    t        j                   dddt        j                        S NFjsonr   serialize_request_bodyr   ChatCompletionStreamRequestrequests   I/var/www/openai/venv/lib/python3.12/site-packages/mistralai_azure/chat.py<lambda>zChat.stream.<locals>.<lambda>q   !    (D(Dvv/Q/Q)    methodpathbase_urlurl_variablesr5   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_chatoperation_idoauth2_scopessecurity_source4224XX5XXhook_ctxr5   error_status_codesr   retry_config200c                 J    t        j                  | t        j                        S Nr   unmarshal_jsonr   CompletionEventraws    r6   r7   zChat.stream.<locals>.<lambda>       E00f6L6LMr9   [DONE]sentinelrR   application/jsondatarS   rT   *API error occurredContent-Type$Unexpected response received (code: , type: )) sdk_configurationr#   r   r3   r   get_pydantic_modelr   Messagesr   ResponseFormatr   Tool%ChatCompletionStreamRequestToolChoice_build_requestrD   r	   rX   
isinstanceRetryConfig
do_requestr   match_responser
   EventStreamstream_to_textr]   HTTPValidationErrorDataHTTPValidationErrorSDKErrorstatus_codeheadersgetselfr%   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r#   r$   r=   r>   reqrX   http_resrg   http_res_textcontent_typer5   s                               @r6   r   zChat.stream   s   p //::J!!H44#!#--hV__8MN!44&*?*?!@ **52B4CT2UV00Xf&R&RS ./#'
, !!+'"&$)%)* 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^^_`  	
 	
r9   c                j  K   d}d}|| j                   j                  }||}t        j                  |||||||t	        j
                  |t        t        j                           t	        j
                  |	t        t        j                           t	        j
                  |
t        t        t        j                              t	        j
                  |t        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	        j0                  |       d{   }t	        j2                  |t        j4                        }t        j6                  |      t	        j*                  |ddgd      r?t	        j0                  |       d{   }t        j8                  d|j:                  ||      |j<                  j?                  d      }t	        j0                  |       d{   }t        j8                  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/   r1   r4   s   r6   r7   z#Chat.stream_async.<locals>.<lambda>  r8   r9   r:   rF   rL   rM   rQ   rU   rY   c                 J    t        j                  | t        j                        S r[   r\   r_   s    r6   r7   z#Chat.stream_async.<locals>.<lambda>&  ra   r9   rb   rc   rR   re   rf   rS   rT   rh   ri   rj   rk   rl   rm   ) rn   r#   r   r3   r   ro   r   rp   r   rq   r   rr   rs   _build_request_asyncrD   r	   rX   ru   rv   do_request_asyncr   rx   r
   EventStreamAsyncstream_to_text_asyncr]   r{   r|   r}   r~   r   r   r   s                               @r6   stream_asynczChat.stream_async   s    p //::J!!H44#!#--hV__8MN!44&*?*?!@ **52B4CT2UV00Xf&R&RS ./#'
, ''+'"&$)%)* 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   F>L3L)A%L3'L,(A/L3L/AL31L128L3,L3/L31L3Fc                .   d}d}|| j                   j                  }||}t        j                  |||||||t	        j
                  |t        t        j                           t	        j
                  |	t        t        j                           t	        j
                  |
t        t        t        j                              t	        j
                  |t        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        j0                           S t	        j*                  |dd      rDt	        j,                  |j.                  t        j2                        }t        j4                  |      t	        j*                  |ddgd      r7t	        j6                  |      }t        j8                  d|j:                  ||      |j<                  j?                  d      }t	        j6                  |      }t        j8                  d|j:                   d| d|j:                  ||      ).  Chat Completion

        :param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
        :param model: The ID of the model to use for this request.
        :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 response_format:
        :param tools:
        :param tool_choice:
        :param presence_penalty: presence_penalty determines how much the model penalizes the repetition of words or phrases. A higher presence penalty encourages the model to use a wider variety of words and phrases, making the output more diverse and creative.
        :param frequency_penalty: frequency_penalty penalizes the repetition of words based on their frequency in the generated text. A higher frequency penalty discourages the model from repeating words that have already appeared frequently in the output, promoting diversity and reducing repetition.
        :param n: Number of completions to return for each request, input tokens are only billed once.
        :param safe_prompt: Whether to inject a safety prompt before all conversations.
        :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*   /chat/completionsTFr,   re   c                  R    t        j                   dddt        j                        S r/   r   r2   r   ChatCompletionRequestr4   s   r6   r7   zChat.complete.<locals>.<lambda>  !    (D(Dvv/K/K)r9   r:   rF   (chat_completion_v1_chat_completions_postrM   rQ   rV   r5   rW   rX   rY   rR   rf   rS   rT   rh   ri   rj   rk   rl   rm   ) rn   r#   r   r   r   ro   r   ChatCompletionRequestMessagesr   rq   r   rr   ChatCompletionRequestToolChoicert   rD   r	   rX   ru   rv   rw   r   rx   r]   textChatCompletionResponser{   r|   rz   r}   r~   r   r   r   s                               @r6   completezChat.complete<  s   | //::J!!H..#!#--$vCCD "44&*?*?!@ **52B4CT2UV00Xf&L&LM ./#+
0 !!$'"&$)%)* 2%++44! "! " 
& e%%22%?00==gu001#%HIL?? G  $ 6 6 ? ?
 4% # 	
 %1CD''x(E(EF  %1CD''v7U7UVD,,$775%.#>!00:M//$h&:&:M8   ''++N;,,X6oo283G3G2HQ]P^^_`  	
 	
r9   c                t  K   d}d}|| j                   j                  }||}t        j                  |||||||t	        j
                  |t        t        j                           t	        j
                  |	t        t        j                           t	        j
                  |
t        t        t        j                              t	        j
                  |t        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        j0                           S t	        j*                  |dd      rDt	        j,                  |j.                  t        j2                        }t        j4                  |      t	        j*                  |ddgd      r?t	        j6                  |       d{   }t        j8                  d|j:                  ||      |j<                  j?                  d      }t	        j6                  |       d{   }t        j8                  d|j:                   d| d|j:                  ||      7 q7 7 <w)r   Nr)   r*   r   TFr,   re   c                  R    t        j                   dddt        j                        S r/   r   r4   s   r6   r7   z%Chat.complete_async.<locals>.<lambda>B  r   r9   r:   rF   r   rM   rQ   r   rY   rR   rf   rS   rT   rh   ri   rj   rk   rl   rm   ) rn   r#   r   r   r   ro   r   r   r   rq   r   rr   r   r   rD   r	   rX   ru   rv   r   r   rx   r]   r   r   r{   r|   r   r}   r~   r   r   r   s                               @r6   complete_asynczChat.complete_async  s    | //::J!!H..#!#--$vCCD "44&*?*?!@ **52B4CT2UV00Xf&L&LM ./#+
0 ''$'"&$)%)* 2%++44! "! ( 
& e%%22%?00==gu001#%HIL.. G  $ 6 6 ? ?
 4% / 	
 	
 %1CD''x(E(EF  %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   F=L8 L1CL8L4 AL89L6:8L84L86L8)*__name__
__module____qualname____doc__r	   r   r   r   rp   MessagesTypedDictr   strfloatr   intboolStopStopTypedDictrq   ResponseFormatTypedDictrr   ToolTypedDictrs   .ChatCompletionStreamRequestToolChoiceTypedDictr   rv   r   r
   ry   r^   r   r   r   r   &ChatCompletionRequestMessagesTypedDictChatCompletionRequestStop"ChatCompletionRequestStopTypedDictr   (ChatCompletionRequestToolChoiceTypedDictr   r   r    r9   r6   r   r      s    (1/4!%,1!%CG-2   ,0-1#(&*7<$($(48=U
 V__-tF4L4L/MMNU
  $	U

 &e,U
 U
 %S)U
 U
 uV[[&*>*>>?@U
 &c*U
 "&'')G)GGH
U
  $v{{#T&*>*>%??@
U
" <<EEG
#U
. #5//U
0 $E?1U
2 C 3U
4 d^5U
6 "%"3"347U
8 SM9U
: SM;U
< wsCx01=U
> 
.,,V-C-CD	E?U
v (1/4!%,1!%CG-2   ,0-1#(&*7<$($(48=U
 V__-tF4L4L/MMNU
  $	U

 &e,U
 U
 %S)U
 U
 uV[[&*>*>>?@U
 &c*U
 "&'')G)GGH
U
  $v{{#T&*>*>%??@
U
" <<EEG
#U
. #5//U
0 $E?1U
2 C 3U
4 d^5U
6 "%"3"347U
8 SM9U
: SM;U
< wsCx01=U
> 
.11&2H2HI	J?U
| (1/4!%,1!& -2   ,0-1#(&*7<$($(48MY
 556>>?A
Y
  $Y
 &e,Y
 Y
 %S)Y
 Y
 0099;
Y
$ &c*%Y
& "&'')G)GGH
'Y
,  $v{{#T&*>*>%??@
-Y
2 66??A
3Y
> #5/?Y
@ $E?AY
B C CY
D d^EY
F "%"3"34GY
H SMIY
J SMKY
L wsCx01MY
N 
&//	0OY
D (1/4!%,1!& -2   ,0-1#(&*7<$($(48MY
 556>>?A
Y
  $Y
 &e,Y
 Y
 %S)Y
 Y
 0099;
Y
$ &c*%Y
& "&'')G)GGH
'Y
,  $v{{#T&*>*>%??@
-Y
2 66??A
3Y
> #5/?Y
@ $E?AY
B C CY
D d^EY
F "%"3"34GY
H SMIY
J SMKY
L wsCx01MY
N 
&//	0OY
r9   r   N)r   basesdkr   mistralai_azurer   r   mistralai_azure._hooksr   mistralai_azure.typesr   r	   mistralai_azure.utilsr
   typingr   r   r   r   r   r   r   r9   r6   <module>r      s+    G  ) . 9 0 6 6e	
7 e	
r9   