
    gp                      d dl mZ d dl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 ddlm Z m!Z!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/m0Z0 ddl1m2Z2m3Z3m4Z4 ddl5m6Z6 ddl7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z= ddl>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)'    )annotations)UnionIterableOptional)partial)LiteraloverloadN   )_legacy_response   )MessagesAsyncMessagesMessagesWithRawResponseAsyncMessagesWithRawResponseMessagesWithStreamingResponse"AsyncMessagesWithStreamingResponse)	NOT_GIVENBodyQueryHeadersNotGiven)required_argsmaybe_transformasync_maybe_transform)Runs	AsyncRunsRunsWithRawResponseAsyncRunsWithRawResponseRunsWithStreamingResponseAsyncRunsWithStreamingResponse)cached_property)SyncAPIResourceAsyncAPIResource)to_streamed_response_wrapper"async_to_streamed_response_wrapper)StreamAsyncStream)thread_create_paramsthread_update_paramsthread_create_and_run_params)make_request_options)AssistantEventHandlerAssistantEventHandlerTAssistantStreamManagerAsyncAssistantEventHandlerAsyncAssistantEventHandlerTAsyncAssistantStreamManager)	ChatModel)Thread)Run)ThreadDeleted)AssistantStreamEvent)AssistantToolChoiceOptionParam)"AssistantResponseFormatOptionParamThreadsAsyncThreadsc                  z   e Zd Zedd       Zedd       Zedd       Zedd       Zeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	ddded	 	 	 	 	 	 	 	 	 	 	 d d	Z
eeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ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ed	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 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dgddg      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ed	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 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ddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d)d       Zeeeeeeeeeeeeeedddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*dZy)+r9   c                ,    t        | j                        S N)r   _clientselfs    Z/var/www/openai/venv/lib/python3.12/site-packages/openai/resources/beta/threads/threads.pyrunszThreads.runs@   s    DLL!!    c                ,    t        | j                        S r=   )r   r>   r?   s    rA   messageszThreads.messagesD   s    %%rC   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
        )ThreadsWithRawResponser?   s    rA   with_raw_responsezThreads.with_raw_responseH   s     &d++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
        )ThreadsWithStreamingResponser?   s    rA   with_streaming_responsezThreads.with_streaming_responseR   s     ,D11rC   NrE   metadatatool_resourcesextra_headersextra_query
extra_bodytimeoutc          
         ddi|xs i }| j                  dt        |||dt        j                        t	        ||||      t
              S )[  
        Create a thread.

        Args:
          messages: A list of [messages](https://platform.openai.com/docs/api-reference/messages) to
              start the thread with.

          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.

          tool_resources: A set of resources that are made available to the assistant's tools in this
              thread. The resources are specific to the type of tool. For example, the
              `code_interpreter` tool requires a list of file IDs, while the `file_search`
              tool requires a list of vector store IDs.

          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
        OpenAI-Betaassistants=v2/threadsrE   rO   rP   rQ   rR   rS   rT   bodyoptionscast_to)_postr   r(   ThreadCreateParamsr+   r3   r@   rE   rO   rP   rQ   rR   rS   rT   s           rA   createzThreads.create[   sm    L 'QM<ORQzz  ( (&4
 %77 )+Q[el   
 	
rC   r[   c          	         |st        d|      ddi|xs i }| j                  d| t        ||||      t              S )G  
        Retrieves a thread.

        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
        8Expected a non-empty value for `thread_id` but received rW   rX   	/threads/r[   r^   r_   
ValueError_getr+   r3   r@   	thread_idrQ   rR   rS   rT   s         rA   retrievezThreads.retrieve   sh    . WXaWdeff&QM<ORQyy	{#(+Q[el   
 	
rC   rO   rP   rQ   rR   rS   rT   c          
         |st        d|      ddi|xs i }| j                  d| t        ||dt        j                        t        ||||      t              S )  
        Modifies a thread.

        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.

          tool_resources: A set of resources that are made available to the assistant's tools in this
              thread. The resources are specific to the type of tool. For example, the
              `code_interpreter` tool requires a list of file IDs, while the `file_search`
              tool requires a list of vector store IDs.

          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
        rf   rW   rX   rg   rO   rP   r[   r\   )rj   r`   r   r)   ThreadUpdateParamsr+   r3   r@   rm   rO   rP   rQ   rR   rS   rT   s           rA   updatezThreads.update   s    F WXaWdeff&QM<ORQzz	{#  (&4 %77 )+Q[el   
 	
rC   c          	         |st        d|      ddi|xs i }| j                  d| t        ||||      t              S )D  
        Delete a thread.

        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
        rf   rW   rX   rg   r[   rh   rj   _deleter+   r5   rl   s         rA   deletezThreads.delete   sh    . WXaWdeff&QM<ORQ||	{#(+Q[el "  
 	
rC   instructionsmax_completion_tokensmax_prompt_tokensrO   modelparallel_tool_callsresponse_formatstreamtemperaturethreadtool_choicerP   toolstop_ptruncation_strategyrQ   rR   rS   rT   assistant_idr   c                    ya  
        Create a thread and run it in one request.

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

          instructions: Override the default system message 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.

          thread: If no thread is provided, an empty thread will be created.

          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.

          tool_resources: A set of resources that are used by the assistant's tools. The resources are
              specific to the type of tool. For example, the `code_interpreter` tool requires
              a list of file IDs, while the `file_search` tool requires a list of vector store
              IDs.

          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@   r   r|   r}   r~   rO   r   r   r   r   r   r   r   rP   r   r   r   rQ   rR   rS   rT   s                        rA   create_and_runzThreads.create_and_run      @ 	rC   r|   r}   r~   rO   r   r   r   r   r   r   rP   r   r   r   rQ   rR   rS   rT   c                    ya  
        Create a thread and run it in one request.

        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.

          instructions: Override the default system message 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.

          thread: If no thread is provided, an empty thread will be created.

          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.

          tool_resources: A set of resources that are used by the assistant's tools. The resources are
              specific to the type of tool. For example, the `code_interpreter` tool requires
              a list of file IDs, while the `file_search` tool requires a list of vector store
              IDs.

          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
        Nr   r@   r   r   r|   r}   r~   rO   r   r   r   r   r   r   rP   r   r   r   rQ   rR   rS   rT   s                        rA   r   zThreads.create_and_run  r   rC   c                    yr   r   r   s                        rA   r   zThreads.create_and_run  r   rC   c          
        ddi|xs i }| j                  dt        i d|d|d|d|d|d	|d
|d|d|	d|
d|d|d|d|d|d|t        j                        t	        ||||      t
        |	xs dt        t                 S NrW   rX   /threads/runsr   r|   r}   r~   rO   r   r   r   r   r   r   r   rP   r   r   r   r[   Fr]   r^   r_   r   
stream_cls)r`   r   r*   ThreadCreateAndRunParamsr+   r4   r&   r6   r   s                        rA   r   zThreads.create_and_run  s3   6 'QM<ORQzz "L"L ,-B ():	
  U *+> & f "; f "; %n U U  *+>!$ -EE'* )+Q[el ?U239  
 	
rC   r|   r}   r~   rO   r   r   r   r   r   r   rP   r   r   r   poll_interval_msrQ   rR   rS   rT   c                   | j                  |||||||||	d|
|||||||||      }| j                  j                  |j                  |j                  |||||      S )
        A helper to create a thread, start a run and then 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r   r|   r}   r~   rO   r   r   r   r   r   r   rP   r   r   r   r   rQ   rR   rS   rT   r   rB   pollidrm   r@   r   r|   r}   r~   rO   r   r   r   r   r   r   rP   r   r   r   r   rQ   rR   rS   rT   runs                         rA   create_and_run_pollzThreads.create_and_run_poll  s    > !!%%"7/ 3+#)# 3'#!) " 
, yy~~cffcmm]KQ[]dfvwwrC   c                    y'Create a thread and stream the run backNr   r@   r   r|   r}   r~   rO   r   r   r   r   r   r   rP   r   r   r   rQ   rR   rS   rT   s                       rA   create_and_run_streamzThreads.create_and_run_stream      6 	rC   c                    yr   r   r@   r   r|   r}   r~   rO   r   r   r   r   r   r   rP   r   r   r   event_handlerrQ   rR   rS   rT   s                        rA   r   zThreads.create_and_run_stream       8 	rC   r|   r}   r~   rO   r   r   r   r   r   r   rP   r   r   r   r   rQ   rR   rS   rT   c               T   dd|rdndd|xs i }t        | j                  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   rX   zthreads.create_and_run_streamtruefalse)rW   zX-Stainless-Stream-Helperz X-Stainless-Custom-Event-Handlerr   r   r|   r}   r~   rO   r   r   r   r   r   r   Tr   r   rP   r   r   r[   r   )r   )r   r`   r   r*   r   r+   r4   r&   r6   r.   r,   )r@   r   r|   r}   r~   rO   r   r   r   r   r   r   rP   r   r   r   r   rQ   rR   rS   rT   make_requests                         rA   r   zThreads.create_and_run_stream>  sS   8 +)H:GW
 "	
 JJ "L"L ,-B ():	
  U *+> & "; "; d f U %n *+>  U!$ -EE'* )+Q[el 23;
> &l-BjShSjkkrC   )returnr   )r   r   )r   rH   )r   rL   rE   z1Iterable[thread_create_params.Message] | NotGivenrO   Optional[object] | NotGivenrP   z7Optional[thread_create_params.ToolResources] | NotGivenrQ   Headers | NonerR   Query | NonerS   Body | NonerT   'float | httpx.Timeout | None | NotGivenr   r3   rm   strrQ   r   rR   r   rS   r   rT   r   r   r3   rm   r   rO   r   rP   z7Optional[thread_update_params.ToolResources] | NotGivenrQ   r   rR   r   rS   r   rT   r   r   r3   rm   r   rQ   r   rR   r   rS   r   rT   r   r   r5   *r   r   r|   Optional[str] | NotGivenr}   Optional[int] | NotGivenr~   r   rO   r   r   &Union[str, ChatModel, None] | NotGivenr   bool | NotGivenr   7Optional[AssistantResponseFormatOptionParam] | NotGivenr   z#Optional[Literal[False]] | NotGivenr   Optional[float] | NotGivenr   .thread_create_and_run_params.Thread | NotGivenr   3Optional[AssistantToolChoiceOptionParam] | NotGivenrP   ?Optional[thread_create_and_run_params.ToolResources] | NotGivenr   @Optional[Iterable[thread_create_and_run_params.Tool]] | NotGivenr   r   r   DOptional[thread_create_and_run_params.TruncationStrategy] | NotGivenrQ   r   rR   r   rS   r   rT   r   r   r4   )*r   r   r   Literal[True]r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   rQ   r   rR   r   rS   r   rT   r   r   zStream[AssistantStreamEvent])*r   r   r   boolr|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   rQ   r   rR   r   rS   r   rT   r   r   "Run | Stream[AssistantStreamEvent])*r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   3Optional[Literal[False]] | Literal[True] | NotGivenr   r   r   r   r   r   rP   r   r   r   r   r   r   r   rQ   r   rR   r   rS   r   rT   r   r   r   *r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   r   zint | NotGivenrQ   r   rR   r   rS   r   rT   r   r   r4   )(r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   rQ   r   rR   r   rS   r   rT   r   r   z-AssistantStreamManager[AssistantEventHandler])*r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   r   r-   rQ   r   rR   r   rS   r   rT   r   r   z.AssistantStreamManager[AssistantEventHandlerT])*r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   r   zAssistantEventHandlerT | NonerQ   r   rR   r   rS   r   rT   r   r   z^AssistantStreamManager[AssistantEventHandler] | AssistantStreamManager[AssistantEventHandlerT]__name__
__module____qualname__r!   rB   rE   rI   rM   r   rc   rn   ru   rz   r	   r   r   r   r   r   rC   rA   r9   r9   ?   su   " " & & , , 2 2 GP09R[ )-$("&;D5
 D5
 .	5

 P5
 &5
 "5
  5
 95
 
5
z )-$("&;D 
 
 & 
 " 
   
 9 
 
 
L 1:R[ )-$("&;D3
3
 .	3

 P3
 &3
 "3
  3
 93
 
3
v )-$("&;D 
 
 & 
 " 
   
 9 
 
 
D 
 2;:C6?098A/8S\6?2;AJKTZcR[,5dm )-$("&;D1  /	
  8 4 . 6 - Q 4 0 ? I X  P!" *#$ b%* &+, "-.  /0 912 
3 B  2;:C6?098A/8S\2;AJKTZcR[,5dm )-$("&;D1  	
 /  8 4 . 6 - Q 0 ? I X  P!" *#$ b%* &+, "-.  /0 912 
&3 B  2;:C6?098A/8S\2;AJKTZcR[,5dm )-$("&;D1  	
 /  8 4 . 6 - Q 0 ? I X  P!" *#$ b%* &+, "-.  /0 912 
,3 B N#nh%?@
 2;:C6?098A/8S\FO2;AJKTZcR[,5dm )-$("&;D18
 8
 /	8

  88
 48
 .8
 68
 -8
 Q8
 D8
 08
 ?8
 I8
 X8
  P!8
" *#8
$ b%8
* &+8
, "-8
.  /8
0 918
2 
,38
 A8
| 2;:C6?098A/8S\2;AJKTZcR[,5dm+4 )-$("&;D15x 5x /	5x
  85x 45x .5x 65x -5x Q5x 05x ?5x I5x X5x P5x  *!5x" b#5x$ )%5x* &+5x, "-5x.  /5x0 915x2 
35xn 
 2;:C6?098A/8S\2;AJKTZcR[,5dm )-$("&;D/  /	
  8 4 . 6 - Q 0 ? I X P  *!" b#( &)* "+,  -. 9/0 
71 8 
 2;:C6?098A/8S\2;AJKTZcR[,5dm )-$("&;D1  /	
  8 4 . 6 - Q 0 ? I X P  *!" b#$ .%* &+, "-.  /0 912 
83 B 2;:C6?098A/8S\2;AJKTZcR[,5dm7; )-$("&;D1@l @l /	@l
  8@l 4@l .@l 6@l -@l Q@l 0@l ?@l I@l X@l P@l  *!@l" b#@l$ 5%@l* &+@l, "-@l.  /@l0 91@l2 
h3@lrC   c                  z   e Zd Zedd       Zedd       Zedd       Zedd       Zeeeddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 ddZ	ddded	 	 	 	 	 	 	 	 	 	 	 d d	Z
eeddded
	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d!dZ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ed	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 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dgddg      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ed	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 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ddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d)d       Zeeeeeeeeeeeeeedddded	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 d*dZy)+r:   c                ,    t        | j                        S r=   )r   r>   r?   s    rA   rB   zAsyncThreads.runs  s    &&rC   c                ,    t        | j                        S r=   )r   r>   r?   s    rA   rE   zAsyncThreads.messages  s    T\\**rC   c                    t        |       S rG   )AsyncThreadsWithRawResponser?   s    rA   rI   zAsyncThreads.with_raw_response  s     +400rC   c                    t        |       S rK   )!AsyncThreadsWithStreamingResponser?   s    rA   rM   z$AsyncThreads.with_streaming_response  s     166rC   NrN   c          
        K   ddi|xs i }| j                  dt        |||dt        j                         d{   t	        ||||      t
               d{   S 7 $7 w)rV   rW   rX   rY   rZ   Nr[   r\   )r`   r   r(   ra   r+   r3   rb   s           rA   rc   zAsyncThreads.create  s     L 'QM<ORQZZ, ( (&4
 %77  )+Q[el    
 
 	

s!   8A#A
A#A!A#!A#r[   c          	        K   |st        d|      ddi|xs i }| j                  d| t        ||||      t               d{   S 7 w)re   rf   rW   rX   rg   r[   rh   Nri   rl   s         rA   rn   zAsyncThreads.retrieve  sv     . WXaWdeff&QM<ORQYY	{#(+Q[el   
 
 	
 
   AAA	Aro   c          
        K   |st        d|      ddi|xs i }| j                  d| t        ||dt        j                         d{   t        ||||      t               d{   S 7 $7 w)	rq   rf   rW   rX   rg   rr   Nr[   r\   )rj   r`   r   r)   rs   r+   r3   rt   s           rA   ru   zAsyncThreads.update  s     F WXaWdeff&QM<ORQZZ	{#, (&4 %77  )+Q[el    
 
 	

s$   A
A5A1
A5,A3-A53A5c          	        K   |st        d|      ddi|xs i }| j                  d| t        ||||      t               d{   S 7 w)rw   rf   rW   rX   rg   r[   rh   Nrx   rl   s         rA   rz   zAsyncThreads.delete+  sv     . WXaWdeff&QM<ORQ\\	{#(+Q[el " " 
 
 	
 
r   r{   r   r   c                  K   ywr   r   r   s                        rA   r   zAsyncThreads.create_and_runM       @ 	   r   c                  K   ywr   r   r   s                        rA   r   zAsyncThreads.create_and_run  r   r   c                  K   ywr   r   r   s                        rA   r   zAsyncThreads.create_and_runQ  r   r   c          
     D  K   ddi|xs i }| j                  dt        i d|d|d|d|d|d	|d
|d|d|	d|
d|d|d|d|d|d|t        j                         d {   t	        ||||      t
        |	xs dt        t                  d {   S 7 57 wr   )r`   r   r*   r   r+   r4   r'   r6   r   s                        rA   r   zAsyncThreads.create_and_run  sL    6 'QM<ORQZZ,"L"L ,-B ():	
  U *+> & f "; f "; %n U U  *+>!$ -EE' * )+Q[el ?U"#789   
 
 	

s$   A$B &B
'0B BB B r   c                  K   | j                  |||||||||	d|
|||||||||       d{   }| j                  j                  |j                  |j                  |||||       d{   S 7 A7 w)r   Fr   Nr   r   s                         rA   r   z AsyncThreads.create_and_run_poll  s     > ''%%"7/ 3+#)# 3'#!) ( 
 
, YY^^FFCMM=+z7Td
 
 	
-
,
s!   )A1A-<A1(A/)A1/A1c                    yr   r   r   s                       rA   r   z"AsyncThreads.create_and_run_streamG  r   rC   c                    yr   r   r   s                        rA   r   z"AsyncThreads.create_and_run_streamd  r   rC   r   c          
     J   dd|rdndd|xs i }| j                  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   )
r`   r   r*   r   r+   r4   r'   r6   r1   r/   )r@   r   r|   r}   r~   rO   r   r   r   r   r   r   rP   r   r   r   r   rQ   rR   rS   rT   requests                         rA   r   z"AsyncThreads.create_and_run_stream  sU   > +)H:GW
 "	
 ** "L"L ,-B ():	
  U *+> & "; "; d f U %n *+>  U!$ -EE'* )+Q[el "#789  
< +7-BoSmSopprC   )r   r   )r   r   )r   r   )r   r   r   r   r   r   r   )*r   r   r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   rQ   r   rR   r   rS   r   rT   r   r   z!AsyncStream[AssistantStreamEvent])*r   r   r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   rQ   r   rR   r   rS   r   rT   r   r   'Run | AsyncStream[AssistantStreamEvent])*r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   rQ   r   rR   r   rS   r   rT   r   r   r   r   )(r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   rQ   r   rR   r   rS   r   rT   r   r   z7AsyncAssistantStreamManager[AsyncAssistantEventHandler])*r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   r   r0   rQ   r   rR   r   rS   r   rT   r   r   z8AsyncAssistantStreamManager[AsyncAssistantEventHandlerT])*r   r   r|   r   r}   r   r~   r   rO   r   r   r   r   r   r   r   r   r   r   r   r   r   rP   r   r   r   r   r   r   r   r   z"AsyncAssistantEventHandlerT | NonerQ   r   rR   r   rS   r   rT   r   r   zrAsyncAssistantStreamManager[AsyncAssistantEventHandler] | AsyncAssistantStreamManager[AsyncAssistantEventHandlerT]r   r   rC   rA   r:   r:     sa   ' ' + + 1 1 7 7 GP09R[ )-$("&;D5
 D5
 .	5

 P5
 &5
 "5
  5
 95
 
5
z )-$("&;D 
 
 & 
 " 
   
 9 
 
 
L 1:R[ )-$("&;D3
3
 .	3

 P3
 &3
 "3
  3
 93
 
3
v )-$("&;D 
 
 & 
 " 
   
 9 
 
 
D 
 2;:C6?098A/8S\6?2;AJKTZcR[,5dm )-$("&;D1  /	
  8 4 . 6 - Q 4 0 ? I X  P!" *#$ b%* &+, "-.  /0 912 
3 B  2;:C6?098A/8S\2;AJKTZcR[,5dm )-$("&;D1  	
 /  8 4 . 6 - Q 0 ? I X  P!" *#$ b%* &+, "-.  /0 912 
+3 B  2;:C6?098A/8S\2;AJKTZcR[,5dm )-$("&;D1  	
 /  8 4 . 6 - Q 0 ? I X  P!" *#$ b%* &+, "-.  /0 912 
13 B N#nh%?@
 2;:C6?098A/8S\FO2;AJKTZcR[,5dm )-$("&;D18
 8
 /	8

  88
 48
 .8
 68
 -8
 Q8
 D8
 08
 ?8
 I8
 X8
  P!8
" *#8
$ b%8
* &+8
, "-8
.  /8
0 918
2 
138
 A8
| 2;:C6?098A/8S\2;AJKTZcR[,5dm+4 )-$("&;D17
 7
 /	7

  87
 47
 .7
 67
 -7
 Q7
 07
 ?7
 I7
 X7
 P7
  *!7
" b#7
$ )%7
* &+7
, "-7
.  /7
0 917
2 
37
r 
 2;:C6?098A/8S\2;AJKTZcR[,5dm )-$("&;D/  /	
  8 4 . 6 - Q 0 ? I X P  *!" b#( &)* "+,  -. 9/0 
A1 8 
 2;:C6?098A/8S\2;AJKTZcR[,5dm )-$("&;D1  /	
  8 4 . 6 - Q 0 ? I X P  *!" b#$ 3%* &+, "-.  /0 912 
B3 B 2;:C6?098A/8S\2;AJKTZcR[,5dm<@ )-$("&;D1Bq Bq /	Bq
  8Bq 4Bq .Bq 6Bq -Bq QBq 0Bq ?Bq IBq XBq PBq  *!Bq" b#Bq$ :%Bq* &+Bq, "-Bq.  /Bq0 91Bq4	C5BqrC   c                  8    e Zd ZddZedd       Zedd       Zy)rH   c                z   || _         t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j
                        | _        t        j                  |j                        | _        t        j                  |j                        | _        y r=   )_threadsr   to_raw_response_wrapperrc   rn   ru   rz   r   r@   threadss     rA   __init__zThreadsWithRawResponse.__init__  s    &>>NN
 )@@
 '>>NN
 '>>NN
 /FF""
rC   c                @    t        | j                  j                        S r=   )r   r   rB   r?   s    rA   rB   zThreadsWithRawResponse.runs  s    "4==#5#566rC   c                @    t        | j                  j                        S r=   )r   r   rE   r?   s    rA   rE   zThreadsWithRawResponse.messages  s    &t}}'='=>>rC   Nr   r9   r   None)r   r   )r   r   r   r   r   r   r!   rB   rE   r   rC   rA   rH   rH     s/    
& 7 7 ? ?rC   rH   c                  8    e Zd ZddZedd       Zedd       Zy)r   c                z   || _         t        j                  |j                        | _        t        j                  |j                        | _        t        j                  |j
                        | _        t        j                  |j                        | _        t        j                  |j                        | _        y r=   )r   r   async_to_raw_response_wrapperrc   rn   ru   rz   r   r   s     rA   r   z$AsyncThreadsWithRawResponse.__init__  s    &DDNN
 )FF
 'DDNN
 'DDNN
 /LL""
rC   c                @    t        | j                  j                        S r=   )r   r   rB   r?   s    rA   rB   z AsyncThreadsWithRawResponse.runs  s    '(:(:;;rC   c                @    t        | j                  j                        S r=   )r   r   rE   r?   s    rA   rE   z$AsyncThreadsWithRawResponse.messages  s    +DMM,B,BCCrC   Nr   r:   r   r   )r   r   )r   r   r   r   rC   rA   r   r     s1    
& < < D DrC   r   c                  8    e Zd ZddZedd       Zedd       Zy)rL   c                   || _         t        |j                        | _        t        |j                        | _        t        |j                        | _        t        |j
                        | _        t        |j                        | _        y r=   )r   r$   rc   rn   ru   rz   r   r   s     rA   r   z%ThreadsWithStreamingResponse.__init__  su    2NN
 5
 3NN
 3NN
 ;""
rC   c                @    t        | j                  j                        S r=   )r   r   rB   r?   s    rA   rB   z!ThreadsWithStreamingResponse.runs  s    (););<<rC   c                @    t        | j                  j                        S r=   )r   r   rE   r?   s    rA   rE   z%ThreadsWithStreamingResponse.messages  s    ,T]]-C-CDDrC   Nr   )r   r   )r   r   r   r   rC   rA   rL   rL     s1    
& = = E ErC   rL   c                  8    e Zd ZddZedd       Zedd       Zy)r   c                   || _         t        |j                        | _        t        |j                        | _        t        |j                        | _        t        |j
                        | _        t        |j                        | _        y r=   )r   r%   rc   rn   ru   rz   r   r   s     rA   r   z*AsyncThreadsWithStreamingResponse.__init__  sv    8NN
 ;
 9NN
 9NN
 A""
rC   c                @    t        | j                  j                        S r=   )r    r   rB   r?   s    rA   rB   z&AsyncThreadsWithStreamingResponse.runs2  s    -dmm.@.@AArC   c                @    t        | j                  j                        S r=   )r   r   rE   r?   s    rA   rE   z*AsyncThreadsWithStreamingResponse.messages6  s    1$--2H2HIIrC   Nr   )r   r    )r   r   r   r   rC   rA   r   r     s3    
& B B J JrC   r   )S
__future__r   typingr   r   r   	functoolsr   typing_extensionsr   r	   httpx r   rE   r   r   r   r   r   r   _typesr   r   r   r   r   _utilsr   r   r   	runs.runsr   r   r   r   r   r    _compatr!   	_resourcer"   r#   	_responser$   r%   
_streamingr&   r'   
types.betar(   r)   r*   _base_clientr+   lib.streamingr,   r-   r.   r/   r0   r1   types.chat_modelr2   types.beta.threadr3   types.beta.threads.runr4   types.beta.thread_deletedr5   !types.beta.assistant_stream_eventr6   -types.beta.assistant_tool_choice_option_paramr7   1types.beta.assistant_response_format_option_paramr8   __all__r9   r:   rH   r   rL   r   r   rC   rA   <module>r      s    # , ,  /  !  A @ 
  ( ; Z . 
 2  + ( * 7 F \ dn
%lo lDCq# CqL? ?:D D:E E:J JrC   