o
    i^                    @   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 dd
lZddlmZ dd
lZddlmZ ddlmZmZmZ ddlmZm Z m!Z!m"Z" ddl#m$Z$ e%e&Z'ej(rxddl)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UnionN)AsyncGenerator)defaultdict)ResponseStartedEventConversationEventsDataInputEntries)	RunResultRunResultEventsFunctionResultEventreconstitue_entries)run_requirements)
RunContextc                "   @   s  e Zd ZdZeeeeeeedddf	dddeejej	f de
e 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j dee dee deeeef  defddZeeeeeeedddf	dddeejej	f de
e 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j dee dee deeeef  deeeef df fddZdeeeeeeeeeedddddeejej	f dee de
e de
ej de
e 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j dee dee deeeef  dejf ddZdeeeeeeeeeedddddeejej	f dee de
e de
ej de
e 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j dee dee deeeef  dejf ddZdd edddd!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  fd$d%Z!dd edddd!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  fd&d'Z"edddd(d)e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dd(d)ede
ej dee dee deeeef  dej#fd,d-Z%dd.d/dedddd0d)edeejej	f dee dee deej& deeejejf  de
ej dee dee deeeef  dejfd1d2Z'dd.d/dedddd0d)edeejej	f dee dee deej& deeejejf  de
ej dee dee deeeef  dejfd3d4Z(edddd(d)ede
ej dee dee deeeef  dej)fd5d6Z*edddd(d)ede
ej dee dee deeeef  dej)fd7d8Z+edddd(d)ede
ej dee dee deeeef  dej,fd9d:Z-edddd(d)ede
ej dee dee deeeef  dej,fd;d<Z.dd.d/dedddd0d)edeejej	f d=edee dee deej/ deeejejf  de
ej dee dee deeeef  dejfd>d?Z0dd.d/dedddd0d)edeejej	f d=edee dee deej/ deeejejf  de
ej dee dee deeeef  dejfd@dAZ1d.eeeeeeeeeedddddeejej	f dee de
e de
ej2 de
e de
eeej3 eej4 f  de
eejejf  d	e
e 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e5j6ej7 f dBdCZ8d.eeeeeeeeeedddddeejej	f dee de
e de
ej2 de
e de
eeej3 eej4 f  de
eejejf  d	e
e 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e5j9ej7 f dDdEZ:d.d.d/dedddd0d)edeejej	f dee dee deej; deeejejf  de
ej dee dee deeeef  de5j6ej7 fdFdGZ<d.d.d/dedddd0d)edeejej	f dee dee deej; deeejejf  de
ej dee dee deeeef  de5j9ej7 fdHdIZ=d.d.d/dedddd0d)edeejej	f d=edee dee deej> deeejejf  de
ej dee dee deeeef  de5j6ej7 fdJdKZ?d.d.d/dedddd0d)edeejej	f d=edee dee deej> deeejejf  de
ej dee dee deeeef  de5j9ej7 fdLdMZ@dS )NConversationsz(beta) Conversations APINrun_ctxr   inputsinstructionstoolscompletion_argsnamedescriptionretries
server_url
timeout_mshttp_headersreturnc              
      s&  ddl m} ddlm} ddlm} ||| j|||||dI dH \}}}	 |jdu rQ| jd||||||	|
d|I dH }|j|_|j|_t	
d	|j  n| j|j|||	|
d
I dH }| jd7  _|j|j ||j}|s|t	d 	 |S ||I dH }|j| ttt |}q')zRun a conversation with the given inputs and context.

        The execution of a run will only stop when no required local execution can be done.r   Beta_validate_runget_function_callsbeta_clientr   r   r   r    r!   NTr   r'   r"   r#   r$   r%   r&   &Started Run with conversation with id conversation_idr   r$   r%   r&   r   !No more function calls to execute )mistralai.betar*   mistralai.extra.run.contextr,   mistralai.extra.run.toolsr.   sdk_configurationr4   start_asyncloggerinfoappend_asyncrequest_countoutput_entriesextendoutputsdebugexecute_function_callstypingcastlistr   )selfr   r   r   r    r!   r"   r#   r$   r%   r&   r'   r*   r,   r.   req
run_resultinput_entriesresfcallsfresultsr6   r6   ]/var/www/html/karishye-ai-python/venv/lib/python3.10/site-packages/mistralai/conversations.py	run_async,   s`   	




zConversations.run_asyncc                    s   ddl m} ddlm} ddlm ||	j||||dI dH \dttt	t
f df f 	
fdd	}| S )
zSimilar to `run_async` but returns a generator which streams events.

        The last streamed object is the RunResult object which summarises what happened in the run.r   r)   r+   r-   r/   Nr(   c            	   
     sz  } 	 t t}jd u r!	jd|  
dI d H }n	jj| 
dI d H }|2 z>3 d H W }t|jtrUjd u rU|jj_|jj_t	dj  t
|jdd  }d urh|| |j tt|V  q16  jd7  _t|}j| |}|std n*|I d H }j| |D ]}tdtd|j|jd	d
V  qttt |} qV  d S )NTr1   r3   r2   output_indexr   r5   zfunction.result)typeresulttool_call_id)eventdatar6   )r   rG   r4   start_stream_asyncappend_stream_async
isinstancerV   r   r<   r=   getattrappendrE   rF   r   r?   r   r@   rA   rC   rD   r   rS   rT   r   )	current_entriesreceived_event_trackerrL   rU   rQ   rB   rM   rN   fresultr#   r.   r'   rK   r"   rI   r$   r   rJ   rH   r%   r&   r6   rO   run_generator   sx   








:z5Conversations.run_stream_async.<locals>.run_generator)r7   r*   r8   r,   r9   r.   r:   r   r   r   r   )rH   r   r   r   r    r!   r"   r#   r$   r%   r&   r'   r*   r,   r`   r6   r_   rO   run_stream_asynct   s    	$@zConversations.run_stream_asyncF)streamstorehandoff_executionr   r    r!   r"   r#   agent_idmodelr$   r%   r&   r'   rb   rc   rd   re   rf   c                   s  d}d}|du r| j j}|dur|}n| ||}tjt|tj||||t|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re| j jture| j j}d}t|tjrs|g df}| jt| j |p{d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|)  Create a conversation and append entries to it.

        Create a new conversation, using a base model or an agent and append entries. Completion and tool executions are run and the response is appended to the conversation.Use the returned conversation_id to continue the conversation.

        :param inputs:
        :param stream:
        :param store:
        :param handoff_execution:
        :param instructions:
        :param tools:
        :param completion_args:
        :param name:
        :param description:
        :param agent_id:
        :param model:
        :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   rb   rc   rd   r   r    r!   r"   r#   re   rf   POST/v1/conversationsTF
user-agentapplication/jsonc                         t  dddtjS NFjsonr   serialize_request_bodyr   ConversationRequestr6   requestr6   rO   <lambda>-      z%Conversations.start.<locals>.<lambda>methodpathbase_urlurl_variablesrt   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_api_v1_conversations_startconfigrz   operation_idoauth2_scopessecurity_source4224XX5XXhook_ctxrt   error_status_codesretry_config200r   r   *API error occurredr   Unexpected response received)r:   r&   _get_urlr   rr   r   get_pydantic_modelConversationInputsr   r   ToolsCompletionArgs_build_requestr   r   r   rY   RetryConfig
do_requestr   r
   Securitymatch_responser   ConversationResponseHTTPValidationErrorDataHTTPValidationErrorstream_to_textSDKErrorrH   r   rb   rc   rd   r   r    r!   r"   r#   re   rf   r$   r%   r&   r'   rz   r{   rI   r   http_resresponse_datahttp_res_textr6   rs   rO   start   s   +


	

zConversations.startc                   s  d}d}|du r| j j}|dur|}n| ||}tjt|tj||||t|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rf| j jturf| j j}d}t|tjrt|g df}| jt| j |p|d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|)rg   Nrh   ri   rj   TFrk   rl   c                      rm   rn   rp   r6   rs   r6   rO   ru     rv   z+Conversations.start_async.<locals>.<lambda>rw   r   r   r   r   r   r   r   r   r   r   r   r   r   )r:   r&   r   r   rr   r   r   r   r   r   r   r   _build_request_asyncr   r   r   rY   r   do_request_asyncr   r
   r   r   r   r   r   r   stream_to_text_asyncr   r   r6   rs   rO   r;   [  s   +


	zConversations.start_asyncr   d   )page	page_sizer$   r%   r&   r'   r   r   c                C   sv  d}d}|du r| j j}|dur|}n| ||}tj||d}	| jdd|||	ddddd|| j j|d	}
|tkrB| j jturB| j j}d}t	|t
jrP|g d
f}| jt| j |pXddg t| j jtjd|
g d|d}d}t
|ddr|tttj |S t
|ddrttj|}t||t
|ddrt
|}td||t
|ddrt
|}td||td|a  List all created conversations.

        Retrieve a list of conversation entities sorted by creation time.

        :param page:
        :param page_size:
        :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   GETrj   FTrk   rl   rx   ry   rz   r{   rt   r|   r}   r~   r   r   r'   r   r&   r   r    agents_api_v1_conversations_listr   r   r   r   r   r   r   r   r   r   )r:   r&   r   r   #AgentsAPIV1ConversationsListRequestr   r   r   r   rY   r   r   r   r   r
   r   r   r   r   ResponseBodyr   r   r   r   rH   r   r   r$   r%   r&   r'   rz   r{   rt   rI   r   r   r   r   r6   r6   rO   rG     sz   
	

zConversations.listc                   s  d}d}|du r| j j}|dur|}n| ||}tj||d}	| jdd|||	ddddd|| j j|d	}
|tkrC| j jturC| j j}d}t	|t
jrQ|g d
f}| jt| j |pYddg t| j jtjd|
g d|dI dH }d}t
|ddrtt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   )r:   r&   r   r   r   r   r   r   r   rY   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r   r6   r6   rO   
list_async7  s|   
	zConversations.list_async)r$   r%   r&   r'   r4   c                C   p  d}d}|du r| j j}|dur|}n| ||}tj|d}| jdd|||ddddd|| j j|d	}	|tkrA| j jturA| j j}d}
t	|t
jrO|g d
f}
| jt| j |pWddg t| j jtjd|	g d|
d}d}t
|ddryttj|S t
|ddrttj|}t||t
|ddrt
|}td||t
|ddrt
|}td||td|a8  Retrieve a conversation information.

        Given a conversation_id retrieve a conversation entity with its attributes.

        :param conversation_id: ID of the conversation from which we are fetching metadata.
        :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r4   r   #/v1/conversations/{conversation_id}FTrk   rl   r   r   r   agents_api_v1_conversations_getr   r   r   r   r   r   r   r   r   r   )r:   r&   r   r   "AgentsAPIV1ConversationsGetRequestr   r   r   r   rY   r   r   r   r   r
   r   r   r   5AgentsAPIV1ConversationsGetResponseV1ConversationsGetr   r   r   r   rH   r4   r$   r%   r&   r'   rz   r{   rt   rI   r   r   r   r   r6   r6   rO   get  s|   
	

zConversations.getc                     d}d}|du r| j j}|dur|}n| ||}tj|d}| jdd|||ddddd|| j j|d	}	|tkrB| j jturB| j j}d}
t	|t
jrP|g d
f}
| jt| j |pXddg t| j jtjd|	g d|
dI dH }d}t
|ddr}t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   )r:   r&   r   r   r   r   r   r   r   rY   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r6   r6   rO   	get_async  s~   
	zConversations.get_asyncTserver)rb   rc   rd   r!   r$   r%   r&   r'   c       
            s  d}d}|	du r| j j}	|dur|}n| ||}tj|tjt|tj|||t|t	tj
 dd | jdd|| ddddd|
| j j fd	d
|	d}|tkr[| j jtur[| j j}d}t|tjri|g df}| jt| j |pqd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|)A  Append new entries to an existing conversation.

        Run completion on the history of the conversation and the user entries. Return the new created entries.

        :param conversation_id: ID of the conversation to which we append entries.
        :param inputs:
        :param stream:
        :param store: Whether to store the results into our servers or not.
        :param handoff_execution:
        :param completion_args: White-listed arguments from the completion API
        :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   rb   rc   rd   r!   r4   conversation_append_requestri   r   Trk   rl   c                         t  jdddtjS rn   r   rq   r   r   ConversationAppendRequestr6   rs   r6   rO   ru         z&Conversations.append.<locals>.<lambda>rw   r   r   "agents_api_v1_conversations_appendr   r   r   r   r   r   r   r   r   r   )r:   r&   r   r   %AgentsAPIV1ConversationsAppendRequestr   r   r   r   r   r   r   r   r   r   rY   r   r   r   r
   r   r   r   r   r   r   r   r   rH   r4   r   rb   rc   rd   r!   r$   r%   r&   r'   rz   r{   rI   r   r   r   r   r6   rs   rO   r[   I  s   !


	

zConversations.appendc       
            s  d}d}|	du r| j j}	|dur|}n| ||}tj|tjt|tj|||t|t	tj
 dd | jdd|| ddddd|
| j j fd	d
|	d}|tkr\| j jtur\| j j}d}t|tjrj|g df}| jt| j |prd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   ri   r   Trk   rl   c                      r   rn   r   r6   rs   r6   rO   ru     r   z,Conversations.append_async.<locals>.<lambda>rw   r   r   r   r   r   r   r   r   r   r   r   r   r   )r:   r&   r   r   r   r   r   r   r   r   r   r   r   r   r   rY   r   r   r   r
   r   r   r   r   r   r   r   r   r   r6   rs   rO   r>     s   !


	zConversations.append_asyncc                C   r   a  Retrieve all entries in a conversation.

        Given a conversation_id retrieve all the entries belonging to that conversation. The entries are sorted in the order they were appended, those can be messages, connectors or function_call.

        :param conversation_id: ID of the conversation from which we are fetching entries.
        :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   z+/v1/conversations/{conversation_id}/historyFTrk   rl   r   r   r   #agents_api_v1_conversations_historyr   r   r   r   r   r   r   r   r   r   )r:   r&   r   r   &AgentsAPIV1ConversationsHistoryRequestr   r   r   r   rY   r   r   r   r   r
   r   r   r   ConversationHistoryr   r   r   r   r   r6   r6   rO   get_history7  x   
	

zConversations.get_historyc                   r   r   )r:   r&   r   r   r   r   r   r   r   rY   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r6   r6   rO   get_history_async  z   
	zConversations.get_history_asyncc                C   r   a  Retrieve all messages in a conversation.

        Given a conversation_id retrieve all the messages belonging to that conversation. This is similar to retrieving all entries except we filter the messages only.

        :param conversation_id: ID of the conversation from which we are fetching messages.
        :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   z,/v1/conversations/{conversation_id}/messagesFTrk   rl   r   r   r   $agents_api_v1_conversations_messagesr   r   r   r   r   r   r   r   r   r   )r:   r&   r   r   'AgentsAPIV1ConversationsMessagesRequestr   r   r   r   rY   r   r   r   r   r
   r   r   r   ConversationMessagesr   r   r   r   r   r6   r6   rO   get_messages  r   zConversations.get_messagesc                   r   r   )r:   r&   r   r   r   r   r   r   r   rY   r   r   r   r   r
   r   r   r   r   r   r   r   r   r   r6   r6   rO   get_messages_asyncB  r   z Conversations.get_messages_asyncfrom_entry_idc                   s  d}d}|
du r| j j}
|	dur|	}n| ||}tj|tjt|tj|||t|t	tj
 |dd | jdd|| ddddd|| j j fd	d
|
d}|tkr\| j jtur\| j j}d}t|tjrj|g df}| jt| j |prd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|)  Restart a conversation starting from a given entry.

        Given a conversation_id and an id, recreate a conversation from this point and run completion. A new conversation is returned with the new entries returned.

        :param conversation_id: ID of the original conversation which is being restarted.
        :param inputs:
        :param from_entry_id:
        :param stream:
        :param store: Whether to store the results into our servers or not.
        :param handoff_execution:
        :param completion_args: White-listed arguments from the completion API
        :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   rb   rc   rd   r!   r   r4   conversation_restart_requestri   +/v1/conversations/{conversation_id}/restartTrk   rl   c                      r   rn   r   rq   r   r   ConversationRestartRequestr6   rs   r6   rO   ru     r   z'Conversations.restart.<locals>.<lambda>rw   r   r   #agents_api_v1_conversations_restartr   r   r   r   r   r   r   r   r   r   )r:   r&   r   r   &AgentsAPIV1ConversationsRestartRequestr   r   r   r   r   r   r   r   r   r   rY   r   r   r   r
   r   r   r   r   r   r   r   r   rH   r4   r   r   rb   rc   rd   r!   r$   r%   r&   r'   rz   r{   rI   r   r   r   r   r6   rs   rO   restart  s   #


	

zConversations.restartc                   s  d}d}|
du r| j j}
|	dur|	}n| ||}tj|tjt|tj|||t|t	tj
 |dd | jdd|| ddddd|| j j fd	d
|
d}|tkr]| j jtur]| j j}d}t|tjrk|g df}| jt| j |psd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   ri   r   Trk   rl   c                      r   rn   r   r6   rs   r6   rO   ru   ]  r   z-Conversations.restart_async.<locals>.<lambda>rw   r   r   r   r   r   r   r   r   r   r   r   r   r   )r:   r&   r   r   r   r   r   r   r   r   r   r   r   r   r   rY   r   r   r   r
   r   r   r   r   r   r   r   r   r   r6   rs   rO   restart_async  s   #


	zConversations.restart_asyncc                   s  d}d}|du r| j j}|dur|}n| ||}tjt|tj||||t|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re| j jture| j j}d}t|tjrs|g df}| jt| j |p{ddg t| j jtjd|g dd|d}d}t|ddrtj|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||)rg   Nrh   ri   /v1/conversations#streamTFrk   text/event-streamc                      rm   rn   r   rq   r   ConversationStreamRequestr6   rs   r6   rO   ru     rv   z,Conversations.start_stream.<locals>.<lambda>rw   r   r   (agents_api_v1_conversations_start_streamr   r   r   rt   r   rb   r   r   c                 S      t | tjS Nr   unmarshal_jsonr   ConversationEventsrawr6   r6   rO   ru   
      
client_refr   rl   r   r   r   r   r   )r:   r&   r   r   r   r   r   r   r   r   ConversationStreamRequestToolsr   r   r   r   r   rY   r   r   r   r
   r   r   r	   EventStreamr   r   r   r   r   r   r6   rs   rO   start_stream  s   0


	



zConversations.start_streamc                   s  d}d}|du r| j j}|dur|}n| ||}tjt|tj||||t|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rf| j jturf| j j}d}t|tjrt|g df}| jt| j |p|ddg t| j jtjd|g dd|dI dH }d}t|ddrtj|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rt|I dH }td||t|I dH }td||)rg   Nrh   ri   r   TFrk   r   c                      rm   rn   r   r6   rs   r6   rO   ru   v  rv   z2Conversations.start_stream_async.<locals>.<lambda>rw   r   r   r   r   r   r   r   c                 S   r   r   r   r   r6   r6   rO   ru     r   r   r   rl   r   r   r   r   r   )r:   r&   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rY   r   r   r   r
   r   r   r	   EventStreamAsyncr   r   r   r   r   r   r6   rs   rO   rW     s   0


	z Conversations.start_stream_asyncc       
            s  d}d}|	du r| j j}	|dur|}n| ||}tj|tjt|tj|||t|t	tj
 dd | jdd|| ddddd|
| j j fd	d
|	d}|tkr[| j jtur[| j j}d}t|tjri|g df}| jt| j |pqddg t| j jtjd|g dd|d}d}t|ddrtj|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||)r   Nr   r4   "conversation_append_stream_requestri   */v1/conversations/{conversation_id}#streamTrk   r   c                      r   rn   r   rq   r  r   ConversationAppendStreamRequestr6   rs   r6   rO   ru     r   z-Conversations.append_stream.<locals>.<lambda>rw   r   r   )agents_api_v1_conversations_append_streamr   r   r   r   c                 S   r   r   r   r   r6   r6   rO   ru     r   r   r   rl   r   r   r   r   r   )r:   r&   r   r   +AgentsAPIV1ConversationsAppendStreamRequestr  r   r   r   r   r   r   r   r   r   rY   r   r   r   r
   r   r   r	   r  r   r   r   r   r   r   r6   rs   rO   append_stream  s   !


	



zConversations.append_streamc       
            s  d}d}|	du r| j j}	|dur|}n| ||}tj|tjt|tj|||t|t	tj
 dd | jdd|| ddddd|
| j j fd	d
|	d}|tkr\| j jtur\| j j}d}t|tjrj|g df}| jt| j |prddg t| j jtjd|g dd|dI dH }d}t|ddrtj|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rt|I dH }td||t|I dH }td||)r   Nr   r  ri   r  Trk   r   c                      r   rn   r  r6   rs   r6   rO   ru   n  r   z3Conversations.append_stream_async.<locals>.<lambda>rw   r   r   r	  r   r   r   r   c                 S   r   r   r   r   r6   r6   rO   ru     r   r   r   rl   r   r   r   r   r   )r:   r&   r   r   r
  r  r   r   r   r   r   r   r   r   r   rY   r   r   r   r
   r   r   r	   r  r   r   r   r   r   r   r6   rs   rO   rX   )  s   !


	z!Conversations.append_stream_asyncc                   s  d}d}|
du r| j j}
|	dur|	}n| ||}tj|tjt|tj|||t|t	tj
 |dd | jdd|| ddddd|| j j fd	d
|
d}|tkr\| j jtur\| j j}d}t|tjrj|g df}| jt| j |prddg t| j jtjd|g dd|d}d}t|ddrtj|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||)r   Nr   r4   #conversation_restart_stream_requestri   2/v1/conversations/{conversation_id}/restart#streamTrk   r   c                      r   rn   r   rq   r  r    ConversationRestartStreamRequestr6   rs   r6   rO   ru     r   z.Conversations.restart_stream.<locals>.<lambda>rw   r   r   *agents_api_v1_conversations_restart_streamr   r   r   r   c                 S   r   r   r   r   r6   r6   rO   ru   	  r   r   r   rl   r   r   r   r   r   )r:   r&   r   r   ,AgentsAPIV1ConversationsRestartStreamRequestr  r   r   r   r   r   r   r   r   r   rY   r   r   r   r
   r   r   r	   r  r   r   r   r   r   r   r6   rs   rO   restart_stream  s   #


	



zConversations.restart_streamc                   s  d}d}|
du r| j j}
|	dur|	}n| ||}tj|tjt|tj|||t|t	tj
 |dd | jdd|| ddddd|| j j fd	d
|
d}|tkr]| j jtur]| j j}d}t|tjrk|g df}| jt| j |psddg t| j jtjd|g dd|dI dH }d}t|ddrtj|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rt|I dH }td||t|I dH }td||)r   Nr   r  ri   r  Trk   r   c                      r   rn   r  r6   rs   r6   rO   ru   p	  r   z4Conversations.restart_stream_async.<locals>.<lambda>rw   r   r   r  r   r   r   r   c                 S   r   r   r   r   r6   r6   rO   ru   	  r   r   r   rl   r   r   r   r   r   )r:   r&   r   r   r  r  r   r   r   r   r   r   r   r   r   rY   r   r   r   r
   r   r   r	   r  r   r   r   r   r   r   r6   rs   rO   restart_stream_async(	  s   #


	z"Conversations.restart_stream_async)A__name__
__module____qualname____doc__r   r   r   r   r   ConversationInputsTypedDictr   strr   r   ToolsTypedDictr   CompletionArgsTypedDictr   r   r   intr   r   rP   r   r   ra   boolHandoffExecutionr   r   r;   r   rG   r   r   r   r   )ConversationAppendRequestHandoffExecutionr[   r>   r   r   r   r   r   r   *ConversationRestartRequestHandoffExecutionr   r   )ConversationStreamRequestHandoffExecutionr   'ConversationStreamRequestToolsTypedDictr	   r  r   r  r  rW   /ConversationAppendStreamRequestHandoffExecutionr  rX   0ConversationRestartStreamRequestHandoffExecutionr  r  r6   r6   r6   rO   r   &   s   Gj
 
 	
_	
`
_
`

|

{
]
]
]
_
 
~	


 	


 


 


 

 
r   ),r  basesdkr   	mistralair   r   mistralai._hooksr   mistralai.typesr   r   mistralai.utilsr	   r
   'mistralai.utils.unmarshal_json_responser   rE   r   r   r   r   r   r   loggingcollectionsr   mistralai.modelsr   r   r   mistralai.extra.run.resultr   r   r   r   mistralai.extra.run.utilsr   	getLoggerr  r<   TYPE_CHECKINGr8   r   r   r6   r6   r6   rO   <module>   s&    
