o
    :/i                     @   s~  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mZ ddlmZ ddlmZ erGd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e%B defddZ&dee%B de fdd Z'dee%B de!fd!d"Z(dee%B 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eB de+fd-d.Z-d%d&deeB fd/d0Z.dS )1z1
Schemas and utilities for preprocessing inputs.
    )Sequence)TYPE_CHECKING
NamedTuple	TypeAlias	TypedDictoverload)EmbedsPromptExplicitEncoderDecoderPromptProcessorInputs
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   m/lsinfo/ai/hellotax_ai/llm_service/venv_vllm/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   0   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.
    r2   )Token prompt should be a list of integersprompt_token_idsr)   z9Cannot pass encoder-decoder prompt to decoder-only modelsr2   r6   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   r3   r   r   r   parse_dec_only_promptw   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	)
Nr3   r4   r5   r7   7Cannot pass embeddings prompt to encoder-decoder modelsr2   r6   -Prompt dictionary must contain text or tokensr8   r9   r3   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)Nr3   r4   r5   r7   r=   multi_modal_datamm_processor_kwargsmulti_modal_uuidsz0Cannot pass multi-modal inputs to decoder promptr2   r6   r>   r8   r9   r3   r   r   r   _parse_dec_prompt   s"   





rC   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?   rC   )r2   
enc_prompt
dec_promptr   r   r   parse_enc_dec_prompt   s   

rF   model_configr   c                 C   s   | j rt|S t|S r   is_encoder_decoderrF   r<   rG   r2   r   r   r   parse_model_prompt   s   rK   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-   rM   r   r/   rN   r:   r"   rO   r   r   r   r   rL      s   
 rL   c                 C   s   | j r	t|d S t|S )Nr)   rH   rJ   r   r   r   extract_target_prompt   s
   rP   c                 C   s*   t | |}t|d|d|ddS )Nr2   r6   r7   )rM   rN   rO   )rP   rL   getrG   r2   target_promptr   r   r   extract_prompt_components   s   
rT   c                 C   s    t | |}t|d|dS )Nr6   r7   )rP   r   rQ   rR   r   r   r   extract_prompt_len   s
   
rU   )/r.   collections.abcr   typingr   r   r   r   r   vllm.inputsr   r	   r
   r   r   r   r   
vllm.utilsr   vllm.utils.collection_utilsr   torchvllm.configr   vllm.entrypoints.chat_utilsr   r    r   r:   r$   r%   r/   r&   r'   r(   r0   r1   objectr<   r?   rC   rF   rK   rL   rP   rT   rU   r   r   r   r   <module>   s    $	







