
    gb                    .   d dl Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 dd	lmZ dd
lmZ ddlmZ ddlmZ ddlmZ ddlmZ d dlZddlmZ d dlZddlmZ ddlmZ ddlm Z  ddl!m"Z" ddl#m$Z$ ddl%m&Z& ddl'm(Z( ddl)m*Z* ddl+m,Z, ddl-m.Z. ddl/m0Z0 ddl1m2Z2 d dl3m4Z4 ddl5m6Z6 ddl7m8Z8 ddl9m:Z: dd l;m<Z< dd!l=m>Z> dd"l?m@Z@ dd#lAmBZB dd$lCmDZD dd%lEmFZF dd&lGmHZH dd'lmIZI  e j                  e j                  d(      ZL G d) d*      ZM G d+ d,      ZNy)-    N   )SyncClientWrapper)ChatMessages)ToolV2   ) V2ChatStreamRequestDocumentsItem)CitationOptions)ResponseFormatV2)V2ChatStreamRequestSafetyMode)V2ChatStreamRequestToolChoice)RequestOptions)StreamedChatResponseV2)'convert_and_respect_annotation_metadata)construct_type)BadRequestError)UnauthorizedError)ForbiddenError)NotFoundError)UnprocessableEntityError)TooManyRequestsError)InvalidTokenError)ClientClosedRequestError)InternalServerError)NotImplementedError)ServiceUnavailableError)GatewayTimeoutError)JSONDecodeError)ApiError)V2ChatRequestDocumentsItem)V2ChatRequestSafetyMode)V2ChatRequestToolChoice)ChatResponse)EmbedInputType)EmbeddingType)V2EmbedRequestTruncate)EmbedByTypeResponse)V2RerankResponse)AsyncClientWrapper.c            ,          e Zd ZdefdZeeeeeeeeeeeeeeeeedddededej                  ej                  e      dej                  e   d	ej                  ej                  e      d
ej                  e   dej                  e   dej                  e   dej                  e   dej                  ej                  e      dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej*                  e   f*dZeeeeeeeeeeeeeeeeedddededej                  ej                  e      dej                  e   d	ej                  ej                  e      d
ej                  e   dej                  e   dej                  e   dej                  e   dej                  ej                  e      dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   def*dZeeedddededej                  e   dej                  ej                  e      d ej                  ej                  e      d!ej                  e   dej                  e   de fd"Z!eeedd#ded$ed	ej                  e   d%ej                  e   d&ej                  e   d'ej                  e   dej                  e   de"fd(Z#y))V2Clientclient_wrapperc                    || _         y N_client_wrapperselfr+   s     E/var/www/openai/venv/lib/python3.12/site-packages/cohere/v2/client.py__init__zV2Client.__init__0   
    -    Ntoolsstrict_tools	documentscitation_optionsresponse_formatsafety_mode
max_tokensstop_sequencestemperatureseedfrequency_penaltypresence_penaltykpreturn_promptlogprobstool_choicerequest_optionsmodelmessagesr7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   returnc             #   Z  K   | j                   j                  j                  ddi d|dt        |t        d      dt        |t
        j                  t           d      d|d	t        |t
        j                  t           d      d
t        |t        d      dt        |t        d      d|d|	d|
d|d|d|d|d|d|d|||ddddi|t              5 }	 d|j                  cxk  rdk  rn n}t        j                  |      }|j                         D ]K  }	 t        j                   t"        t%        t"        t'        j(                  |j*                                     M 	 ddd       y|j-                          |j                  dk(  rvt/        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d k(  rvt5        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d!k(  rvt7        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d"k(  rvt9        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d#k(  rvt;        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d$k(  rvt=        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d%k(  rvt?        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d&k(  rvtA        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d'k(  rvtC        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d(k(  rvtE        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d)k(  rvtG        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d*k(  rvtI        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j'                         }tM        |j                  |+      #  Y xY w# tJ        $ r" tM        |j                  |jN                  +      w xY w# 1 sw Y   yxY ww),a  
        Generates a text response to a user message. To learn how to use the Chat API and RAG follow our [Text Generation guides](https://docs.cohere.com/v2/docs/chat-api).

        Follow the [Migration Guide](https://docs.cohere.com/v2/docs/migrating-v1-to-v2) for instructions on moving from API v1 to API v2.

        Parameters
        ----------
        model : str
            The name of a compatible [Cohere model](https://docs.cohere.com/v2/docs/models) (such as command-r or command-r-plus) or the ID of a [fine-tuned](https://docs.cohere.com/v2/docs/chat-fine-tuning) model.

        messages : ChatMessages

        tools : typing.Optional[typing.Sequence[ToolV2]]
            A list of available tools (functions) that the model may suggest invoking before producing a text response.

            When `tools` is passed (without `tool_results`), the `text` content in the response will be empty and the `tool_calls` field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the `tool_calls` array will be empty.


        strict_tools : typing.Optional[bool]
            When set to `true`, tool calls in the Assistant message will be forced to follow the tool definition strictly. Learn more in the [Structured Outputs (Tools) guide](https://docs.cohere.com/docs/structured-outputs-json#structured-outputs-tools).

            **Note**: The first few requests with a new set of tools will take longer to process.


        documents : typing.Optional[typing.Sequence[V2ChatStreamRequestDocumentsItem]]
            A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata.


        citation_options : typing.Optional[CitationOptions]

        response_format : typing.Optional[ResponseFormatV2]

        safety_mode : typing.Optional[V2ChatStreamRequestSafetyMode]
            Used to select the [safety instruction](https://docs.cohere.com/v2/docs/safety-modes) inserted into the prompt. Defaults to `CONTEXTUAL`.
            When `OFF` is specified, the safety instruction will be omitted.

            Safety modes are not yet configurable in combination with `tools`, `tool_results` and `documents` parameters.

            **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/v2/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/v2/docs/command-r-plus#august-2024-release) and newer.

            **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes.


        max_tokens : typing.Optional[int]
            The maximum number of tokens the model will generate as part of the response.

            **Note**: Setting a low value may result in incomplete generations.


        stop_sequences : typing.Optional[typing.Sequence[str]]
            A list of up to 5 strings that the model will use to stop generation. If the model generates a string that matches any of the strings in the list, it will stop generating tokens and return the generated text up to that point not including the stop sequence.


        temperature : typing.Optional[float]
            Defaults to `0.3`.

            A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations, and higher temperatures mean more random generations.

            Randomness can be further maximized by increasing the  value of the `p` parameter.


        seed : typing.Optional[int]
            If specified, the backend will make a best effort to sample tokens
            deterministically, such that repeated requests with the same
            seed and parameters should return the same result. However,
            determinism cannot be totally guaranteed.


        frequency_penalty : typing.Optional[float]
            Defaults to `0.0`, min value of `0.0`, max value of `1.0`.
            Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation.


        presence_penalty : typing.Optional[float]
            Defaults to `0.0`, min value of `0.0`, max value of `1.0`.
            Used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies.


        k : typing.Optional[float]
            Ensures that only the top `k` most likely tokens are considered for generation at each step. When `k` is set to `0`, k-sampling is disabled.
            Defaults to `0`, min value of `0`, max value of `500`.


        p : typing.Optional[float]
            Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`.
            Defaults to `0.75`. min value of `0.01`, max value of `0.99`.


        return_prompt : typing.Optional[bool]
            Whether to return the prompt in the response.

        logprobs : typing.Optional[bool]
            Defaults to `false`. When set to `true`, the log probabilities of the generated tokens will be included in the response.


        tool_choice : typing.Optional[V2ChatStreamRequestToolChoice]
            Used to control whether or not the model will be forced to use a tool when answering. When `REQUIRED` is specified, the model will be forced to use at least one of the user-defined tools, and the `tools` parameter must be passed in the request.
            When `NONE` is specified, the model will be forced **not** to use one of the specified tools, and give a direct response.
            If tool_choice isn't specified, then the model is free to choose whether to use the specified tools or not.

            **Note**: This parameter is only compatible with models [Command-r7b](https://docs.cohere.com/v2/docs/command-r7b) and newer.

            **Note**: The same functionality can be achieved in `/v1/chat` using the `force_single_step` parameter. If `force_single_step=true`, this is equivalent to specifying `REQUIRED`. While if `force_single_step=true` and `tool_results` are passed, this is equivalent to specifying `NONE`.


        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.Iterator[StreamedChatResponseV2]


        Examples
        --------
        from cohere import Client, ToolChatMessageV2

        client = Client(
            client_name="YOUR_CLIENT_NAME",
            token="YOUR_TOKEN",
        )
        response = client.v2.chat_stream(
            model="model",
            messages=[
                ToolChatMessageV2(
                    tool_call_id="messages",
                    content="messages",
                )
            ],
        )
        for chunk in response:
            yield chunk
        v2/chatPOSTrI   rJ   writeobject_
annotation	directionr7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   TrF   rG   streamcontent-typeapplication/jsonmethodjsonheadersrH   omit   ,  type_rQ   N                        status_codebody)(r/   httpx_clientrU   r   r   typingSequencer   r   r	   r
   OMITrn   	httpx_sseEventSourceiter_ssecastr   r   rZ   loadsdatareadr   OptionalAnyr   r   r   r   r   r   r   r   r   r   r   r   r   textr1   rI   rJ   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   	_response_event_source_sse_response_jsons                            r2   chat_streamzV2Client.chat_stream3   s    z !!..55C$
 @!foof.EQX  D%&//Bb2cov #$K,T[% "#J+8HT[$$ {%& j'( !.)* {+, -. $%6/0 #$412 Q34 Q56  78 %*=B  2 ,O 6 (
P JW)//5#5$-$9$9)$DM - 6 6 8	!"(++ 6 .*@,0JJtyy,A!"#  !9 o(
 (
p  ((C/)"OOFJJ7*&,oofjj&A(1(8  ((C/+"OOFJJ7*&,oofjj&A(1(8  ((C/("OOFJJ7*&,oofjj&A(1(8  ((C/'"OOFJJ7*&,oofjj&A(1(8  ((C/2"OOFJJ7*&,oofjj&A(1(8  ((C/."OOFJJ7*&,oofjj&A(1(8  ((C/+"OOFJJ7*&,oofjj&A(1(8  ((C/2"OOFJJ7*&,oofjj&A(1(8  ((C/-"OOFJJ7*&,oofjj&A(1(8  ((C/-"OOFJJ7*&,oofjj&A(1(8  ((C/1"OOFJJ7*&,oofjj&A(1(8  ((C/-"OOFJJ7*&,oofjj&A(1(8  "+!1 y'<'<>RR! x # W9+@+@y~~VVWe(
 (
sW   C`+`!A _1"A_)*_1-	`+6Y_1`)_.+_11+```($`+c                |   | j                   j                  j                  ddi d|dt        |t        d      dt        |t
        j                  t           d      d|d	t        |t
        j                  t           d      d
t        |t        d      dt        |t        d      d|d|	d|
d|d|d|d|d|d|d|||ddddi|t              }	 d|j                  cxk  rdk  r:n n7t        j                  t        t        t        |j!                                     S |j                  dk(  rvt#        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  dk(  rvt)        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d k(  rvt+        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d!k(  rvt-        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d"k(  rvt/        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d#k(  rvt1        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d$k(  rvt3        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d%k(  rvt5        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d&k(  rvt7        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d'k(  rvt9        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d(k(  rvt;        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d)k(  rvt=        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j!                         }tA        |j                  |*      # t>        $ r" tA        |j                  |jB                  *      w xY w)+a  
        Generates a text response to a user message and streams it down, token by token. To learn how to use the Chat API with streaming follow our [Text Generation guides](https://docs.cohere.com/v2/docs/chat-api).

        Follow the [Migration Guide](https://docs.cohere.com/v2/docs/migrating-v1-to-v2) for instructions on moving from API v1 to API v2.

        Parameters
        ----------
        model : str
            The name of a compatible [Cohere model](https://docs.cohere.com/v2/docs/models) (such as command-r or command-r-plus) or the ID of a [fine-tuned](https://docs.cohere.com/v2/docs/chat-fine-tuning) model.

        messages : ChatMessages

        tools : typing.Optional[typing.Sequence[ToolV2]]
            A list of available tools (functions) that the model may suggest invoking before producing a text response.

            When `tools` is passed (without `tool_results`), the `text` content in the response will be empty and the `tool_calls` field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the `tool_calls` array will be empty.


        strict_tools : typing.Optional[bool]
            When set to `true`, tool calls in the Assistant message will be forced to follow the tool definition strictly. Learn more in the [Structured Outputs (Tools) guide](https://docs.cohere.com/docs/structured-outputs-json#structured-outputs-tools).

            **Note**: The first few requests with a new set of tools will take longer to process.


        documents : typing.Optional[typing.Sequence[V2ChatRequestDocumentsItem]]
            A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata.


        citation_options : typing.Optional[CitationOptions]

        response_format : typing.Optional[ResponseFormatV2]

        safety_mode : typing.Optional[V2ChatRequestSafetyMode]
            Used to select the [safety instruction](https://docs.cohere.com/v2/docs/safety-modes) inserted into the prompt. Defaults to `CONTEXTUAL`.
            When `OFF` is specified, the safety instruction will be omitted.

            Safety modes are not yet configurable in combination with `tools`, `tool_results` and `documents` parameters.

            **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/v2/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/v2/docs/command-r-plus#august-2024-release) and newer.

            **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes.


        max_tokens : typing.Optional[int]
            The maximum number of tokens the model will generate as part of the response.

            **Note**: Setting a low value may result in incomplete generations.


        stop_sequences : typing.Optional[typing.Sequence[str]]
            A list of up to 5 strings that the model will use to stop generation. If the model generates a string that matches any of the strings in the list, it will stop generating tokens and return the generated text up to that point not including the stop sequence.


        temperature : typing.Optional[float]
            Defaults to `0.3`.

            A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations, and higher temperatures mean more random generations.

            Randomness can be further maximized by increasing the  value of the `p` parameter.


        seed : typing.Optional[int]
            If specified, the backend will make a best effort to sample tokens
            deterministically, such that repeated requests with the same
            seed and parameters should return the same result. However,
            determinism cannot be totally guaranteed.


        frequency_penalty : typing.Optional[float]
            Defaults to `0.0`, min value of `0.0`, max value of `1.0`.
            Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation.


        presence_penalty : typing.Optional[float]
            Defaults to `0.0`, min value of `0.0`, max value of `1.0`.
            Used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies.


        k : typing.Optional[float]
            Ensures that only the top `k` most likely tokens are considered for generation at each step. When `k` is set to `0`, k-sampling is disabled.
            Defaults to `0`, min value of `0`, max value of `500`.


        p : typing.Optional[float]
            Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`.
            Defaults to `0.75`. min value of `0.01`, max value of `0.99`.


        return_prompt : typing.Optional[bool]
            Whether to return the prompt in the response.

        logprobs : typing.Optional[bool]
            Defaults to `false`. When set to `true`, the log probabilities of the generated tokens will be included in the response.


        tool_choice : typing.Optional[V2ChatRequestToolChoice]
            Used to control whether or not the model will be forced to use a tool when answering. When `REQUIRED` is specified, the model will be forced to use at least one of the user-defined tools, and the `tools` parameter must be passed in the request.
            When `NONE` is specified, the model will be forced **not** to use one of the specified tools, and give a direct response.
            If tool_choice isn't specified, then the model is free to choose whether to use the specified tools or not.

            **Note**: This parameter is only compatible with models [Command-r7b](https://docs.cohere.com/v2/docs/command-r7b) and newer.

            **Note**: The same functionality can be achieved in `/v1/chat` using the `force_single_step` parameter. If `force_single_step=true`, this is equivalent to specifying `REQUIRED`. While if `force_single_step=true` and `tool_results` are passed, this is equivalent to specifying `NONE`.


        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ChatResponse


        Examples
        --------
        from cohere import Client, ToolChatMessageV2

        client = Client(
            client_name="YOUR_CLIENT_NAME",
            token="YOUR_TOKEN",
        )
        client.v2.chat(
            model="model",
            messages=[
                ToolChatMessageV2(
                    tool_call_id="messages",
                    content="messages",
                )
            ],
        )
        rM   rN   rI   rJ   rO   rP   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   FrT   rV   rW   rX   r]   r^   r_   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   "r/   rp   requestr   r   rq   rr   r   r   r	   r
   rs   rn   rw   r"   r   rZ   r   r{   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   r1   rI   rJ   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   r   r   s                          r2   chatzV2Client.chat  sP   v ((55==C$
 @!foof.EQX  D%&//B\2]ip #$K,T[% "#J+8HT[$$ {%& j'( !.)* {+, -. $%6/0 #$412 Q34 Q56  78 %*=B  2 ,O > (
	RC	Si++1c1{{ "* ) 0  $$+%KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+$KK

3&"(//&**"=$-NN$4  $$+#KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+*KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+-KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  '^^-N 9#8#8~NN  	Sy'<'<9>>RR	Ss   A^ -Y^ +^;textsimagestruncaterH   
input_typeembedding_typesr   r   r   c                4   | j                   j                  j                  dd||||||dddi|t              }	 d|j                  cxk  rdk  r:n n7t        j                  t        t        t        |j                         	            S |j                  d
k(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt!        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt#        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt%        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt'        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt)        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt+        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt-        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt/        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                         }	t3        |j                  |	      # t0        $ r" t3        |j                  |j4                        w xY w)a  
        This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents.

        Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.

        If you want to learn more how to use the embedding model, have a look at the [Semantic Search Guide](https://docs.cohere.com/docs/semantic-search).

        Parameters
        ----------
        model : str
            Defaults to embed-english-v2.0

            The identifier of the model. Smaller "light" models are faster, while larger models will perform better. [Custom models](https://docs.cohere.com/docs/training-custom-models) can also be supplied with their full ID.

            Available models and corresponding embedding dimensions:

            * `embed-english-v3.0`  1024
            * `embed-multilingual-v3.0`  1024
            * `embed-english-light-v3.0`  384
            * `embed-multilingual-light-v3.0`  384

            * `embed-english-v2.0`  4096
            * `embed-english-light-v2.0`  1024
            * `embed-multilingual-v2.0`  768

        input_type : EmbedInputType

        embedding_types : typing.Sequence[EmbeddingType]
            Specifies the types of embeddings you want to get back. Can be one or more of the following types.

            * `"float"`: Use this when you want to get back the default float embeddings. Valid for all models.
            * `"int8"`: Use this when you want to get back signed int8 embeddings. Valid for only v3 models.
            * `"uint8"`: Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models.
            * `"binary"`: Use this when you want to get back signed binary embeddings. Valid for only v3 models.
            * `"ubinary"`: Use this when you want to get back unsigned binary embeddings. Valid for only v3 models.

        texts : typing.Optional[typing.Sequence[str]]
            An array of strings for the model to embed. Maximum number of texts per call is `96`. We recommend reducing the length of each text to be under `512` tokens for optimal quality.

        images : typing.Optional[typing.Sequence[str]]
            An array of image data URIs for the model to embed. Maximum number of images per call is `1`.

            The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg` or `image/png` format and has a maximum size of 5MB.

        truncate : typing.Optional[V2EmbedRequestTruncate]
            One of `NONE|START|END` to specify how the API will handle inputs longer than the maximum token length.

            Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model.

            If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        EmbedByTypeResponse
            OK

        Examples
        --------
        from cohere import Client

        client = Client(
            client_name="YOUR_CLIENT_NAME",
            token="YOUR_TOKEN",
        )
        client.v2.embed(
            model="model",
            input_type="search_document",
            embedding_types=["float"],
        )
        v2/embedrN   r   r   rI   r   r   r   rV   rW   rX   r]   r^   r_   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r/   rp   r   rs   rn   rq   rw   r&   r   rZ   r   r{   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   
r1   rI   r   r   r   r   r   rH   r   r   s
             r2   embedzV2Client.embed  s,   h ((55== (#2$  2 , > 
	"C	Si++1c1{{'"1 ) 0  $$+%KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+$KK

3&"(//&**"=$-NN$4  $$+#KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+*KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+-KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  '^^-N 9#8#8~NN  	Sy'<'<9>>RR	S   A[, 	Y[, ,+\top_nreturn_documentsmax_tokens_per_docrH   queryr   r   r   c                4   | j                   j                  j                  dd||||||dddi|t              }	 d|j                  cxk  rdk  r:n n7t        j                  t        t        t        |j                         	            S |j                  d
k(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt!        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt#        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt%        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt'        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt)        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt+        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt-        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                  dk(  rvt/        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         	                  |j                         }	t3        |j                  |	      # t0        $ r" t3        |j                  |j4                        w xY w)a  
        This endpoint takes in a query and a list of texts and produces an ordered array with each text assigned a relevance score.

        Parameters
        ----------
        model : str
            The identifier of the model to use, eg `rerank-v3.5`.

        query : str
            The search query

        documents : typing.Sequence[str]
            A list of texts that will be compared to the `query`.
            For optimal performance we recommend against sending more than 1,000 documents in a single request.

            **Note**: long documents will automatically be truncated to the value of `max_tokens_per_doc`.

            **Note**: structured data should be formatted as YAML strings for best performance.

        top_n : typing.Optional[int]
            Limits the number of returned rerank results to the specified value. If not passed, all the rerank results will be returned.

        return_documents : typing.Optional[bool]
            - If false, returns results without the doc text - the api will return a list of {index, relevance score} where index is inferred from the list passed into the request.
            - If true, returns results with the doc text passed in - the api will return an ordered list of {index, text, relevance score} where index + text refers to the list passed into the request.

        max_tokens_per_doc : typing.Optional[int]
            Defaults to `4096`. Long documents will be automatically truncated to the specified number of tokens.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        V2RerankResponse
            OK

        Examples
        --------
        from cohere import Client

        client = Client(
            client_name="YOUR_CLIENT_NAME",
            token="YOUR_TOKEN",
        )
        client.v2.rerank(
            model="model",
            query="query",
            documents=["documents"],
        )
        	v2/rerankrN   rI   r   r9   r   r   r   rV   rW   rX   r]   r^   r_   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r/   rp   r   rs   rn   rq   rw   r'   r   rZ   r   r{   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   
r1   rI   r   r9   r   r   r   rH   r   r   s
             r2   rerankzV2Client.rerank  s,   | ((55==&$4&8  2 , > 
	"C	Si++1c1{{$". ) 0  $$+%KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+$KK

3&"(//&**"=$-NN$4  $$+#KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+*KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+-KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  '^^-N 9#8#8~NN  	Sy'<'<9>>RR	Sr   )$__name__
__module____qualname__r   r3   rs   strr   rq   r{   rr   r   boolr   r	   r
   r   intfloatr   r   Iteratorr   r   r   r    r!   r"   r   r#   r$   r%   r&   r   r'   r    r5   r2   r*   r*   /   sk   .*; . ;?.2X\=A=AFJ+/@D.2%)4837$($(/3*.FJ;?-QS QS 	QS
 vv67QS ood+QS ??6??3S#TUQS !///:QS  )9:QS __%BCQS OOC(QS (<=QS __U+QS ooc"QS "??51QS  !//%0!QS" ??5!#QS$ ??5!%QS& t,'QS( //$')QS* __%BC+QS,  8-QS. 
/	0/QSp
 ;?.2RV=A=A@D+/@D.2%)4837$($(/3*.@D;?-HO HO 	HO
 vv67HO ood+HO ??6??3M#NOHO !///:HO  )9:HO __%<=HO OOC(HO (<=HO __U+HO ooc"HO "??51HO  !//%0!HO" ??5!#HO$ ??5!%HO& t,'HO( //$')HO* __%<=+HO,  8-HO. 
/HO`
 8<8<<@;?iO iO #	iO
  7iO vs34iO  45iO //"89iO  8iO 
iOb '+2637;?SO SO 	SO
 ??3'SO s#SO !//$/SO #OOC0SO  8SO 
SOr5   r*   c            ,          e Zd ZdefdZeeeeeeeeeeeeeeeeedddededej                  ej                  e      dej                  e   d	ej                  ej                  e      d
ej                  e   dej                  e   dej                  e   dej                  e   dej                  ej                  e      dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej*                  e   f*dZeeeeeeeeeeeeeeeeedddededej                  ej                  e      dej                  e   d	ej                  ej                  e      d
ej                  e   dej                  e   dej                  e   dej                  e   dej                  ej                  e      dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   dej                  e   def*dZeeedddededej                  e   dej                  ej                  e      d ej                  ej                  e      d!ej                  e   dej                  e   de fd"Z!eeedd#ded$ed	ej                  e   d%ej                  e   d&ej                  e   d'ej                  e   dej                  e   de"fd(Z#y))AsyncV2Clientr+   c                    || _         y r-   r.   r0   s     r2   r3   zAsyncV2Client.__init__  r4   r5   Nr6   rI   rJ   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rK   c                 K   | j                   j                  j                  ddi d|dt        |t        d      dt        |t
        j                  t           d      d|d	t        |t
        j                  t           d      d
t        |t        d      dt        |t        d      d|d|	d|
d|d|d|d|d|d|d|||ddddi|t              4 d{   }	 d|j                  cxk  rdk  r|n nyt        j                  |      }|j                         2 3 d{   }	 t        j                   t"        t%        t"        t'        j(                  |j*                                     T|j-                          d{    |j                  dk(  rvt/        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d k(  rvt5        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d!k(  rvt7        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d"k(  rvt9        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d#k(  rvt;        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d$k(  rvt=        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d%k(  rvt?        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d&k(  rvtA        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d'k(  rvtC        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d(k(  rvtE        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d)k(  rvtG        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j                  d*k(  rvtI        t        j                   t
        j0                  t
        j2                     t%        t
        j0                  t
        j2                     |j'                                           |j'                         }tM        |j                  |+      7 7 #  Y xY w6 	 ddd      d{  7   y7 # tJ        $ r" tM        |j                  |jN                  +      w xY w# 1 d{  7  sw Y   yxY ww),a  
        Generates a text response to a user message. To learn how to use the Chat API and RAG follow our [Text Generation guides](https://docs.cohere.com/v2/docs/chat-api).

        Follow the [Migration Guide](https://docs.cohere.com/v2/docs/migrating-v1-to-v2) for instructions on moving from API v1 to API v2.

        Parameters
        ----------
        model : str
            The name of a compatible [Cohere model](https://docs.cohere.com/v2/docs/models) (such as command-r or command-r-plus) or the ID of a [fine-tuned](https://docs.cohere.com/v2/docs/chat-fine-tuning) model.

        messages : ChatMessages

        tools : typing.Optional[typing.Sequence[ToolV2]]
            A list of available tools (functions) that the model may suggest invoking before producing a text response.

            When `tools` is passed (without `tool_results`), the `text` content in the response will be empty and the `tool_calls` field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the `tool_calls` array will be empty.


        strict_tools : typing.Optional[bool]
            When set to `true`, tool calls in the Assistant message will be forced to follow the tool definition strictly. Learn more in the [Structured Outputs (Tools) guide](https://docs.cohere.com/docs/structured-outputs-json#structured-outputs-tools).

            **Note**: The first few requests with a new set of tools will take longer to process.


        documents : typing.Optional[typing.Sequence[V2ChatStreamRequestDocumentsItem]]
            A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata.


        citation_options : typing.Optional[CitationOptions]

        response_format : typing.Optional[ResponseFormatV2]

        safety_mode : typing.Optional[V2ChatStreamRequestSafetyMode]
            Used to select the [safety instruction](https://docs.cohere.com/v2/docs/safety-modes) inserted into the prompt. Defaults to `CONTEXTUAL`.
            When `OFF` is specified, the safety instruction will be omitted.

            Safety modes are not yet configurable in combination with `tools`, `tool_results` and `documents` parameters.

            **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/v2/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/v2/docs/command-r-plus#august-2024-release) and newer.

            **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes.


        max_tokens : typing.Optional[int]
            The maximum number of tokens the model will generate as part of the response.

            **Note**: Setting a low value may result in incomplete generations.


        stop_sequences : typing.Optional[typing.Sequence[str]]
            A list of up to 5 strings that the model will use to stop generation. If the model generates a string that matches any of the strings in the list, it will stop generating tokens and return the generated text up to that point not including the stop sequence.


        temperature : typing.Optional[float]
            Defaults to `0.3`.

            A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations, and higher temperatures mean more random generations.

            Randomness can be further maximized by increasing the  value of the `p` parameter.


        seed : typing.Optional[int]
            If specified, the backend will make a best effort to sample tokens
            deterministically, such that repeated requests with the same
            seed and parameters should return the same result. However,
            determinism cannot be totally guaranteed.


        frequency_penalty : typing.Optional[float]
            Defaults to `0.0`, min value of `0.0`, max value of `1.0`.
            Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation.


        presence_penalty : typing.Optional[float]
            Defaults to `0.0`, min value of `0.0`, max value of `1.0`.
            Used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies.


        k : typing.Optional[float]
            Ensures that only the top `k` most likely tokens are considered for generation at each step. When `k` is set to `0`, k-sampling is disabled.
            Defaults to `0`, min value of `0`, max value of `500`.


        p : typing.Optional[float]
            Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`.
            Defaults to `0.75`. min value of `0.01`, max value of `0.99`.


        return_prompt : typing.Optional[bool]
            Whether to return the prompt in the response.

        logprobs : typing.Optional[bool]
            Defaults to `false`. When set to `true`, the log probabilities of the generated tokens will be included in the response.


        tool_choice : typing.Optional[V2ChatStreamRequestToolChoice]
            Used to control whether or not the model will be forced to use a tool when answering. When `REQUIRED` is specified, the model will be forced to use at least one of the user-defined tools, and the `tools` parameter must be passed in the request.
            When `NONE` is specified, the model will be forced **not** to use one of the specified tools, and give a direct response.
            If tool_choice isn't specified, then the model is free to choose whether to use the specified tools or not.

            **Note**: This parameter is only compatible with models [Command-r7b](https://docs.cohere.com/v2/docs/command-r7b) and newer.

            **Note**: The same functionality can be achieved in `/v1/chat` using the `force_single_step` parameter. If `force_single_step=true`, this is equivalent to specifying `REQUIRED`. While if `force_single_step=true` and `tool_results` are passed, this is equivalent to specifying `NONE`.


        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Yields
        ------
        typing.AsyncIterator[StreamedChatResponseV2]


        Examples
        --------
        import asyncio

        from cohere import AsyncClient, ToolChatMessageV2

        client = AsyncClient(
            client_name="YOUR_CLIENT_NAME",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            response = await client.v2.chat_stream(
                model="model",
                messages=[
                    ToolChatMessageV2(
                        tool_call_id="messages",
                        content="messages",
                    )
                ],
            )
            async for chunk in response:
                yield chunk


        asyncio.run(main())
        rM   rN   rI   rJ   rO   rP   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   TrT   rV   rW   rX   Nr]   r^   r_   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   )(r/   rp   rU   r   r   rq   rr   r   r   r	   r
   rs   rn   rt   ru   	aiter_sserw   r   r   rZ   rx   ry   areadr   r{   r|   r   r   r   r   r   r   r   r   r   r   r   r   r   r}   r~   s                            r2   r   zAsyncV2Client.chat_stream  s    J ''44;;C$
 @!foof.EQX  D%&//Bb2cov #$K,T[% "#J+8HT[$$ {%& j'( !.)* {+, -. $%6/0 #$412 Q34 Q56  78 %*=B  2 ,O < (
 (
P JW)//5#5$-$9$9)$DM&3&=&=&? 
!d	!"(++ 6 .*@,0JJtyy,A!"#   oo'''((C/)"OOFJJ7*&,oofjj&A(1(8  ((C/+"OOFJJ7*&,oofjj&A(1(8  ((C/("OOFJJ7*&,oofjj&A(1(8  ((C/'"OOFJJ7*&,oofjj&A(1(8  ((C/2"OOFJJ7*&,oofjj&A(1(8  ((C/."OOFJJ7*&,oofjj&A(1(8  ((C/+"OOFJJ7*&,oofjj&A(1(8  ((C/2"OOFJJ7*&,oofjj&A(1(8  ((C/-"OOFJJ7*&,oofjj&A(1(8  ((C/-"OOFJJ7*&,oofjj&A(1(8  ((C/1"OOFJJ7*&,oofjj&A(1(8  ((C/-"OOFJJ7*&,oofjj&A(1(8  "+!1 y'<'<>RRi(
X
!!  '@ o(
 (
 (
p (t # W9+@+@y~~VVWe(
 (
 (
s   C!a#_5$a'a)=`&`*_8+`.`0A	_;9``Y`a5a8`;` =`a`a`+aaaaaac                  K   | j                   j                  j                  ddi d|dt        |t        d      dt        |t
        j                  t           d      d|d	t        |t
        j                  t           d      d
t        |t        d      dt        |t        d      d|d|	d|
d|d|d|d|d|d|d|||ddddi|t               d{   }	 d|j                  cxk  rdk  r:n n7t        j                  t        t        t        |j!                                     S |j                  dk(  rvt#        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d k(  rvt)        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d!k(  rvt+        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d"k(  rvt-        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d#k(  rvt/        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d$k(  rvt1        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d%k(  rvt3        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d&k(  rvt5        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d'k(  rvt7        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d(k(  rvt9        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d)k(  rvt;        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j                  d*k(  rvt=        t        j                  t
        j$                  t
        j&                     t        t
        j$                  t
        j&                     |j!                                           |j!                         }tA        |j                  |+      7 # t>        $ r" tA        |j                  |jB                  +      w xY ww),a*  
        Generates a text response to a user message and streams it down, token by token. To learn how to use the Chat API with streaming follow our [Text Generation guides](https://docs.cohere.com/v2/docs/chat-api).

        Follow the [Migration Guide](https://docs.cohere.com/v2/docs/migrating-v1-to-v2) for instructions on moving from API v1 to API v2.

        Parameters
        ----------
        model : str
            The name of a compatible [Cohere model](https://docs.cohere.com/v2/docs/models) (such as command-r or command-r-plus) or the ID of a [fine-tuned](https://docs.cohere.com/v2/docs/chat-fine-tuning) model.

        messages : ChatMessages

        tools : typing.Optional[typing.Sequence[ToolV2]]
            A list of available tools (functions) that the model may suggest invoking before producing a text response.

            When `tools` is passed (without `tool_results`), the `text` content in the response will be empty and the `tool_calls` field in the response will be populated with a list of tool calls that need to be made. If no calls need to be made, the `tool_calls` array will be empty.


        strict_tools : typing.Optional[bool]
            When set to `true`, tool calls in the Assistant message will be forced to follow the tool definition strictly. Learn more in the [Structured Outputs (Tools) guide](https://docs.cohere.com/docs/structured-outputs-json#structured-outputs-tools).

            **Note**: The first few requests with a new set of tools will take longer to process.


        documents : typing.Optional[typing.Sequence[V2ChatRequestDocumentsItem]]
            A list of relevant documents that the model can cite to generate a more accurate reply. Each document is either a string or document object with content and metadata.


        citation_options : typing.Optional[CitationOptions]

        response_format : typing.Optional[ResponseFormatV2]

        safety_mode : typing.Optional[V2ChatRequestSafetyMode]
            Used to select the [safety instruction](https://docs.cohere.com/v2/docs/safety-modes) inserted into the prompt. Defaults to `CONTEXTUAL`.
            When `OFF` is specified, the safety instruction will be omitted.

            Safety modes are not yet configurable in combination with `tools`, `tool_results` and `documents` parameters.

            **Note**: This parameter is only compatible with models [Command R 08-2024](https://docs.cohere.com/v2/docs/command-r#august-2024-release), [Command R+ 08-2024](https://docs.cohere.com/v2/docs/command-r-plus#august-2024-release) and newer.

            **Note**: `command-r7b-12-2024` only supports `"CONTEXTUAL"` and `"STRICT"` modes.


        max_tokens : typing.Optional[int]
            The maximum number of tokens the model will generate as part of the response.

            **Note**: Setting a low value may result in incomplete generations.


        stop_sequences : typing.Optional[typing.Sequence[str]]
            A list of up to 5 strings that the model will use to stop generation. If the model generates a string that matches any of the strings in the list, it will stop generating tokens and return the generated text up to that point not including the stop sequence.


        temperature : typing.Optional[float]
            Defaults to `0.3`.

            A non-negative float that tunes the degree of randomness in generation. Lower temperatures mean less random generations, and higher temperatures mean more random generations.

            Randomness can be further maximized by increasing the  value of the `p` parameter.


        seed : typing.Optional[int]
            If specified, the backend will make a best effort to sample tokens
            deterministically, such that repeated requests with the same
            seed and parameters should return the same result. However,
            determinism cannot be totally guaranteed.


        frequency_penalty : typing.Optional[float]
            Defaults to `0.0`, min value of `0.0`, max value of `1.0`.
            Used to reduce repetitiveness of generated tokens. The higher the value, the stronger a penalty is applied to previously present tokens, proportional to how many times they have already appeared in the prompt or prior generation.


        presence_penalty : typing.Optional[float]
            Defaults to `0.0`, min value of `0.0`, max value of `1.0`.
            Used to reduce repetitiveness of generated tokens. Similar to `frequency_penalty`, except that this penalty is applied equally to all tokens that have already appeared, regardless of their exact frequencies.


        k : typing.Optional[float]
            Ensures that only the top `k` most likely tokens are considered for generation at each step. When `k` is set to `0`, k-sampling is disabled.
            Defaults to `0`, min value of `0`, max value of `500`.


        p : typing.Optional[float]
            Ensures that only the most likely tokens, with total probability mass of `p`, are considered for generation at each step. If both `k` and `p` are enabled, `p` acts after `k`.
            Defaults to `0.75`. min value of `0.01`, max value of `0.99`.


        return_prompt : typing.Optional[bool]
            Whether to return the prompt in the response.

        logprobs : typing.Optional[bool]
            Defaults to `false`. When set to `true`, the log probabilities of the generated tokens will be included in the response.


        tool_choice : typing.Optional[V2ChatRequestToolChoice]
            Used to control whether or not the model will be forced to use a tool when answering. When `REQUIRED` is specified, the model will be forced to use at least one of the user-defined tools, and the `tools` parameter must be passed in the request.
            When `NONE` is specified, the model will be forced **not** to use one of the specified tools, and give a direct response.
            If tool_choice isn't specified, then the model is free to choose whether to use the specified tools or not.

            **Note**: This parameter is only compatible with models [Command-r7b](https://docs.cohere.com/v2/docs/command-r7b) and newer.

            **Note**: The same functionality can be achieved in `/v1/chat` using the `force_single_step` parameter. If `force_single_step=true`, this is equivalent to specifying `REQUIRED`. While if `force_single_step=true` and `tool_results` are passed, this is equivalent to specifying `NONE`.


        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        ChatResponse


        Examples
        --------
        import asyncio

        from cohere import AsyncClient, ToolChatMessageV2

        client = AsyncClient(
            client_name="YOUR_CLIENT_NAME",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.v2.chat(
                model="model",
                messages=[
                    ToolChatMessageV2(
                        tool_call_id="messages",
                        content="messages",
                    )
                ],
            )


        asyncio.run(main())
        rM   rN   rI   rJ   rO   rP   r7   r8   r9   r:   r;   r<   r=   r>   r?   r@   rA   rB   rC   rD   rE   FrT   rV   rW   rX   Nr]   r^   r_   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r   r   s                          r2   r   zAsyncV2Client.chat  s`    F ..;;CCC$
 @!foof.EQX  D%&//B\2]ip #$K,T[% "#J+8HT[$$ {%& j'( !.)* {+, -. $%6/0 #$412 Q34 Q56  78 %*=B  2 ,O D (
 (
	RC	Si++1c1{{ "* ) 0  $$+%KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+$KK

3&"(//&**"=$-NN$4  $$+#KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+*KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+-KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  '^^-N 9#8#8~NN[(
V  	Sy'<'<9>>RR	Ss8   C _"^#_(A^ 6_7Y^ _+__r   r   r   r   r   r   c                R  K   | j                   j                  j                  dd||||||dddi|t               d{   }	 d|j                  cxk  rd	k  r:n n7t        j                  t        t        t        |j                         
            S |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt!        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt#        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt%        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt'        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt)        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt+        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt-        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt/        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                         }	t3        |j                  |	      7 # t0        $ r" t3        |j                  |j4                        w xY ww)a  
        This endpoint returns text embeddings. An embedding is a list of floating point numbers that captures semantic information about the text that it represents.

        Embeddings can be used to create text classifiers as well as empower semantic search. To learn more about embeddings, see the embedding page.

        If you want to learn more how to use the embedding model, have a look at the [Semantic Search Guide](https://docs.cohere.com/docs/semantic-search).

        Parameters
        ----------
        model : str
            Defaults to embed-english-v2.0

            The identifier of the model. Smaller "light" models are faster, while larger models will perform better. [Custom models](https://docs.cohere.com/docs/training-custom-models) can also be supplied with their full ID.

            Available models and corresponding embedding dimensions:

            * `embed-english-v3.0`  1024
            * `embed-multilingual-v3.0`  1024
            * `embed-english-light-v3.0`  384
            * `embed-multilingual-light-v3.0`  384

            * `embed-english-v2.0`  4096
            * `embed-english-light-v2.0`  1024
            * `embed-multilingual-v2.0`  768

        input_type : EmbedInputType

        embedding_types : typing.Sequence[EmbeddingType]
            Specifies the types of embeddings you want to get back. Can be one or more of the following types.

            * `"float"`: Use this when you want to get back the default float embeddings. Valid for all models.
            * `"int8"`: Use this when you want to get back signed int8 embeddings. Valid for only v3 models.
            * `"uint8"`: Use this when you want to get back unsigned int8 embeddings. Valid for only v3 models.
            * `"binary"`: Use this when you want to get back signed binary embeddings. Valid for only v3 models.
            * `"ubinary"`: Use this when you want to get back unsigned binary embeddings. Valid for only v3 models.

        texts : typing.Optional[typing.Sequence[str]]
            An array of strings for the model to embed. Maximum number of texts per call is `96`. We recommend reducing the length of each text to be under `512` tokens for optimal quality.

        images : typing.Optional[typing.Sequence[str]]
            An array of image data URIs for the model to embed. Maximum number of images per call is `1`.

            The image must be a valid [data URI](https://developer.mozilla.org/en-US/docs/Web/URI/Schemes/data). The image must be in either `image/jpeg` or `image/png` format and has a maximum size of 5MB.

        truncate : typing.Optional[V2EmbedRequestTruncate]
            One of `NONE|START|END` to specify how the API will handle inputs longer than the maximum token length.

            Passing `START` will discard the start of the input. `END` will discard the end of the input. In both cases, input is discarded until the remaining input is exactly the maximum input token length for the model.

            If `NONE` is selected, when the input exceeds the maximum input token length an error will be returned.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        EmbedByTypeResponse
            OK

        Examples
        --------
        import asyncio

        from cohere import AsyncClient

        client = AsyncClient(
            client_name="YOUR_CLIENT_NAME",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.v2.embed(
                model="model",
                input_type="search_document",
                embedding_types=["float"],
            )


        asyncio.run(main())
        r   rN   r   rV   rW   rX   Nr]   r^   r_   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r   r   s
             r2   r   zAsyncV2Client.embedB  s<    x ..;;CC (#2$  2 , D 
 
	"C	Si++1c1{{'"1 ) 0  $$+%KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+$KK

3&"(//&**"=$-NN$4  $$+#KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+*KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+-KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  '^^-N 9#8#8~NNk
f  	Sy'<'<9>>RR	S5   <\'[6\'A[9 \'Y[9 \'9+\$$\'r   r   r   r   r   c                R  K   | j                   j                  j                  dd||||||dddi|t               d{   }	 d|j                  cxk  rd	k  r:n n7t        j                  t        t        t        |j                         
            S |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt!        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt#        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt%        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt'        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt)        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt+        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt-        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                  dk(  rvt/        t        j                  t
        j                  t
        j                     t        t
        j                  t
        j                     |j                         
                  |j                         }	t3        |j                  |	      7 # t0        $ r" t3        |j                  |j4                        w xY ww)aL  
        This endpoint takes in a query and a list of texts and produces an ordered array with each text assigned a relevance score.

        Parameters
        ----------
        model : str
            The identifier of the model to use, eg `rerank-v3.5`.

        query : str
            The search query

        documents : typing.Sequence[str]
            A list of texts that will be compared to the `query`.
            For optimal performance we recommend against sending more than 1,000 documents in a single request.

            **Note**: long documents will automatically be truncated to the value of `max_tokens_per_doc`.

            **Note**: structured data should be formatted as YAML strings for best performance.

        top_n : typing.Optional[int]
            Limits the number of returned rerank results to the specified value. If not passed, all the rerank results will be returned.

        return_documents : typing.Optional[bool]
            - If false, returns results without the doc text - the api will return a list of {index, relevance score} where index is inferred from the list passed into the request.
            - If true, returns results with the doc text passed in - the api will return an ordered list of {index, text, relevance score} where index + text refers to the list passed into the request.

        max_tokens_per_doc : typing.Optional[int]
            Defaults to `4096`. Long documents will be automatically truncated to the specified number of tokens.

        request_options : typing.Optional[RequestOptions]
            Request-specific configuration.

        Returns
        -------
        V2RerankResponse
            OK

        Examples
        --------
        import asyncio

        from cohere import AsyncClient

        client = AsyncClient(
            client_name="YOUR_CLIENT_NAME",
            token="YOUR_TOKEN",
        )


        async def main() -> None:
            await client.v2.rerank(
                model="model",
                query="query",
                documents=["documents"],
            )


        asyncio.run(main())
        r   rN   r   rV   rW   rX   Nr]   r^   r_   ra   rb   rc   rd   re   rf   rg   rh   ri   rj   rk   rl   rm   r   r   s
             r2   r   zAsyncV2Client.rerank5  s<    L ..;;CC&$4&8  2 , D 
 
	"C	Si++1c1{{$". ) 0  $$+%KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+$KK

3&"(//&**"=$-NN$4  $$+#KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+*KK

3&"(//&**"=$-NN$4  $$+'KK

3&"(//&**"=$-NN$4  $$+.KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  $$+-KK

3&"(//&**"=$-NN$4  $$+)KK

3&"(//&**"=$-NN$4  '^^-N 9#8#8~NNk
f  	Sy'<'<9>>RR	Sr   )$r   r   r   r(   r3   rs   r   r   rq   r{   rr   r   r   r   r	   r
   r   r   r   r   r   AsyncIteratorr   r   r   r    r!   r"   r   r#   r$   r%   r&   r   r'   r   r   r5   r2   r   r     sm   .*< . ;?.2X\=A=AFJ+/@D.2%)4837$($(/3*.FJ;?-YS YS 	YS
 vv67YS ood+YS ??6??3S#TUYS !///:YS  )9:YS __%BCYS OOC(YS (<=YS __U+YS ooc"YS "??51YS  !//%0!YS" ??5!#YS$ ??5!%YS& t,'YS( //$')YS* __%BC+YS,  8-YS. 
		4	5/YS@ ;?.2RV=A=A@D+/@D.2%)4837$($(/3*.@D;?-PO PO 	PO
 vv67PO ood+PO ??6??3M#NOPO !///:PO  )9:PO __%<=PO OOC(PO (<=PO __U+PO ooc"PO "??51PO  !//%0!PO" ??5!#PO$ ??5!%PO& t,'PO( //$')PO* __%<=+PO,  8-PO. 
/POp
 8<8<<@;?qO qO #	qO
  7qO vs34qO  45qO //"89qO  8qO 
qOr '+2637;?[O [O 	[O
 ??3'[O s#[O !//$/[O #OOC0[O  8[O 
[Or5   r   )Orq   core.client_wrapperr   types.chat_messagesr   types.tool_v2r   *types.v2chat_stream_request_documents_itemr   types.citation_optionsr	   types.response_format_v2r
   'types.v2chat_stream_request_safety_moder   'types.v2chat_stream_request_tool_choicer   core.request_optionsr   types.streamed_chat_response_v2r   core.serializationr   rt   core.unchecked_base_modelr   rZ   errors.bad_request_errorr   errors.unauthorized_errorr   errors.forbidden_errorr   errors.not_found_errorr   !errors.unprocessable_entity_errorr   errors.too_many_requests_errorr   errors.invalid_token_errorr   "errors.client_closed_request_errorr   errors.internal_server_errorr   errors.not_implemented_errorr    errors.service_unavailable_errorr   errors.gateway_timeout_errorr   json.decoderr   core.api_errorr   #types.v2chat_request_documents_itemr    types.v2chat_request_safety_moder     types.v2chat_request_tool_choicer!   types.chat_responser"   types.embed_input_typer#   types.embedding_typer$   types.v2embed_request_truncater%   types.embed_by_type_responser&   types.v2rerank_responser'   r(   rw   r|   rs   r*   r   r   r5   r2   <module>r      s     3 . " X 4 7 R R 1 D H  6  6 9 3 2 H A : I > > F > ( % K E E . 3 0 B > 5 4 v{{6::s#_O _OD#O Or5   