o
    
۾i                     @   sb  U d Z ddlmZ ddlmZmZmZmZmZ ddl	m
Z
mZmZmZmZmZ ddlmZ ddlmZ erEddlZddlmZ dd	lmZ ed
eeB eeeB  B dee fddZed
eee B dee fddZed
eee B dee fddZd
eeB eeeB  B dee fddZded eed  B deed  fddZeeB e
B Zeed< 	 eeB Zeed< 	 eeB Z eed< 	 G dd deZ!eeB e B Z"eed< 	 ee!B Z#eed< 	 de$defddZ%de$defdd Z&de$de fd!d"Z'de$de!fd#d$Z(d%d&de$fd'd(Z)G d)d* d*eZ*d%d&de$fd+d,Z+d%d&de$de*fd-d.Z,d%d&de$fd/d0Z-dS )1z0
Schemas and utilites for preprocessing inputs.
    )Sequence)TYPE_CHECKING
NamedTuple	TypeAlias	TypedDictoverload)EmbedsPromptExplicitEncoderDecoderPrompt
PromptTypeSingletonPrompt
TextPromptTokensPrompt)&length_from_prompt_token_ids_or_embeds)
is_list_ofN)ModelConfig)ChatCompletionMessageParamprompt_or_promptsreturnc                 C      d S N r   r   r   T/home/ubuntu/.local/lib/python3.10/site-packages/vllm/renderers/inputs/preprocess.pyprompt_to_seq      r   c                 C   r   r   r   r   r   r   r   r   "   s   c                 C   r   r   r   r   r   r   r   r   )   r   c                 C   s0   t | tttfst| dkrt| tr| gS | S Nr   )
isinstancedictstrbyteslenr   intr   r   r   r   r   /   s   conversation_or_conversationsr   c                 C   s    t | dkrt| tr| gS | S r   )r    r   r   )r"   r   r   r   conversation_to_seq:   s
   r#   DecoderOnlyDictPromptEncoderDictPromptDecoderDictPromptc                   @   s&   e Zd ZU dZeed< edB ed< dS )EncoderDecoderDictPromptz}
    A [`EncoderDecoderPrompt`][vllm.inputs.data.EncoderDecoderPrompt]
    that has been standardized into a dictionary.
    encoder_promptNdecoder_prompt)__name__
__module____qualname____doc__r%   __annotations__r&   r   r   r   r   r'   [   s   
 r'   SingletonDictPrompt
DictPromptpromptc                 C   s   t | tr
t| dS t | trt| tstdt| dS t | tr<d| v r*tdd| v s6d| v s6d| v r8| S td	td
)zS
    Parse a prompt for a decoder-only model and normalize it to a dictionary.
    r1   )Token prompt should be a list of integersprompt_token_idsr(   z9Cannot pass encoder-decoder prompt to decoder-only modelsr1   r5   prompt_embedsz:Prompt dictionary must contain text, tokens, or embeddings8Prompt should be a string, list of tokens, or dictionary	r   r   r   listr   r!   	TypeErrorr   r   r2   r   r   r   parse_dec_only_promptv   s   





r;   c                 C   sx   t | tr
t| dS t | trt| tstdt| dS t | tr8d| v r*tdd| v s2d| v r4| S tdtd	)
Nr2   r3   r4   r6   7Cannot pass embeddings prompt to encoder-decoder modelsr1   r5   -Prompt dictionary must contain text or tokensr7   r8   r2   r   r   r   _parse_enc_prompt   s   





r>   c                 C   s   t | tr
t| dS t | trt| tstdt| dS t | trHd| v r*tdd| v s6d| v s6d| v r:td	d
| v sBd| v rD| S tdtd)Nr2   r3   r4   r6   r<   multi_modal_datamm_processor_kwargsmulti_modal_uuidsz0Cannot pass multi-modal inputs to decoder promptr1   r5   r=   r7   r8   r2   r   r   r   _parse_dec_prompt   s"   





rB   c                 C   sP   t | trd| v r| d }| d }n| }d}tt||du r"ddS t|dS )zW
    Parse a prompt for an encoder-decoder model and normalize it to a dictionary.
    r(   r)   N)r(   r)   )r   r   r'   r>   rB   )r1   
enc_prompt
dec_promptr   r   r   parse_enc_dec_prompt   s   

rE   model_configr   c                 C   s   | j rt|S t|S r   is_encoder_decoderrE   r;   rF   r1   r   r   r   parse_model_prompt   s   rJ   c                   @   s>   e Zd ZU dZedB ed< dZee dB ed< dZ	ded< dS )PromptComponentsNtext	token_idsztorch.Tensor | Noneembeds)
r*   r+   r,   rL   r   r.   rM   r9   r!   rN   r   r   r   r   rK      s   
 rK   c                 C   s   | j r	t|d S t|S )Nr(   rG   rI   r   r   r   extract_target_prompt   s
   rO   c                 C   s*   t | |}t|d|d|ddS )Nr1   r5   r6   )rL   rM   rN   )rO   rK   getrF   r1   target_promptr   r   r   extract_prompt_components   s   
rS   c                 C   s    t | |}t|d|dS )Nr5   r6   )rO   r   rP   rQ   r   r   r   extract_prompt_len   s
   
rT   ).r-   collections.abcr   typingr   r   r   r   r   vllm.inputsr   r	   r
   r   r   r   
vllm.utilsr   vllm.utils.collection_utilsr   torchvllm.configr   vllm.entrypoints.chat_utilsr   r   r   r9   r#   r$   r.   r%   r&   r'   r/   r0   objectr;   r>   rB   rE   rJ   rK   rO   rS   rT   r   r   r   r   <module>   s     







