
    g                        d dl Z d dlmZmZmZmZ d dlZd dlZd dlm	Z
 d dlmZmZmZ d dlmZ d dlmZ ddlmZ d	efd
Z G d de      Z	 ddedeeef   dedej6                  j$                  deeeej:                  f      de
dededee   d	ededee   fdZdddd ej:                  d      dfdededede
ded	ededeeeef      dee   dee   dee   deeeej:                  f      deeeef      fdZ y)    N)AnyCallableOptionalUnion)Logging)AsyncHTTPHandlerHTTPHandlerget_async_httpx_client)CohereEmbeddingRequest)EmbeddingResponse   )CohereEmbeddingConfigheadersc                 D    |j                  dddd       | rd|  |d<   |S )Nzunspecified:litellmzapplication/json)zRequest-Sourceacceptzcontent-typezBearer Authorization)update)api_keyr   s     V/var/www/openai/venv/lib/python3.12/site-packages/litellm/llms/cohere/embed/handler.pyvalidate_environmentr      s7    NN3(.	
 %,WI#6 N    c                        e Zd Z fdZ xZS )CohereErrorc                     || _         || _        t        j                  dd      | _        t        j
                  || j                        | _        t        | !  | j                         y )NPOSTz!https://api.cohere.ai/v1/generate)methodurl)status_coderequest)	r   messagehttpxRequestr   Responseresponsesuper__init__)selfr   r    	__class__s      r   r&   zCohereError.__init__!   sT    &}}B
 ;ULL	
r   )__name__
__module____qualname__r&   __classcell__)r(   s   @r   r   r       s    	
 	
r   r   modeldatainputmodel_responsetimeoutlogging_objoptional_paramsapi_baser   encodingclientc           
        K   |j                  ||||	|d       |'t        t        j                  j                  d|i      }	 |j                  ||	t        j                  |             d {   }t               j!                  |||||| |
|      S 7 %# t        j                  $ r2}|j                  ||d|i|j                  j                         |d }~wt        $ r'}|j                  ||d|it        |             |d }~ww xY ww)	N)complete_input_dictr   r4   r/   r   additional_argsr1   )llm_providerparamsr   r.   r8   )r/   r   r:   original_responser$   r   r2   r.   r0   r-   r5   r/   )pre_callr
   litellmLlmProvidersCOHEREpostjsondumpsr!   HTTPStatusError	post_callr$   text	Exceptionstrr   _transform_response)r-   r.   r/   r0   r1   r2   r3   r4   r   r   r5   r6   r$   es                 r   async_embeddingrN   -   s8      #' 
   ~' --44w'

XwTZZPTEUVV* !"66% 7 	 	+ W   2D9jjoo	 	 	
  2D9!!f	 	 	
 sH   AD*B /B0B 4!DB D
*-CD
#"DD

Dcomplete_api_base
aembeddingc                    t        |	|      }|xs d}| } |xs t               j                  | ||      }|
du r0t        | ||||||||	|||t	        |t
              r|      S d       S |j                  ||	d|i       |t	        |t              st        d	      }|j                  ||t        j                  |      
      }t               j                  ||	|||| ||      S )N)r   zhttps://api.cohere.ai/v1/embed)r-   r/   inference_paramsT)r-   r.   r/   r0   r1   r2   r3   r4   r   r   r5   r6   r8   r9   r   )concurrent_limitr=   r?   )r   r   _transform_requestrN   
isinstancer   r@   r	   rD   rE   rF   rL   )r-   r/   r0   r2   r3   r   r5   r.   rO   r   rP   r1   r6   	embed_urlr$   s                  r   	embeddingrW   p   s2    #7G<G!E%EIE (*==5? > D
 T)#+ %*V=M*N 
 	
 
 	
( .5   ~Z<a0{{9gDJJt<L{MH "66% 7 	 	r   )N)!rE   typingr   r   r   r   r!   rA   *litellm.litellm_core_utils.litellm_loggingr   LiteLLMLoggingObj&litellm.llms.custom_httpx.http_handlerr   r	   r
   litellm.types.llms.bedrockr   litellm.types.utilsr   transformationr   dictr   rJ   r   rK   listutilsfloatTimeoutrN   boolrW    r   r   <module>rf      s    1 1   S 
 > 1 1
4 


) 

2 *.@@
,,
-@ @ MM33	@
 eE5==012@ #@ @ @ c]@ @ @ %&@V ;?'+!!%5BU]]45H=ABBB &B #	B
 B B B 5556
7B  }B c]B B eE5==012B U;(889:Br   