
    g8s                         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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get_security_from_env)AnyListMappingOptionalUnionc            %       l   e Zd ZdZeddededddeedddddeeej                     eej                     f   d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j2                     dee
   dee   deee
e
f      deej6                     f"dZeddededddeedddddeeej                     eej                     f   d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j2                     dee
   dee   deee
e
f      deej6                     f"dZeddededddeedddddeeej<                     eej>                     f   de
dee   dee   d	eeej@                  ejB                  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jD                  ejF                  f      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$jJ                  ejL                        f"dZ'eddededddeedddddeeej<                     eej>                     f   de
dee   dee   d	eeej@                  ejB                  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jD                  ejF                  f      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$jP                  ejL                        f"dZ)y)AgentszAgents API.FN)
max_tokensstreamstoprandom_seedresponse_formattoolstool_choicepresence_penaltyfrequency_penaltynretries
server_url
timeout_mshttp_headersmessagesagent_idr   r   r   r   r   r   r   r   r   r   r   r   r   r    returnc                X   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 t+        | j                   j                  t        j,                              |g d|      }d}t	        j.                  |dd      r5t	        j0                  |j2                  t        t        j4                           S t	        j.                  |dd      rDt	        j0                  |j2                  t        j6                        }t        j8                  |      t	        j.                  |ddgd      r7t	        j:                  |      }t        j<                  d|j>                  ||      |j@                  jC                  d      }t	        j:                  |      }t        j<                  d|j>                   d| d|j>                  ||      )(  Agents Completion

        :param messages: The prompt(s) to generate completions for, encoded as a list of dict with role and content.
        :param agent_id: The ID of the agent to use for this completion.
        :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 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"   POST/v1/agents/completionsTF
user-agentapplication/jsonc                  R    t        j                   dddt        j                        S NFjsonr   serialize_request_bodyr   AgentsCompletionRequestrequests   E/var/www/openai/venv/lib/python3.12/site-packages/mistralai/agents.py<lambda>z!Agents.complete.<locals>.<lambda>p   !    (D(Dvv/M/M)    methodpathbase_urlurl_variablesr2   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,agents_completion_v1_agents_completions_postoperation_idoauth2_scopessecurity_source4224XX5XXhook_ctxr2   error_status_codesretry_config200rO   datarP   rQ   *API error occurredContent-Type$Unexpected response received (code: , type: ))"sdk_configurationr   r   r0   r   get_pydantic_modelr   AgentsCompletionRequestMessagesr   ResponseFormatr   Tool!AgentsCompletionRequestToolChoice_build_requestrA   r	   rU   
isinstanceRetryConfig
do_requestr   r   Securitymatch_responseunmarshal_jsontextChatCompletionResponseHTTPValidationErrorDataHTTPValidationErrorstream_to_textSDKErrorstatus_codeheadersgetselfr!   r"   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r:   r;   reqrU   http_resrX   http_res_textcontent_typer2   s                            @r3   completezAgents.complete   s   p //::J!!H00!#--$vEEF "44&*?*?!@ **52B4CT2UV00Xf&N&NO ./%
* !!)'"&$)%)* 2%++44! "! " 
& e%%22%?00==gu001#%HIL?? K  5**33V__! 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^^_`  	
 	
r6   c                  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 t+        | j                   j                  t        j,                              |g d|       d{   }d}t	        j.                  |dd      r5t	        j0                  |j2                  t        t        j4                           S t	        j.                  |dd      rDt	        j0                  |j2                  t        j6                        }t        j8                  |      t	        j.                  |ddgd      r?t	        j:                  |       d{   }t        j<                  d|j>                  ||      |j@                  jC                  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.   r1   s   r3   r4   z'Agents.complete_async.<locals>.<lambda>  r5   r6   r7   rC   rI   rJ   rN   rR   rV   rO   rW   rP   rQ   rY   rZ   r[   r\   r]   r^   )"r_   r   r   r0   r   r`   r   ra   r   rb   r   rc   rd   _build_request_asyncrA   r	   rU   rf   rg   do_request_asyncr   r   ri   rj   rk   rl   rm   rn   ro   stream_to_text_asyncrq   rr   rs   rt   ru   s                            @r3   complete_asynczAgents.complete_async   s    p //::J!!H00!#--$vEEF "44&*?*?!@ **52B4CT2UV00Xf&N&NO ./%
* '')'"&$)%)* 2%++44! "! ( 
& e%%22%?00==gu001#%HIL.. K  5**33V__! 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^^_`  	
 	
;
, G Cs8   GMMCM4M	5AMM8M	MMTc                8   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 t+        | j                   j                  t        j,                              |g dd|      }d}t	        j.                  |dd      rt1        j2                  |d d      S t	        j.                  |dd      rOt	        j4                  |      }t	        j6                  |t        j8                        }t        j:                  |      t	        j.                  |ddgd      r7t	        j4                  |      }t        j<                  d|j>                  ||      |j@                  jC                  d      }t	        j4                  |      }t        j<                  d|j>                   d| d|j>                  ||      )  Stream Agents 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 agent_id: The ID of the agent to use for this completion.
        :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 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'   /v1/agents/completions#streamTFr)   text/event-streamc                  R    t        j                   dddt        j                        S r,   r   r/   r   AgentsCompletionStreamRequestr1   s   r3   r4   zAgents.stream.<locals>.<lambda>  !    (D(Dvv/S/S)r6   r7   rC   stream_agentsrJ   rN   rS   r2   rT   r   rU   rV   c                 J    t        j                  | t        j                        S Nr   rk   r   CompletionEventraws    r3   r4   zAgents.stream.<locals>.<lambda>      E00f6L6LMr6   [DONE]sentinelrO   r*   rW   rP   rQ   rY   rZ   r[   r\   r]   r^   )"r_   r   r   r   r   r`   r   %AgentsCompletionStreamRequestMessagesr   rb   r   rc   'AgentsCompletionStreamRequestToolChoicere   rA   r	   rU   rf   rg   rh   r   r   ri   rj   r
   EventStreamrp   rk   rn   ro   rq   rr   rs   rt   ru   s                            @r3   r   zAgents.stream6  s   t //::J!!H66!#--$vKKL "44&*?*?!@ **52B4CT2UV00Xf&T&TU ./%
* !!0'"&$)%)* 3%++44! "! " 
& e%%22%?00==gu001#%HIL?? ,  5**33V__! 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^^_`  	
 	
r6   c                  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 t+        | j                   j                  t        j,                              |g dd|       d{   }d}t	        j.                  |dd      rt1        j2                  |d d      S t	        j.                  |dd      rWt	        j4                  |       d{   }t	        j6                  |t        j8                        }t        j:                  |      t	        j.                  |ddgd      r?t	        j4                  |       d{   }t        j<                  d|j>                  ||      |j@                  jC                  d      }t	        j4                  |       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   r1   s   r3   r4   z%Agents.stream_async.<locals>.<lambda>4  r   r6   r7   rC   r   rJ   rN   r   rV   c                 J    t        j                  | t        j                        S r   r   r   s    r3   r4   z%Agents.stream_async.<locals>.<lambda>T  r   r6   r   r   rO   r*   rW   rP   rQ   rY   rZ   r[   r\   r]   r^   )"r_   r   r   r   r   r`   r   r   r   rb   r   rc   r   r~   rA   r	   rU   rf   rg   r   r   r   ri   rj   r
   EventStreamAsyncr   rk   rn   ro   rq   rr   rs   rt   ru   s                            @r3   stream_asynczAgents.stream_async  s"    t //::J!!H66!#--$vKKL "44&*?*?!@ **52B4CT2UV00Xf&T&TU ./%
* ''0'"&$)%)* 3%++44! "! ( 
& e%%22%?00==gu001#%HIL.. ,  5**33V__! 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^^_`  	
 	
C
, G G CsK   GML>A%M<M=A/M,M-AMM8MMMM)*__name__
__module____qualname____doc__r	   r   r   r   ra   (AgentsCompletionRequestMessagesTypedDictstrr   intr   boolAgentsCompletionRequestStop$AgentsCompletionRequestStopTypedDictrb   ResponseFormatTypedDictrc   ToolTypedDictrd   *AgentsCompletionRequestToolChoiceTypedDictfloatr   rg   r   rm   r{   r   r   .AgentsCompletionStreamRequestMessagesTypedDict!AgentsCompletionStreamRequestStop*AgentsCompletionStreamRequestStopTypedDictr   0AgentsCompletionStreamRequestToolChoiceTypedDictr
   r   r   r   r   r    r6   r3   r   r      s    -2!& -2   ,0-1#(7<$($(48GR
 778@@AC
R
 R
 %S)R
 R
 22;;=
R
  &c*!R
" "&'')G)GGH
#R
(  $v{{#T&*>*>%??@
)R
. 88AAC
/R
: #5/;R
< $E?=R
> C ?R
@ "%"3"34AR
B SMCR
D SMER
F wsCx01GR
H 
&//	0IR
x -2!& -2   ,0-1#(7<$($(48GR
 778@@AC
R
 R
 %S)R
 R
 22;;=
R
  &c*!R
" "&'')G)GGH
#R
(  $v{{#T&*>*>%??@
)R
. 88AAC
/R
: #5/;R
< $E?=R
> C ?R
@ "%"3"34AR
B SMCR
D SMER
F wsCx01GR
H 
&//	0IR
x -2!% -2   ,0-1#(7<$($(48GX
 ==>FFGI
X
 X
 %S)X
 X
 88AAC
X
  &c*!X
" "&'')G)GGH
#X
(  $v{{#T&*>*>%??@
)X
. >>GGI
/X
: #5/;X
< $E?=X
> C ?X
@ "%"3"34AX
B SMCX
D SMEX
F wsCx01GX
H 
.,,V-C-CD	EIX
D -2!% -2   ,0-1#(7<$($(48GX
 ==>FFGI
X
 X
 %S)X
 X
 88AAC
X
  &c*!X
" "&'')G)GGH
#X
(  $v{{#T&*>*>%??@
)X
. >>GGI
/X
: #5/;X
< $E?=X
> C ?X
@ "%"3"34AX
B SMCX
D SMEX
F wsCx01GX
H 
.11&2H2HI	JIX
r6   r   N)r   basesdkr   	mistralair   r   mistralai._hooksr   mistralai.typesr   r	   mistralai.utilsr
   r   typingr   r   r   r   r   r   r   r6   r3   <module>r      s+    G  # ( 3 A 6 6]	
W ]	
r6   