
    i                        d Z 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j8                  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)z3
Legacy /v1/embedding handler for Bedrock Cohere. 
    N)AnyCallableOptionalUnion)Logging)AsyncHTTPHandlerHTTPHandlerget_async_httpx_client)CohereEmbeddingRequest)EmbeddingResponse   )CohereEmbeddingConfigheadersc                     |j                         D ci c]  }|j                         | }}d|vrd|d<   d|vrd|d<   d|vrd|d<   | rd|vrd|  |d	<   |S c c}w )
Nzrequest-sourcezunspecified:litellmzRequest-Sourceacceptzapplication/jsonzcontent-typeauthorizationzBearer Authorization)keyslower)api_keyr   kexisting_keys_lowers       r/Users/manta/Documents/Projects/TheRoad-I1/.venv/lib/python3.12/site-packages/litellm/llms/cohere/embed/handler.pyvalidate_environmentr      s     29@A1779a<@ 22$9 !**.00"4?*==%,WI#6 N As   A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	
    )__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   r8   r3   r   additional_argsr5   )llm_providerparamsr   r2   r<   )r3   r   r>   original_responser'   r   r6   r2   r4   r1   r9   r3   )pre_callr
   litellmLlmProvidersCOHEREpostjsondumpsr$   HTTPStatusError	post_callr'   text	Exceptionstrr   _transform_response)r1   r2   r3   r4   r5   r6   r7   r8   r   r   r9   r:   r'   es                 r   async_embeddingrR   5   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)r1   r3   inference_paramsT)r1   r2   r3   r4   r5   r6   r7   r8   r   r   r9   r:   r<   r=   r   )concurrent_limitrA   rC   )r   r   _transform_requestrR   
isinstancer   rD   r	   rH   rI   rJ   rP   )r1   r3   r4   r6   r7   r   r9   r2   rS   r   rT   r5   r:   	embed_urlr'   s                  r   	embeddingr[   w   s2    #7G<G!E%EIE (*==5? > D
 T)#+ %*V=M*N 
 	
 
 	
( .5   ~Z<a0{{9gDJJt<L{MH "66% 7 	 	r,   )N)"__doc__rI   typingr   r   r   r   r$   rE   *litellm.litellm_core_utils.litellm_loggingr   LiteLLMLoggingObj&litellm.llms.custom_httpx.http_handlerr   r	   r
   litellm.types.llms.bedrockr   litellm.types.utilsr   v1_transformationr   dictr   rN   r   rO   listutilsfloatTimeoutrR   boolr[    r,   r   <module>rk      s    1 1   S 
 > 1 44 "

) 

2 *.??
,,
-? ? MM33	?
 eE5==012? #? ? ? c]? ? ? %&?T ;?'+!!%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,   