Ë
    uPêjQ  ã                   ó¶   — d Z ddlmZmZ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mZ ddlmZ dd	lmZ er	dd
lmZ eZneZ G d„ de«      Z G d„ de	«      Zy)a  
Hosted VLLM Embedding API Configuration.

This module provides the configuration for hosted VLLM's Embedding API.
VLLM is OpenAI-compatible and supports embeddings via the /v1/embeddings endpoint.

Docs: https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html
é    )ÚTYPE_CHECKINGÚAnyÚFinalN)ÚBaseLLMException)ÚBaseEmbeddingConfig©Úget_secret_str)ÚAllEmbeddingInputValuesÚAllMessageValues)ÚEmbeddingResponse)Ú convert_to_model_response_object)ÚLoggingc                   ó   — e Zd ZdZy)ÚHostedVLLMEmbeddingErrorz1Exception class for Hosted VLLM Embedding errors.N)Ú__name__Ú
__module__Ú__qualname__Ú__doc__© ó    úv/home/oem/CyberBrain26-unified/.venv/lib/python3.12/site-packages/litellm/llms/hosted_vllm/embedding/transformation.pyr   r      s   „ Ú;r   r   c                   óJ  — e Zd ZdZ	 	 ddededee   dedededz  d	edz  d
efd„Z	 dd	edz  dedz  dededede	dz  d
efd„Z
dedededed
ef
d„Zdedej                  dedededz  dededed
efd„Zded
efd„Zdededede	d
ef
d„Zdededeej*                  z  d
efd„Zy)ÚHostedVLLMEmbeddingConfigz�
    Configuration for Hosted VLLM's Embedding API.

    Reference: https://docs.vllm.ai/en/latest/serving/openai_compatible_server.html
    NÚheadersÚmodelÚmessagesÚoptional_paramsÚlitellm_paramsÚapi_keyÚapi_baseÚreturnc                 óV   — |€t        d«      xs d}ddi}|r|dk7  rd|› �|d<   i |¥|¥S )zN
        Validate environment and set up headers for Hosted VLLM API.
        ÚHOSTED_VLLM_API_KEYzfake-api-keyzContent-Typezapplication/jsonzBearer ÚAuthorizationr   )	Úselfr   r   r   r   r   r   r    Údefault_headerss	            r   Úvalidate_environmentz.HostedVLLMEmbeddingConfig.validate_environment(   sW   € ð ˆ?Ü$Ð%:Ó;ÒM¸~ˆGð Ð.ð"
ˆñ
 �w .Ò0Ø18¸¸	Ð/BˆO˜OÑ,ð .�/Ð- WÐ-Ð-r   Ústreamc                 óˆ   — |€t        d«      }|€t        d«      ‚|j                  d«      }|j                  d«      s|› d�}|S )zN
        Get the complete URL for Hosted VLLM Embedding API endpoint.
        ÚHOSTED_VLLM_API_BASEz/api_base is required for hosted_vllm embeddingsú/z/embeddings)r	   Ú
ValueErrorÚrstripÚendswith)r%   r    r   r   r   r   r(   s          r   Úget_complete_urlz*HostedVLLMEmbeddingConfig.get_complete_urlC   sX   € ð ÐÜ%Ð&<Ó=ˆHØÐÜ Ð!RÓSÐSð —?‘? 3Ó'ˆð × Ñ  Ô/Ø"˜ ;Ð/ˆHàˆr   Úinputc                 ó~   — t        |t        «      r|g}|j                  d«      r|j                  ddd«      }||dœ|¥S )zX
        Transform embedding request to Hosted VLLM format (OpenAI-compatible).
        zhosted_vllm/Ú é   )r   r0   )Ú
isinstanceÚstrÚ
startswithÚreplace)r%   r   r0   r   r   s        r   Útransform_embedding_requestz5HostedVLLMEmbeddingConfig.transform_embedding_request]   sS   € ô �eœSÔ!Ø�GˆEð ×Ñ˜NÔ+Ø—M‘M .°"°aÓ8ˆEð Øñ
ð ð
ð 	
r   Úraw_responseÚmodel_responseÚlogging_objÚrequest_datac	                 óv   — |j                  |j                  ¬«       |j                  «       }	t        |	|d¬«      S )z[
        Transform embedding response from Hosted VLLM format (OpenAI-compatible).
        )Úoriginal_responseÚ	embedding)Úresponse_objectÚmodel_response_objectÚresponse_type)Ú	post_callÚtextÚjsonr   )
r%   r   r9   r:   r;   r   r<   r   r   Úresponse_jsons
             r   Útransform_embedding_responsez6HostedVLLMEmbeddingConfig.transform_embedding_responseu   sA   € ð 	×Ñ°×0AÑ0AÐÔBð  ,×0Ñ0Ó2ˆä/Ø)Ø"0Ø%ô
ð 	
r   c                 ó
   — g d¢S )zU
        Get list of supported OpenAI parameters for Hosted VLLM embeddings.
        )ÚtimeoutÚ
dimensionsÚencoding_formatÚuserr   )r%   r   s     r   Úget_supported_openai_paramsz5HostedVLLMEmbeddingConfig.get_supported_openai_paramsŽ   s   € ò
ð 	
r   Únon_default_paramsÚdrop_paramsc                 óh   — |j                  «       D ]  \  }}|| j                  |«      v sŒ|||<   Œ  |S )z>
        Map OpenAI parameters to Hosted VLLM format.
        )ÚitemsrM   )r%   rN   r   r   rO   ÚparamÚvalues          r   Úmap_openai_paramsz+HostedVLLMEmbeddingConfig.map_openai_params™   sE   € ð /×4Ñ4Ó6ò 	/‰LˆE�5Ø˜×8Ñ8¸Ó?Ò?Ø).� Ò&ð	/ð Ðr   Úerror_messageÚstatus_codec                 ó   — t        |||¬«      S )z=
        Get the error class for Hosted VLLM errors.
        )ÚmessagerV   r   )r   )r%   rU   rV   r   s       r   Úget_error_classz)HostedVLLMEmbeddingConfig.get_error_class¨   s   € ô (Ø!Ø#Øô
ð 	
r   )NN)N)r   r   r   r   Údictr5   Úlistr   r'   Úboolr/   r
   r8   ÚhttpxÚResponser   ÚLiteLLMLoggingObjrG   rM   rT   ÚintÚHeadersr   rY   r   r   r   r   r   !   sÛ  „ ñð #Ø#ñ.àð.ð ð.ð Ð'Ñ(ð	.ð
 ð.ð ð.ð �t‘ð.ð ˜‘*ð.ð 
ó.ðD #ñà˜‘*ðð �t‘ðð ð	ð
 ðð ðð �t‘ðð 
óð4
àð
ð 'ð
ð ð	
ð
 ð
ð 
ó
ð0
àð
ð —n‘nð
ð *ð	
ð
 'ð
ð �t‘ð
ð ð
ð ð
ð ð
ð 
ó
ð2	
°ð 	
¸ó 	
ðà ðð ðð ð	ð
 ðð 
óð
¨Sð 
¸sð 
ÈTÐTY×TaÑTaÑMað 
Ðfvô 
r   r   )r   Útypingr   r   r   r]   Ú)litellm.llms.base_llm.chat.transformationr   Ú.litellm.llms.base_llm.embedding.transformationr   Úlitellm.secret_managers.mainr	   Úlitellm.types.llms.openair
   r   Úlitellm.types.utilsr   Úlitellm.utilsr   Ú*litellm.litellm_core_utils.litellm_loggingr   Ú_LiteLLMLoggingObjr_   r   r   r   r   r   ú<module>rk      sU   ðñ÷ -Ñ ,ã å FÝ NÝ 7ß OÝ 1Ý :áÝXà*ÑàÐô<Ð/ô <ôO
Ð 3õ O
r   