o
    i6                     @   s   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 dd	lmZmZmZmZmZ G d
d deZdS )zACode generated by Speakeasy (https://speakeasy.com). DO NOT EDIT.   )BaseSDK    )modelsutils)HookContext)OptionalNullableUNSET)eventstreamingget_security_from_env)unmarshal_json_response)AnyListMappingOptionalUnionc                *   @   s  e Zd ZdZeddededdde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ejejf  dee deej deej dee
 dee deee
e
f  dejf(ddZeddededdde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ejejf  dee deej deej dee
 dee deee
e
f  dejf(ddZ eddededdde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ejejf  dee deej deej dee
 dee deee
e
f  de'j(ej) f(ddZ*eddededdde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ejejf  dee deej deej dee
 dee deee
e
f  de'j+ej) f(d d!Z,dS )"AgentszAgents API.FN)
max_tokensstreamstoprandom_seedresponse_formattoolstool_choicepresence_penaltyfrequency_penaltyn
predictionparallel_tool_callsprompt_moderetries
server_url
timeout_mshttp_headersmessagesagent_idr   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   returnc                   s  d}d}|du r| j j}|dur|}n| ||}tj||||t|ttj t|t	tj
 t|tttj  t|	t	tj |
||t|t	tj |||d | jdd|| ddddd|| j j fd	d
|d}|tkry| j jtury| j j}d}t|tjr|g df}| jt| j |pddg t| j jtjd|g d|d}d}t|ddrttj|S t|ddrttj|}t||t|ddrt|}td||t|ddrt|}td||td|)	  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 prediction:
        :param parallel_tool_calls:
        :param prompt_mode: Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used.
        :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/v1/agents/completionsTF
user-agentapplication/jsonc                         t  dddtjS NFjsonr   serialize_request_bodyr   AgentsCompletionRequest requestr2   V/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/mistralai/agents.py<lambda>       z!Agents.complete.<locals>.<lambda>methodpathbase_urlurl_variablesr4   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configr;   operation_idoauth2_scopessecurity_source4224XX5XXhook_ctxr4   error_status_codesretry_config200rR   rS   *API error occurredrT   Unexpected response received) sdk_configurationr!   _get_urlr   r1   r   get_pydantic_modelr   AgentsCompletionRequestMessagesr   ResponseFormatr   Tool!AgentsCompletionRequestToolChoice
Prediction_build_requestrB   r   rX   
isinstanceRetryConfig
do_requestr   r
   Securitymatch_responser   ChatCompletionResponseHTTPValidationErrorDataHTTPValidationErrorstream_to_textSDKErrorselfr#   r$   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r    r!   r"   r;   r<   reqrX   http_resresponse_datahttp_res_textr2   r3   r5   complete   s   @





	

zAgents.completec                   s  d}d}|du r| j j}|dur|}n| ||}tj||||t|ttj t|t	tj
 t|tttj  t|	t	tj |
||t|t	tj |||d | jdd|| ddddd|| j j fd	d
|d}|tkrz| j jturz| j j}d}t|tjr|g df}| jt| j |pddg t| j jtjd|g d|dI dH }d}t|ddrttj|S t|ddrttj|}t||t|ddrt|I dH }td||t|ddrt|I dH }td||td|)r&   Nr'   r(   r)   TFr*   r+   c                      r,   r-   r/   r2   r3   r2   r5   r6     r7   z'Agents.complete_async.<locals>.<lambda>r8   rD   rJ   rK   rL   rQ   rU   rY   rR   rS   rZ   r[   rT   r\   ) r]   r!   r^   r   r1   r   r_   r   r`   r   ra   r   rb   rc   rd   _build_request_asyncrB   r   rX   rf   rg   do_request_asyncr   r
   ri   rj   r   rk   rl   rm   stream_to_text_asyncro   rp   r2   r3   r5   complete_async   s   @





	zAgents.complete_asyncTc                   s  d}d}|du r| j j}|dur|}n| ||}tj||||t|ttj t|t	tj
 t|tttj  t|	t	tj |
||t|t	tj |||d | jdd|| ddddd|| j j fd	d
|d}|tkry| j jtury| j j}d}t|tjr|g df}| jt| j |pddg t| j jtjd|g dd|d}d}t|ddrtj|dd
 d| dS t|ddrt|}ttj||}t|||t|ddrt|}t d||t|ddrt|}t d||t|}t d||)m	  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 prediction:
        :param parallel_tool_calls:
        :param prompt_mode: Allows toggling between the reasoning mode and no system prompt. When set to `reasoning` the system prompt for reasoning models will be used.
        :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,   r-   r   r0   r   AgentsCompletionStreamRequestr2   r3   r2   r5   r6     r7   zAgents.stream.<locals>.<lambda>r8   rD   rJ   stream_agentsrL   rQ   rV   r4   rW   r   rX   rY   c                 S      t | tjS Nr   unmarshal_jsonr   CompletionEventrawr2   r2   r5   r6         [DONE]sentinel
client_refrR   r+   rS   rZ   r[   rT   r\   )!r]   r!   r^   r   r   r   r_   r   %AgentsCompletionStreamRequestMessagesr   ra   r   rb   'AgentsCompletionStreamRequestToolChoicerd   re   rB   r   rX   rf   rg   rh   r   r
   ri   rj   r	   EventStreamrn   r   rl   rm   ro   rp   r2   r3   r5   r   M  s   B





	



zAgents.streamc                   s(  d}d}|du r| j j}|dur|}n| ||}tj||||t|ttj t|t	tj
 t|tttj  t|	t	tj |
||t|t	tj |||d | jdd|| ddddd|| j j fd	d
|d}|tkrz| j jturz| j j}d}t|tjr|g df}| jt| j |pddg t| j jtjd|g dd|dI dH }d}t|ddrtj|dd
 d| dS t|ddrt|I dH }ttj||}t|||t|ddrt|I dH }t d||t|ddrt|I dH }t d||t|I dH }t d||)r{   Nr'   r(   r|   TFr*   r}   c                      r,   r-   r~   r2   r3   r2   r5   r6   i  r7   z%Agents.stream_async.<locals>.<lambda>r8   rD   rJ   r   rL   rQ   r   rY   c                 S   r   r   r   r   r2   r2   r5   r6     r   r   r   rR   r+   rS   rZ   r[   rT   r\   )!r]   r!   r^   r   r   r   r_   r   r   r   ra   r   rb   r   rd   rw   rB   r   rX   rf   rg   rx   r   r
   ri   rj   r	   EventStreamAsyncry   r   rl   rm   ro   rp   r2   r3   r5   stream_async  s   B





	zAgents.stream_async)-__name__
__module____qualname____doc__r   r   r   r   r`   (AgentsCompletionRequestMessagesTypedDictstrr   intr   boolAgentsCompletionRequestStop$AgentsCompletionRequestStopTypedDictra   ResponseFormatTypedDictrb   ToolTypedDictrc   *AgentsCompletionRequestToolChoiceTypedDictfloatrd   PredictionTypedDictMistralPromptModer   rg   r   rk   rv   rz   r   .AgentsCompletionStreamRequestMessagesTypedDict!AgentsCompletionStreamRequestStop*AgentsCompletionStreamRequestStopTypedDictr   0AgentsCompletionStreamRequestToolChoiceTypedDictr	   r   r   r   r   r   r2   r2   r2   r5   r      s   
	
 #$%&'()
 (	
 #$%&'()
 (	
 #$%&'(
)
 2	
 #$%&'(
)r   N)r   basesdkr   	mistralair   r   mistralai._hooksr   mistralai.typesr   r   mistralai.utilsr	   r
   'mistralai.utils.unmarshal_json_responser   typingr   r   r   r   r   r   r2   r2   r2   r5   <module>   s    