
    g-                       d dl mZ d dlZd dlmZmZmZmZ d dlm	Z	 d dlm
Z
mZ d dlZddlmZ dd	lmZmZmZmZmZmZ dd
lmZmZmZmZmZ ddlmZmZ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+ ddl,m-Z-m.Z. ddl/m0Z0m1Z1 ddl2m3Z3m4Z4m5Z5m6Z6m7Z7m8Z8 ddl9m:Z: ddl;m<Z<m=Z=m>Z>m?Z? ddl@mAZA ddlBmCZC ddlDmEZE ddlFmGZG ddlHmIZI ddlJmKZK ddgZL G d de$      ZM G d de%      ZN G d d       ZO G d! d"      ZP G d# d$      ZQ G d% d&      ZRy)'    )annotationsN)ListUnionIterableOptional)partial)Literaloverload   )_legacy_response   )Steps
AsyncStepsStepsWithRawResponseAsyncStepsWithRawResponseStepsWithStreamingResponseAsyncStepsWithStreamingResponse)	NOT_GIVENBodyQueryHeadersNotGiven)is_givenrequired_argsmaybe_transformasync_maybe_transform)cached_property)SyncAPIResourceAsyncAPIResource)to_streamed_response_wrapper"async_to_streamed_response_wrapper)StreamAsyncStream)SyncCursorPageAsyncCursorPage)AsyncPaginatormake_request_options)AssistantEventHandlerAssistantEventHandlerTAssistantStreamManagerAsyncAssistantEventHandlerAsyncAssistantEventHandlerTAsyncAssistantStreamManager)	ChatModel)run_list_paramsrun_create_paramsrun_update_paramsrun_submit_tool_outputs_params)Run)AssistantToolParam)AssistantStreamEvent)RunStepInclude)AssistantToolChoiceOptionParam)"AssistantResponseFormatOptionParamRuns	AsyncRunsc                  "
   e Zd Zed/d       Zed0d       Zed1d       Zeeeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d2d	       Z	eeeeeeeeeeeeeeeeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3d       Z	eeeeeeeeeeeeeeeeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4d       Z	 e
dgddg      eeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5d       Z	ddded	 	 	 	 	 	 	 	 	 	 	 	 	 d6dZeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d7dZeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d8dZddded	 	 	 	 	 	 	 	 	 	 	 	 	 d6dZeeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d9dZe ej"                  d      eeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d:d              Ze ej"                  d      eeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d;d              Z ej"                  d      eeeeeeeeeeeeeedddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d<d       Zdddeef	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d=dZeeeeeeeeeeeeeeeeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d>d       Zeeeeeeeeeeeeeeeeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d?d       Zeeeeeeeeeeeeeeedddded 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d@d!Zeeddded"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dAd$       Zeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dBd%       Zeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dCd&       Z e
dd#gg d'      eddded"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dDd(       Zeddded)	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dEd*Zeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dFd+       Zeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dGd,       Zdddded-	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dHd.Zy)Ir9   c                ,    t        | j                        S N)r   _clientselfs    \/var/www/openai/venv/lib/python3.12/site-packages/openai/resources/beta/threads/runs/runs.pystepsz
Runs.steps<   s    T\\""    c                    t        |       S a  
        This property can be used as a prefix for any HTTP method call to return the
        the raw response object instead of the parsed content.

        For more information, see https://www.github.com/openai/openai-python#accessing-raw-response-data-eg-headers
        )RunsWithRawResponser?   s    rA   with_raw_responsezRuns.with_raw_response@   s     #4((rC   c                    t        |       S z
        An alternative to `.with_raw_response` that doesn't eagerly read the response body.

        For more information, see https://www.github.com/openai/openai-python#with_streaming_response
        )RunsWithStreamingResponser?   s    rA   with_streaming_responsezRuns.with_streaming_responseJ   s     )..rC   Nincludeadditional_instructionsadditional_messagesinstructionsmax_completion_tokensmax_prompt_tokensmetadatamodelparallel_tool_callsresponse_formatstreamtemperaturetool_choicetoolstop_ptruncation_strategyextra_headersextra_query
extra_bodytimeout	thread_idassistant_idrW   c                    ya  
        Create a run.

        Args:
          assistant_id: The ID of the
              [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
              execute this run.

          include: A list of additional fields to include in the response. Currently the only
              supported value is `step_details.tool_calls[*].file_search.results[*].content`
              to fetch the file search result content.

              See the
              [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
              for more information.

          additional_instructions: Appends additional instructions at the end of the instructions for the run. This
              is useful for modifying the behavior on a per-run basis without overriding other
              instructions.

          additional_messages: Adds additional messages to the thread before creating the run.

          instructions: Overrides the
              [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
              of the assistant. This is useful for modifying the behavior on a per-run basis.

          max_completion_tokens: The maximum number of completion tokens that may be used over the course of the
              run. The run will make a best effort to use only the number of completion tokens
              specified, across multiple turns of the run. If the run exceeds the number of
              completion tokens specified, the run will end with status `incomplete`. See
              `incomplete_details` for more info.

          max_prompt_tokens: The maximum number of prompt tokens that may be used over the course of the run.
              The run will make a best effort to use only the number of prompt tokens
              specified, across multiple turns of the run. If the run exceeds the number of
              prompt tokens specified, the run will end with status `incomplete`. See
              `incomplete_details` for more info.

          metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
              for storing additional information about the object in a structured format. Keys
              can be a maximum of 64 characters long and values can be a maximum of 512
              characters long.

          model: The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
              be used to execute this run. If a value is provided here, it will override the
              model associated with the assistant. If not, the model associated with the
              assistant will be used.

          parallel_tool_calls: Whether to enable
              [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
              during tool use.

          response_format: Specifies the format that the model must output. Compatible with
              [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
              [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
              and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

              Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
              Outputs which ensures the model will match your supplied JSON schema. Learn more
              in the
              [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

              Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
              message the model generates is valid JSON.

              **Important:** when using JSON mode, you **must** also instruct the model to
              produce JSON yourself via a system or user message. Without this, the model may
              generate an unending stream of whitespace until the generation reaches the token
              limit, resulting in a long-running and seemingly "stuck" request. Also note that
              the message content may be partially cut off if `finish_reason="length"`, which
              indicates the generation exceeded `max_tokens` or the conversation exceeded the
              max context length.

          stream: If `true`, returns a stream of events that happen during the Run as server-sent
              events, terminating when the Run enters a terminal state with a `data: [DONE]`
              message.

          temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
              make the output more random, while lower values like 0.2 will make it more
              focused and deterministic.

          tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
              not call any tools and instead generates a message. `auto` is the default value
              and means the model can pick between generating a message or calling one or more
              tools. `required` means the model must call one or more tools before responding
              to the user. Specifying a particular tool like `{"type": "file_search"}` or
              `{"type": "function", "function": {"name": "my_function"}}` forces the model to
              call that tool.

          tools: Override the tools the assistant can use for this run. This is useful for
              modifying the behavior on a per-run basis.

          top_p: An alternative to sampling with temperature, called 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.

          truncation_strategy: Controls for how a thread will be truncated prior to the run. Use this to
              control the intial context window of the run.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        N r@   ra   rb   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   r]   r^   r_   r`   s                          rA   createzRuns.createS       T 	rC   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   r]   r^   r_   r`   c                    ya  
        Create a run.

        Args:
          assistant_id: The ID of the
              [assistant](https://platform.openai.com/docs/api-reference/assistants) to use to
              execute this run.

          stream: If `true`, returns a stream of events that happen during the Run as server-sent
              events, terminating when the Run enters a terminal state with a `data: [DONE]`
              message.

          include: A list of additional fields to include in the response. Currently the only
              supported value is `step_details.tool_calls[*].file_search.results[*].content`
              to fetch the file search result content.

              See the
              [file search tool documentation](https://platform.openai.com/docs/assistants/tools/file-search#customizing-file-search-settings)
              for more information.

          additional_instructions: Appends additional instructions at the end of the instructions for the run. This
              is useful for modifying the behavior on a per-run basis without overriding other
              instructions.

          additional_messages: Adds additional messages to the thread before creating the run.

          instructions: Overrides the
              [instructions](https://platform.openai.com/docs/api-reference/assistants/createAssistant)
              of the assistant. This is useful for modifying the behavior on a per-run basis.

          max_completion_tokens: The maximum number of completion tokens that may be used over the course of the
              run. The run will make a best effort to use only the number of completion tokens
              specified, across multiple turns of the run. If the run exceeds the number of
              completion tokens specified, the run will end with status `incomplete`. See
              `incomplete_details` for more info.

          max_prompt_tokens: The maximum number of prompt tokens that may be used over the course of the run.
              The run will make a best effort to use only the number of prompt tokens
              specified, across multiple turns of the run. If the run exceeds the number of
              prompt tokens specified, the run will end with status `incomplete`. See
              `incomplete_details` for more info.

          metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
              for storing additional information about the object in a structured format. Keys
              can be a maximum of 64 characters long and values can be a maximum of 512
              characters long.

          model: The ID of the [Model](https://platform.openai.com/docs/api-reference/models) to
              be used to execute this run. If a value is provided here, it will override the
              model associated with the assistant. If not, the model associated with the
              assistant will be used.

          parallel_tool_calls: Whether to enable
              [parallel function calling](https://platform.openai.com/docs/guides/function-calling#configuring-parallel-function-calling)
              during tool use.

          response_format: Specifies the format that the model must output. Compatible with
              [GPT-4o](https://platform.openai.com/docs/models#gpt-4o),
              [GPT-4 Turbo](https://platform.openai.com/docs/models#gpt-4-turbo-and-gpt-4),
              and all GPT-3.5 Turbo models since `gpt-3.5-turbo-1106`.

              Setting to `{ "type": "json_schema", "json_schema": {...} }` enables Structured
              Outputs which ensures the model will match your supplied JSON schema. Learn more
              in the
              [Structured Outputs guide](https://platform.openai.com/docs/guides/structured-outputs).

              Setting to `{ "type": "json_object" }` enables JSON mode, which ensures the
              message the model generates is valid JSON.

              **Important:** when using JSON mode, you **must** also instruct the model to
              produce JSON yourself via a system or user message. Without this, the model may
              generate an unending stream of whitespace until the generation reaches the token
              limit, resulting in a long-running and seemingly "stuck" request. Also note that
              the message content may be partially cut off if `finish_reason="length"`, which
              indicates the generation exceeded `max_tokens` or the conversation exceeded the
              max context length.

          temperature: What sampling temperature to use, between 0 and 2. Higher values like 0.8 will
              make the output more random, while lower values like 0.2 will make it more
              focused and deterministic.

          tool_choice: Controls which (if any) tool is called by the model. `none` means the model will
              not call any tools and instead generates a message. `auto` is the default value
              and means the model can pick between generating a message or calling one or more
              tools. `required` means the model must call one or more tools before responding
              to the user. Specifying a particular tool like `{"type": "file_search"}` or
              `{"type": "function", "function": {"name": "my_function"}}` forces the model to
              call that tool.

          tools: Override the tools the assistant can use for this run. This is useful for
              modifying the behavior on a per-run basis.

          top_p: An alternative to sampling with temperature, called 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.

          truncation_strategy: Controls for how a thread will be truncated prior to the run. Use this to
              control the intial context window of the run.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        Nre   r@   ra   rb   rW   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   r]   r^   r_   r`   s                          rA   rg   zRuns.create   rh   rC   c                    yrk   re   rl   s                          rA   rg   zRuns.createk  rh   rC   c               r   |st        d|      ddi|xs i }| j                  d| dt        i d|d|d|d	|d
|d|d|	d|
d|d|d|d|d|d|d|d|t        j                        t        ||||t        d|it        j                              t        |xs dt        t                 S N8Expected a non-empty value for `thread_id` but received OpenAI-Betaassistants=v2	/threads//runsrb   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rW   rX   rY   rZ   r[   r\   rM   r]   r^   r_   r`   queryFbodyoptionscast_torW   
stream_cls)	
ValueError_postr   r0   RunCreateParamsr'   r3   r"   r5   rf   s                          rA   rg   zRuns.create  sn   : WXaWdeff&QM<ORQzz	{%( "L-/F *+> #L	
 ,-B ():  U *+> & f "; "; U U  *+>!$ "11'* )+'%%y'&:<M<]<]^ ?U23A  !
 !	
rC   r]   r^   r_   r`   c          	         |st        d|      |st        d|      ddi|xs i }| j                  d| d| t        ||||      t              S )	D  
        Retrieves a run.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        rp   5Expected a non-empty value for `run_id` but received rq   rr   rs   /runs/r   ry   rz   r|   _getr'   r3   r@   run_idra   r]   r^   r_   r`   s          rA   retrievezRuns.retrieve:  s    0 WXaWdeffTU[T^_``&QM<ORQyy	{&1(+Q[el   
 	
rC   rS   r]   r^   r_   r`   c          
         |st        d|      |st        d|      ddi|xs i }| j                  d| d| t        d|it        j                        t        ||||      t        	      S )
~  
        Modifies a run.

        Args:
          metadata: Set of 16 key-value pairs that can be attached to an object. This can be useful
              for storing additional information about the object in a structured format. Keys
              can be a maximum of 64 characters long and values can be a maximum of 512
              characters long.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        rp   r   rq   rr   rs   r   rS   r   rx   ry   rz   )r|   r}   r   r1   RunUpdateParamsr'   r3   r@   r   ra   rS   r]   r^   r_   r`   s           rA   updatezRuns.update_  s    < WXaWdeffTU[T^_``&QM<ORQzz	{&1 *h!79J9Z9Z[(+Q[el   
 	
rC   afterbeforelimitorderr]   r^   r_   r`   c                   |st        d|      ddi|xs i }| j                  d| dt        t           t	        ||||	t        ||||dt        j                              t              S 	a!  
        Returns a list of runs belonging to a thread.

        Args:
          after: A cursor for use in pagination. `after` is an object ID that defines your place
              in the list. For instance, if you make a list request and receive 100 objects,
              ending with obj_foo, your subsequent call can include after=obj_foo in order to
              fetch the next page of the list.

          before: A cursor for use in pagination. `before` is an object ID that defines your place
              in the list. For instance, if you make a list request and receive 100 objects,
              starting with obj_foo, your subsequent call can include before=obj_foo in order
              to fetch the previous page of the list.

          limit: A limit on the number of objects to be returned. Limit can range between 1 and
              100, and the default is 20.

          order: Sort order by the `created_at` timestamp of the objects. `asc` for ascending
              order and `desc` for descending order.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        rp   rq   rr   rs   rt   )r   r   r   r   ru   )pagery   rT   )r|   _get_api_listr$   r3   r'   r   r/   RunListParams
r@   ra   r   r   r   r   r]   r^   r_   r`   s
             rA   listz	Runs.list  s    V WXaWdeff&QM<ORQ!!	{%($(+'%%!&"(!&!&	 $11 % " 
 	
rC   c          	         |st        d|      |st        d|      ddi|xs i }| j                  d| d| dt        ||||      t        	      S )
X  
        Cancels a run that is `in_progress`.

        Args:
          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        rp   r   rq   rr   rs   r   /cancelr   r   r|   r}   r'   r3   r   s          rA   cancelzRuns.cancel  s    0 WXaWdeffTU[T^_``&QM<ORQzz	{&8(+Q[el   
 	
rC   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   poll_interval_msr]   r^   r_   r`   c                   | j                  ||||||||||	||||
d|||||||      }| j                  |j                  ||||||      S )
        A helper to create a run an poll for a terminal state. More information on Run
        lifecycles can be found here:
        https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
        Fra   rb   rM   rN   rO   rP   rQ   rR   rS   rT   rV   rX   rY   rU   rW   rZ   r\   r[   r]   r^   r_   r`   ra   r]   r^   r_   r   r`   rg   pollidr@   rb   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   r   ra   r]   r^   r_   r`   runs                           rA   create_and_pollzRuns.create_and_poll  s    B kk%$; 3%"7/+## 3 3'#!/  
2 yyFF'#!-  
 	
rC   use `stream` insteadrN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   r]   r^   r_   r`   c                    yCreate a Run streamNre   r@   rb   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   ra   r]   r^   r_   r`   s                        rA   create_and_streamzRuns.create_and_stream7      : 	rC   c                    yr   re   r@   rb   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   ra   event_handlerr]   r^   r_   r`   s                         rA   r   zRuns.create_and_streamV      < 	rC   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   r   r]   r^   r_   r`   c               |   |st        d|      dd|rdndd|xs i }t        | j                  d| dt        i d	|d
|d|d|d|d|d|d|d|
d|d|ddd|d|d|	d|t        j
                        t        ||||      t        dt        t                 }t        ||xs
 t                     S )r   rp   rr   threads.runs.create_and_streamtruefalserq   zX-Stainless-Stream-Helperz X-Stainless-Custom-Event-Handlerrs   rt   rb   rN   rO   rP   rQ   rR   rS   rT   rV   rX   rY   rW   TrZ   r\   rU   r[   r   rw   r   r|   r   r}   r   r0   r~   r'   r3   r"   r5   r*   r(   )r@   rb   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   ra   r   r]   r^   r_   r`   make_requests                          rA   r   zRuns.create_and_streamv  sx   : WXaWdeff +)I:GW
 "	
 JJ	{%( "L-/F *+> #L	
 ,-B ():  U & "; "; d U *+> *+>  U!$ "11'* )+Q[el 23;
> &l-BjShSjkkrC   c                j   ddi|xs i }t        |      rt        |      |d<   h d}	 | j                  j                  ||||||      }	|	j	                         }
|
j
                  |v r|
S t        |      s+|	j                  j                  d      }|t        |      }nd}| j                  |dz         )
        A helper to poll a run status until it reaches a terminal state. More
        information on Run lifecycles can be found here:
        https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
        X-Stainless-Poll-Helperr    X-Stainless-Custom-Poll-Interval>   failedexpired	cancelled	completed
incompleterequires_actionra   r   r]   r_   r^   r`   openai-poll-after-ms  
r   strrG   r   parsestatusheadersgetint_sleepr@   r   ra   r]   r^   r_   r`   r   terminal_statesresponser   from_headers               rA   r   z	Runs.poll  s     3FT}?RPRT$%@CDT@UM<=j--66#+%' 7 H .."Czz_,
,-&..223IJ*'*;'7$'+$KK(4/0- rC   c                    yr   re   )r@   rb   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   ra   r]   r^   r_   r`   s                         rA   rW   zRuns.stream  r   rC   c                    yr   re   r@   rb   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   ra   r   r]   r^   r_   r`   s                          rA   rW   zRuns.stream	  r   rC   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   r   r]   r^   r_   r`   c                  |st        d|      dd|rdndd|xs i }t        | j                  d| dt        i d	|d
|d|d|d|d|d|d|	d|d|d|ddd|d|
d|d|t        j
                        t        ||||t        d|it        j
                              t        dt        t                 }t        ||xs
 t                     S r   rp   rr   r   r   r   r   rs   rt   rb   rN   rO   rP   rQ   rR   rS   rT   rV   rX   rY   rW   TrZ   rU   r\   r[   rM   ru   rw   r   r   )r@   rb   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   ra   r   r]   r^   r_   r`   r   s                           rA   rW   zRuns.stream)  s   : WXaWdeff +)I:GW
 "	
 JJ	{%( "L-/F *+> #L	
 ,-B ():  U & "; "; d U *+> *+>  U!$ "11'* )+'%%y'&:<M<]<]^ 23C"
F &l-BjShSjkkrC   rW   r]   r^   r_   r`   tool_outputsc                    yam  
        When a run has the `status: "requires_action"` and `required_action.type` is
        `submit_tool_outputs`, this endpoint can be used to submit the outputs from the
        tool calls once they're all completed. All outputs must be submitted in a single
        request.

        Args:
          tool_outputs: A list of tools for which the outputs are being submitted.

          stream: If `true`, returns a stream of events that happen during the Run as server-sent
              events, terminating when the Run enters a terminal state with a `data: [DONE]`
              message.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        Nre   	r@   r   ra   r   rW   r]   r^   r_   r`   s	            rA   submit_tool_outputszRuns.submit_tool_outputst      H 	rC   c                    yam  
        When a run has the `status: "requires_action"` and `required_action.type` is
        `submit_tool_outputs`, this endpoint can be used to submit the outputs from the
        tool calls once they're all completed. All outputs must be submitted in a single
        request.

        Args:
          stream: If `true`, returns a stream of events that happen during the Run as server-sent
              events, terminating when the Run enters a terminal state with a `data: [DONE]`
              message.

          tool_outputs: A list of tools for which the outputs are being submitted.

          extra_headers: Send extra headers

          extra_query: Add additional query parameters to the request

          extra_body: Add additional JSON properties to the request

          timeout: Override the client-level default timeout for this request, in seconds
        Nre   	r@   r   ra   rW   r   r]   r^   r_   r`   s	            rA   r   zRuns.submit_tool_outputs  r   rC   c                    yr   re   r   s	            rA   r   zRuns.submit_tool_outputs  r   rC   ra   rW   r   c          
        |st        d|      |st        d|      ddi|xs i }| j                  d| d| dt        ||dt        j                        t        ||||	      t        |xs d
t        t                 S Nrp   r   rq   rr   rs   r   /submit_tool_outputsr   rW   r   Frw   )	r|   r}   r   r2   RunSubmitToolOutputsParamsr'   r3   r"   r5   r   s	            rA   r   zRuns.submit_tool_outputs  s     WXaWdeffTU[T^_``&QM<ORQzz	{&0DE $0$ /II )+Q[el ?U23  
 	
rC   r   r]   r^   r_   r`   c          
     x    | j                  |||d||||      }	| j                  |	j                  ||||||      S )
        A helper to submit a tool output to a run and poll for a terminal run state.
        More information on Run lifecycles can be found here:
        https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
        Fr   ra   r   rW   r]   r^   r_   r`   r   ra   r]   r^   r_   r`   r   r   r   r   
r@   r   r   ra   r   r]   r^   r_   r`   r   s
             rA   submit_tool_outputs_and_pollz!Runs.submit_tool_outputs_and_poll  sb    & &&%'#! ' 	
 yy66'#!-  
 	
rC   c                    y
        Submit the tool outputs from a previous run and stream the run to a terminal
        state. More information on Run lifecycles can be found here:
        https://platform.openai.com/docs/assistants/how-it-works/runs-and-run-steps
        Nre   r@   r   r   ra   r]   r^   r_   r`   s           rA   submit_tool_outputs_streamzRuns.submit_tool_outputs_stream2      & 	rC   c                    yr   re   	r@   r   r   ra   r   r]   r^   r_   r`   s	            rA   r   zRuns.submit_tool_outputs_streamG      ( 	rC   r   r]   r^   r_   r`   c               H   |st        d|      |st        d|      dd|rdndd|xs i }t        | j                  d| d	| d
t        |ddt        j
                        t        ||||      t        dt        t                 }	t        |	|xs
 t                     S r   r   rp   rr   z'threads.runs.submit_tool_outputs_streamr   r   r   rs   r   r   Tr   r   rw   r   )r|   r   r}   r   r2   r   r'   r3   r"   r5   r*   r(   
r@   r   r   ra   r   r]   r^   r_   r`   requests
             rA   r   zRuns.submit_tool_outputs_stream]  s    & TU[T^_``WXaWdeff +)R:GW
 "	
 JJ	{&0DE $0" /II )+Q[el 23
" &g]=eNcNeffrC   )returnr   )r	  rF   )r	  rJ   .ra   r   rb   r   rM   List[RunStepInclude] | NotGivenrN   Optional[str] | NotGivenrO   BOptional[Iterable[run_create_params.AdditionalMessage]] | NotGivenrP   r  rQ   Optional[int] | NotGivenrR   r  rS   Optional[object] | NotGivenrT   &Union[str, ChatModel, None] | NotGivenrU   bool | NotGivenrV   7Optional[AssistantResponseFormatOptionParam] | NotGivenrW   #Optional[Literal[False]] | NotGivenrX   Optional[float] | NotGivenrY   3Optional[AssistantToolChoiceOptionParam] | NotGivenrZ   1Optional[Iterable[AssistantToolParam]] | NotGivenr[   r  r\   9Optional[run_create_params.TruncationStrategy] | NotGivenr]   Headers | Noner^   Query | Noner_   Body | Noner`   'float | httpx.Timeout | None | NotGivenr	  r3   ).ra   r   rb   r   rW   Literal[True]rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  r]   r  r^   r  r_   r  r`   r  r	  Stream[AssistantStreamEvent]).ra   r   rb   r   rW   boolrM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  r]   r  r^   r  r_   r  r`   r  r	  "Run | Stream[AssistantStreamEvent]).ra   r   rb   r   rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rW   3Optional[Literal[False]] | Literal[True] | NotGivenrX   r  rY   r  rZ   r  r[   r  r\   r  r]   r  r^   r  r_   r  r`   r  r	  r  r   r   ra   r   r]   r  r^   r  r_   r  r`   r  r	  r3   r   r   ra   r   rS   r  r]   r  r^   r  r_   r  r`   r  r	  r3   )ra   r   r   str | NotGivenr   r#  r   int | NotGivenr   !Literal['asc', 'desc'] | NotGivenr]   r  r^   r  r_   r  r`   r  r	  zSyncCursorPage[Run].rb   r   rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  r   r$  ra   r   r]   r  r^   r  r_   r  r`   r  r	  r3   )*rb   r   rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r]   r  r^   r  r_   r  r`   r  r	  -AssistantStreamManager[AssistantEventHandler]),rb   r   rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r   r)   r]   r  r^   r  r_   r  r`   r  r	  .AssistantStreamManager[AssistantEventHandlerT]),rb   r   rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r   AssistantEventHandlerT | Noner]   r  r^   r  r_   r  r`   r  r	  ^AssistantStreamManager[AssistantEventHandler] | AssistantStreamManager[AssistantEventHandlerT]r   r   ra   r   r]   r  r^   r  r_   r  r`   r  r   r$  r	  r3   ),rb   r   rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r]   r  r^   r  r_   r  r`   r  r	  r'  ).rb   r   rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r   r)   r]   r  r^   r  r_   r  r`   r  r	  r(  ).rb   r   rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r   r)  r]   r  r^   r  r_   r  r`   r  r	  r*  r   r   ra   r   r   3Iterable[run_submit_tool_outputs_params.ToolOutput]rW   r  r]   r  r^   r  r_   r  r`   r  r	  r3   )r   r   ra   r   rW   r  r   r-  r]   r  r^   r  r_   r  r`   r  r	  r  )r   r   ra   r   rW   r  r   r-  r]   r  r^   r  r_   r  r`   r  r	  r  )r   r   ra   r   r   r-  rW   r   r]   r  r^   r  r_   r  r`   r  r	  r  r   r-  r   r   ra   r   r   r$  r]   r  r^   r  r_   r  r`   r  r	  r3   )r   r-  r   r   ra   r   r]   r  r^   r  r_   r  r`   r  r	  r'  )r   r-  r   r   ra   r   r   r)   r]   r  r^   r  r_   r  r`   r  r	  r(  )r   r-  r   r   ra   r   r   r)  r]   r  r^   r  r_   r  r`   r  r	  r*  __name__
__module____qualname__r   rB   rG   rK   r
   r   rg   r   r   r   r   r   r   typing_extensions
deprecatedr   r   rW   r   r   r   re   rC   rA   r9   r9   ;   s   # # ) ) / /  4=<Ebk1::C6?098A/8S\6?2;KTCL,5Yb )-$("&;D5II 	I
 1I ":I `I /I  8I 4I .I 6I -I QI 4I  0!I" I#I$ A%I& *'I( W)I. &/I0 "1I2  3I4 95I6 
7I IV  4=<Ebk1::C6?098A/8S\2;KTCL,5Yb )-$("&;D5II 	I
 I 1I ":I `I /I  8I 4I .I 6I -I QI  0!I" I#I$ A%I& *'I( W)I. &/I0 "1I2  3I4 95I6 
&7I IV  4=<Ebk1::C6?098A/8S\2;KTCL,5Yb )-$("&;D5II 	I
 I 1I ":I `I /I  8I 4I .I 6I -I QI  0!I" I#I$ A%I& *'I( W)I. &/I0 "1I2  3I4 95I6 
,7I IV N#nh%?@ 4=<Ebk1::C6?098A/8S\FO2;KTCL,5Yb )-$("&;D5@
@
 	@

 1@
 ":@
 `@
 /@
  8@
 4@
 .@
 6@
 -@
 Q@
 D@
  0!@
" I#@
$ A%@
& *'@
( W)@
. &/@
0 "1@
2  3@
4 95@
6 
,7@
 A@
R )-$("&;D#
#
 	#
 &#
 "#
  #
 9#
 
#
T 1: )-$("&;D*
*
 	*

 .*
 &*
 "*
  *
 9*
 
*
` !*!* )3< )-$("&;DA
A
 	A

 A
 A
 1A
 &A
 "A
  A
 9A
 
A
T )-$("&;D#
#
 	#
 &#
 "#
  #
 9#
 
#
R 4=<Ebk1::C6?098A/8S\2;KTCL,5Yb+4 )-$("&;D5B
 B
 1	B

 ":B
 `B
 /B
  8B
 4B
 .B
 6B
 -B
 QB
 0B
 IB
  A!B
" *#B
$ W%B
& )'B
( )B
. &/B
0 "1B
2  3B
4 95B
6 
7B
H !!!"89
 =Fbk1::C6?098A/8S\2;KTCL,5Yb )-$("&;D1  ":	
 ` /  8 4 . 6 - Q 0 I A  *!" W#$ %* &+, "-.  /0 912 
73 : : !!!"89
 =Fbk1::C6?098A/8S\2;KTCL,5Yb
 )-$("&;D3  ":	
 ` /  8 4 . 6 - Q 0 I A  *!" W#$ %& .', &-. "/0  12 934 
85 : < "!!"89
 =Fbk1::C6?098A/8S\2;KTCL,5Yb7; )-$("&;D3Dl Dl ":	Dl
 `Dl /Dl  8Dl 4Dl .Dl 6Dl -Dl QDl 0Dl IDl ADl  *!Dl" W#Dl$ %Dl& 5'Dl, &-Dl. "/Dl0  1Dl2 93Dl4 
h5Dl :DlT )-$("&;D+4+1+1 +1 &	+1
 "+1  +1 9+1 )+1 
+1Z 
 4=<Ebk1::C6?098A/8S\2;KTCL,5Yb )-$("&;D3  1	
 ": ` /  8 4 . 6 - Q 0 I  A!" *#$ W%& ', &-. "/0  12 934 
75 < 
 4=<Ebk1::C6?098A/8S\2;KTCL,5Yb
 )-$("&;D5  1	
 ": ` /  8 4 . 6 - Q 0 I  A!" *#$ W%& '( .). &/0 "12  34 956 
87 F 4=<Ebk1::C6?098A/8S\2;KTCL,5Yb7; )-$("&;D5Il Il 1	Il
 ":Il `Il /Il  8Il 4Il .Il 6Il -Il QIl 0Il IIl  A!Il" *#Il$ W%Il& 'Il( 5)Il. &/Il0 "1Il2  3Il4 95Il6 
h7IlV  7@ )-$("&;D## 	#
 J# 4# &# "#  # 9# 
# #J  )-$("&;D## 	#
 # J# &# "#  # 9# 
&# #J  )-$("&;D## 	#
 # J# &# "#  # 9# 
,# #J K02YZ GP )-$("&;D"
"
 	"

 J"
 D"
 &"
 ""
  "
 9"
 
,"
 ["
T ,5 )-$("&;D%
 J%
 	%

 %
 )%
 &%
 "%
  %
 9%
 
%
N  )-$("&;D J 	
  & "   9 
7 (  )-$("&;D J 	
  . & "   9 
8 6 8< )-$("&;D0g J0g 	0g
 0g 50g &0g "0g  0g 90g 
h0grC   c                  
   e Zd Zed/d       Zed0d       Zed1d       Zeeeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d2d	       Z	eeeeeeeeeeeeeeeeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d3d       Z	eeeeeeeeeeeeeeeeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d4d       Z	 e
dgddg      eeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d5d       Z	ddded	 	 	 	 	 	 	 	 	 	 	 	 	 d6dZeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d7dZeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d8dZddded	 	 	 	 	 	 	 	 	 	 	 	 	 d6dZeeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d9dZe ej"                  d      eeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d:d              Ze ej"                  d      eeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d;d              Z ej"                  d      eeeeeeeeeeeeeedddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d<d       Zdddeef	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d=dZeeeeeeeeeeeeeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d:d       Zeeeeeeeeeeeeeeeeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d>d       Zeeeeeeeeeeeeeeedddded 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d?d!Zeeddded"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d@d$       Zeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dAd%       Zeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dBd&       Z e
dd#gg d'      eddded"	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dCd(       Zeddded)	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dDd*Zeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dEd+       Zeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dFd,       Zdddded-	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dGd.Zy)Hr:   c                ,    t        | j                        S r=   )r   r>   r?   s    rA   rB   zAsyncRuns.steps  s    $,,''rC   c                    t        |       S rE   )AsyncRunsWithRawResponser?   s    rA   rG   zAsyncRuns.with_raw_response  s     (--rC   c                    t        |       S rI   )AsyncRunsWithStreamingResponser?   s    rA   rK   z!AsyncRuns.with_streaming_response  s     .d33rC   NrL   ra   rb   rW   c                  K   ywrd   re   rf   s                          rA   rg   zAsyncRuns.create       T 	   ri   c                  K   ywrk   re   rl   s                          rA   rg   zAsyncRuns.create4  r<  r=  c                  K   ywrk   re   rl   s                          rA   rg   zAsyncRuns.create  r<  r=  c                 K   |st        d|      ddi|xs i }| j                  d| dt        i d|d|d|d	|d
|d|d|	d|
d|d|d|d|d|d|d|d|t        j                         d {   t        ||||t        d|it        j                         d {         t        |xs dt        t                  d {   S 7 X7 .7 wro   )	r|   r}   r   r0   r~   r'   r3   r#   r5   rf   s                          rA   rg   zAsyncRuns.createL  s    : WXaWdeff&QM<ORQZZ	{%(,"L-/F *+> #L	
 ,-B ():  U *+> & f "; "; U U  *+>!$ "11' * )+'%19g2FHYHiHijj ?U"#78A   !
 !
 !	
4 k9!
s6   A8C:C
;+C&C''CCCCCr   c          	        K   |st        d|      |st        d|      ddi|xs i }| j                  d| d| t        ||||      t               d	{   S 7 w)
r   rp   r   rq   rr   rs   r   r   r   Nr   r   s          rA   r   zAsyncRuns.retrieve  s     0 WXaWdeffTU[T^_``&QM<ORQYY	{&1(+Q[el   
 
 	
 
s   AA"A A"r   c          
       K   |st        d|      |st        d|      ddi|xs i }| j                  d| d| t        d|it        j                         d{   t        ||||	      t        
       d{   S 7 $7 w)r   rp   r   rq   rr   rs   r   rS   Nr   r   )r|   r}   r   r1   r   r'   r3   r   s           rA   r   zAsyncRuns.update  s     < WXaWdeffTU[T^_``&QM<ORQZZ	{&1,j(-CEVEfEfgg(+Q[el    
 
 	
g
s$   ABB
B>B?BBr   c                   |st        d|      ddi|xs i }| j                  d| dt        t           t	        ||||	t        ||||dt        j                              t              S r   )r|   r   r%   r3   r'   r   r/   r   r   s
             rA   r   zAsyncRuns.list  s    V WXaWdeff&QM<ORQ!!	{%( %(+'%%!&"(!&!&	 $11 % " 
 	
rC   c          	        K   |st        d|      |st        d|      ddi|xs i }| j                  d| d| dt        ||||      t        	       d
{   S 7 w)r   rp   r   rq   rr   rs   r   r   r   r   Nr   r   s          rA   r   zAsyncRuns.cancel#  s     0 WXaWdeffTU[T^_``&QM<ORQZZ	{&8(+Q[el    
 
 	
 
s   AA#A!A#r   c                  K   | j                  ||||||||||	||||
d|||||||       d{   }| j                  |j                  ||||||       d{   S 7 .7 w)r   Fr   Nr   r   r   s                           rA   r   zAsyncRuns.create_and_pollH  s     B KK%$; 3%"7/+## 3 3'#!/   
 
2 YYFF'#!-  
 
 	
3
2
s!   +A A)A AA A r   r   c                    yr   re   r   s                        rA   r   zAsyncRuns.create_and_stream  r   rC   c                    yr   re   r   s                         rA   r   zAsyncRuns.create_and_stream  r   rC   r   c          
     r   |st        d|      dd|rdndd|xs i }| j                  d| dt        i d	|d
|d|d|d|d|d|d|d|
d|d|ddd|d|d|d|	t        j                        t        ||||      t        dt        t                 }t        ||xs
 t                     S )r   rp   rr   r   r   r   r   rs   rt   rb   rN   rO   rP   rQ   rR   rS   rT   rV   rX   rY   rW   TrZ   r\   r[   rU   r   rw   r   r|   r}   r   r0   r~   r'   r3   r#   r5   r-   r+   )r@   rb   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   ra   r   r]   r^   r_   r`   r  s                          rA   r   zAsyncRuns.create_and_stream  s{   @ WXaWdeff +)I:GW
 "	
 **	{%( "L-/F *+> #L	
 ,-B ():  U & "; "; d U *+> U  *+>!$ "11'* )+Q[el "#789  
< +7-BoSmSopprC   c                  K   ddi|xs i }t        |      rt        |      |d<   h d}	 | j                  j                  ||||||       d{   }	|	j	                         }
|
j
                  |v r|
S t        |      s+|	j                  j                  d      }|t        |      }nd}| j                  |dz         d{    7 w7 w)	r   r   r   r   >   r   r   r   r   r   r   r   Nr   r   r   r   s               rA   r   zAsyncRuns.poll	  s      3FT}?RPRT$%@CDT@UM<=j!33<<#+%' =  H .."Czz_,
,-&..223IJ*'*;'7$'+$++.5666- * 7s%   ACCA1CC	C	Cc                    yr   re   r   s                        rA   rW   zAsyncRuns.streamA	  s    8 	rC   c                    yr   re   r   s                          rA   rW   zAsyncRuns.stream_	  r   rC   r   c                  |st        d|      dd|rdndd|xs i }| j                  d| dt        i d	|d
|d|d|d|d|d|d|	d|d|d|ddd|d|
d|d|t        j                        t        ||||t        d|it        j                              t        dt        t                 }t        ||xs
 t                     S r   rI  )r@   rb   rM   rN   rO   rP   rQ   rR   rS   rT   rU   rV   rX   rY   rZ   r[   r\   ra   r   r]   r^   r_   r`   r  s                           rA   rW   zAsyncRuns.stream	  s   @ WXaWdeff +)I:GW
 "	
 **	{%( "L-/F *+> #L	
 ,-B ():  U & "; "; d U *+> *+>  U!$ "11'* )+'%%y'&:<M<]<]^ "#78A  !
D +7-BoSmSopprC   r   r   c                  K   ywr   re   r   s	            rA   r   zAsyncRuns.submit_tool_outputs	       H 	r=  c                  K   ywr   re   r   s	            rA   r   zAsyncRuns.submit_tool_outputs	  rO  r=  c                  K   ywr   re   r   s	            rA   r   zAsyncRuns.submit_tool_outputs
  rO  r=  r   c          
     8  K   |st        d|      |st        d|      ddi|xs i }| j                  d| d| dt        ||dt        j                         d {   t        ||||	      t        |xs d
t        t                  d {   S 7 57 wr   )	r|   r}   r   r2   r   r'   r3   r#   r5   r   s	            rA   r   zAsyncRuns.submit_tool_outputs>
  s      WXaWdeffTU[T^_``&QM<ORQZZ	{&0DE,$0$ /II  )+Q[el ?U"#78   
 
 	

s$   AB B
!0BBBBr   c          
        K   | j                  |||d||||       d{   }	| j                  |	j                  ||||||       d{   S 7 .7 w)r   Fr   Nr   r   r   s
             rA   r   z&AsyncRuns.submit_tool_outputs_and_pollc
  s{     & ,,%'#! - 	
 	
 YY66'#!-  
 
 	
	

s!   AA)A	A
AAc                    yr   re   r   s           rA   r   z$AsyncRuns.submit_tool_outputs_stream
  r   rC   c                    yr   re   r  s	            rA   r   z$AsyncRuns.submit_tool_outputs_stream
  r  rC   r  c          
     >   |st        d|      |st        d|      dd|rdndd|xs i }| j                  d| d	| d
t        |ddt        j                        t        ||||      t        dt        t                 }	t        |	|xs
 t                     S r  )r|   r}   r   r2   r   r'   r3   r#   r5   r-   r+   r  s
             rA   r   z$AsyncRuns.submit_tool_outputs_stream
  s    , TU[T^_``WXaWdeff +)R:GW
 "	
 **	{&0DE $0" /II )+Q[el "#78  
  +7-BoSmSopprC   )r	  r   )r	  r8  )r	  r:  r
  ).ra   r   rb   r   rW   r  rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  r]   r  r^   r  r_   r  r`   r  r	  !AsyncStream[AssistantStreamEvent]).ra   r   rb   r   rW   r  rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  r]   r  r^   r  r_   r  r`   r  r	  'Run | AsyncStream[AssistantStreamEvent]).ra   r   rb   r   rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rW   r   rX   r  rY   r  rZ   r  r[   r  r\   r  r]   r  r^   r  r_   r  r`   r  r	  rX  r!  r"  )ra   r   r   r#  r   r#  r   r$  r   r%  r]   r  r^   r  r_   r  r`   r  r	  z)AsyncPaginator[Run, AsyncCursorPage[Run]]r&  )*rb   r   rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r]   r  r^   r  r_   r  r`   r  r	  7AsyncAssistantStreamManager[AsyncAssistantEventHandler]),rb   r   rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r   r,   r]   r  r^   r  r_   r  r`   r  r	  8AsyncAssistantStreamManager[AsyncAssistantEventHandlerT]),rb   r   rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r   "AsyncAssistantEventHandlerT | Noner]   r  r^   r  r_   r  r`   r  r	  rAsyncAssistantStreamManager[AsyncAssistantEventHandler] | AsyncAssistantStreamManager[AsyncAssistantEventHandlerT]r+  ).rb   r   rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r   r,   r]   r  r^   r  r_   r  r`   r  r	  rZ  ).rb   r   rM   r  rN   r  rO   r  rP   r  rQ   r  rR   r  rS   r  rT   r  rU   r  rV   r  rX   r  rY   r  rZ   r  r[   r  r\   r  ra   r   r   r[  r]   r  r^   r  r_   r  r`   r  r	  r\  r,  )r   r   ra   r   rW   r  r   r-  r]   r  r^   r  r_   r  r`   r  r	  rW  )r   r   ra   r   rW   r  r   r-  r]   r  r^   r  r_   r  r`   r  r	  rX  )r   r   ra   r   r   r-  rW   r   r]   r  r^   r  r_   r  r`   r  r	  rX  r.  )r   r-  r   r   ra   r   r]   r  r^   r  r_   r  r`   r  r	  rY  )r   r-  r   r   ra   r   r   r,   r]   r  r^   r  r_   r  r`   r  r	  rZ  )r   r-  r   r   ra   r   r   r[  r]   r  r^   r  r_   r  r`   r  r	  r\  r/  re   rC   rA   r:   r:     s   ( ( . . 4 4  4=<Ebk1::C6?098A/8S\6?2;KTCL,5Yb )-$("&;D5II 	I
 1I ":I `I /I  8I 4I .I 6I -I QI 4I  0!I" I#I$ A%I& *'I( W)I. &/I0 "1I2  3I4 95I6 
7I IV  4=<Ebk1::C6?098A/8S\2;KTCL,5Yb )-$("&;D5II 	I
 I 1I ":I `I /I  8I 4I .I 6I -I QI  0!I" I#I$ A%I& *'I( W)I. &/I0 "1I2  3I4 95I6 
+7I IV  4=<Ebk1::C6?098A/8S\2;KTCL,5Yb )-$("&;D5II 	I
 I 1I ":I `I /I  8I 4I .I 6I -I QI  0!I" I#I$ A%I& *'I( W)I. &/I0 "1I2  3I4 95I6 
17I IV N#nh%?@ 4=<Ebk1::C6?098A/8S\FO2;KTCL,5Yb )-$("&;D5@
@
 	@

 1@
 ":@
 `@
 /@
  8@
 4@
 .@
 6@
 -@
 Q@
 D@
  0!@
" I#@
$ A%@
& *'@
( W)@
. &/@
0 "1@
2  3@
4 95@
6 
17@
 A@
R )-$("&;D#
#
 	#
 &#
 "#
  #
 9#
 
#
T 1: )-$("&;D*
*
 	*

 .*
 &*
 "*
  *
 9*
 
*
` !*!* )3< )-$("&;DA
A
 	A

 A
 A
 1A
 &A
 "A
  A
 9A
 
3A
T )-$("&;D#
#
 	#
 &#
 "#
  #
 9#
 
#
R 4=<Ebk1::C6?098A/8S\2;KTCL,5Yb+4 )-$("&;D5B
 B
 1	B

 ":B
 `B
 /B
  8B
 4B
 .B
 6B
 -B
 QB
 0B
 IB
  A!B
" *#B
$ W%B
& )'B
( )B
. &/B
0 "1B
2  3B
4 95B
6 
7B
H !!!"89
 =Fbk1::C6?098A/8S\2;KTCL,5Yb )-$("&;D1  ":	
 ` /  8 4 . 6 - Q 0 I A  *!" W#$ %* &+, "-.  /0 912 
A3 : : !!!"89
 =Fbk1::C6?098A/8S\2;KTCL,5Yb
 )-$("&;D3  ":	
 ` /  8 4 . 6 - Q 0 I A  *!" W#$ %& 3', &-. "/0  12 934 
B5 : < "!!"89
 =Fbk1::C6?098A/8S\2;KTCL,5Yb<@ )-$("&;D3Fq Fq ":	Fq
 `Fq /Fq  8Fq 4Fq .Fq 6Fq -Fq QFq 0Fq IFq AFq  *!Fq" W#Fq$ %Fq& :'Fq, &-Fq. "/Fq0  1Fq2 93Fq6	C7Fq :FqX )-$("&;D+4+7+7 +7 &	+7
 "+7  +7 9+7 )+7 
+7Z 
 =Fbk1::C6?098A/8S\2;KTCL,5Yb )-$("&;D1  ":	
 ` /  8 4 . 6 - Q 0 I A  *!" W#$ %* &+, "-.  /0 912 
A3 : 
 4=<Ebk1::C6?098A/8S\2;KTCL,5Yb
 )-$("&;D5  1	
 ": ` /  8 4 . 6 - Q 0 I  A!" *#$ W%& '( 3). &/0 "12  34 956 
B7 F 4=<Ebk1::C6?098A/8S\2;KTCL,5Yb<@ )-$("&;D5Kq Kq 1	Kq
 ":Kq `Kq /Kq  8Kq 4Kq .Kq 6Kq -Kq QKq 0Kq IKq  A!Kq" *#Kq$ W%Kq& 'Kq( :)Kq. &/Kq0 "1Kq2  3Kq4 95Kq8	C9KqZ  7@ )-$("&;D## 	#
 J# 4# &# "#  # 9# 
# #J  )-$("&;D## 	#
 # J# &# "#  # 9# 
+# #J  )-$("&;D## 	#
 # J# &# "#  # 9# 
1# #J K02YZ GP )-$("&;D"
"
 	"

 J"
 D"
 &"
 ""
  "
 9"
 
1"
 ["
T ,5 )-$("&;D%
 J%
 	%

 %
 )%
 &%
 "%
  %
 9%
 
%
N  )-$("&;D J 	
  & "   9 
A (  )-$("&;D J 	
  3 & "   9 
B 6 =A )-$("&;D2q J2q 	2q
 2q :2q &2q "2q  2q 92q	C2qrC   c                  &    e Zd ZddZedd       Zy)rF   c                   || _         t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j
                        | _        t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j                        | _        y r=   )	_runsr   to_raw_response_wrapperrg   r   r   r   r   r   r@   runss     rA   __init__zRunsWithRawResponse.__init__
  s    
&>>KK
 )@@MM
 '>>KK
 %<<II
	 '>>KK
 $4#K#K$$$
 rC   c                @    t        | j                  j                        S r=   )r   r_  rB   r?   s    rA   rB   zRunsWithRawResponse.steps  s    #DJJ$4$455rC   Nrb  r9   r	  None)r	  r   r0  r1  r2  rc  r   rB   re   rC   rA   rF   rF   
  s    
, 6 6rC   rF   c                  &    e Zd ZddZedd       Zy)r8  c                   || _         t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j
                        | _        t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j                        | _        y r=   )	r_  r   async_to_raw_response_wrapperrg   r   r   r   r   r   ra  s     rA   rc  z!AsyncRunsWithRawResponse.__init__  s    
&DDKK
 )FFMM
 'DDKK
 %BBII
	 'DDKK
 $4#Q#Q$$$
 rC   c                @    t        | j                  j                        S r=   )r   r_  rB   r?   s    rA   rB   zAsyncRunsWithRawResponse.steps  s    ()9)9::rC   Nrb  r:   r	  rf  )r	  r   rg  re   rC   rA   r8  r8    s    
, ; ;rC   r8  c                  &    e Zd ZddZedd       Zy)rJ   c                J   || _         t        |j                        | _        t        |j                        | _        t        |j                        | _        t        |j
                        | _        t        |j                        | _        t        |j                        | _        y r=   )r_  r    rg   r   r   r   r   r   ra  s     rA   rc  z"RunsWithStreamingResponse.__init__#  s    
2KK
 5MM
 3KK
 1II
	 3KK
 $@$$$
 rC   c                @    t        | j                  j                        S r=   )r   r_  rB   r?   s    rA   rB   zRunsWithStreamingResponse.steps9  s    )$***:*:;;rC   Nre  )r	  r   rg  re   rC   rA   rJ   rJ   "  s    
, < <rC   rJ   c                  &    e Zd ZddZedd       Zy)r:  c                J   || _         t        |j                        | _        t        |j                        | _        t        |j                        | _        t        |j
                        | _        t        |j                        | _        t        |j                        | _        y r=   )r_  r!   rg   r   r   r   r   r   ra  s     rA   rc  z'AsyncRunsWithStreamingResponse.__init__?  s    
8KK
 ;MM
 9KK
 7II
	 9KK
 $F$$$
 rC   c                @    t        | j                  j                        S r=   )r   r_  rB   r?   s    rA   rB   z$AsyncRunsWithStreamingResponse.stepsU  s    .tzz/?/?@@rC   Nrl  )r	  r   rg  re   rC   rA   r:  r:  >  s    
, A ArC   r:  )S
__future__r   r3  typingr   r   r   r   	functoolsr   r	   r
   httpx r   rB   r   r   r   r   r   r   _typesr   r   r   r   r   _utilsr   r   r   r   _compatr   	_resourcer   r   	_responser    r!   
_streamingr"   r#   
paginationr$   r%   _base_clientr&   r'   lib.streamingr(   r)   r*   r+   r,   r-   types.chat_modelr.   types.beta.threadsr/   r0   r1   r2   types.beta.threads.runr3   types.beta.assistant_tool_paramr4   !types.beta.assistant_stream_eventr5   (types.beta.threads.runs.run_step_includer6   -types.beta.assistant_tool_choice_option_paramr7   1types.beta.assistant_response_format_option_paramr8   __all__r9   r:   rF   r8  rJ   r:  re   rC   rA   <module>r     s    #  2 2  /  "  B A  ) < [ / ; B  ,  , C G H ] e;
Rg? Rgj*Wq  Wqt*6 68; ;8< <8A ArC   