o
    پiX                  	   @   s@  U d dl Z d dlmZ d dlmZmZ d dlmZmZm	Z	m
Z
 G dd deZeG dd dZi Zeeef ed	< g Ze	e ed
< dd Zdd Zdd Zdd Zeeddddddd eeddddddd eeddddd dejd!d" eed#d$ddd dejd!d%d& eed'd$ddd dejd!d" eed(d$ddd dejd!d)d& eed*d+d,d-d.dd/d0 eed1dd2d3d4dejd5 eed6dd7d3d4dd8d9d: eed;dd<d=d>dd?d@d: eedAdd,dBdCddDdEd: eedFdddGdHdIdJdKd: eedLdd,dBdCddDdEdMdN eedOdddGdHddJdKd: eedPdd<d=d>dd?d%d: eedQddRdSdTddUd@d: eedVdddWdXdejd!d" eedYdZd[d\d]dd^d0 eed_ddd`dadejd5 eedbdcdddedfdd!dg eedhddidjdkdejd5 eedldmddd ddndogdg eedpdqddd ddndogdg eedrddsdtduddvdg eedwdddGdHddJdg eedxddydzd{dejg d|d@d& ed}efd~dZed}efddZed}efddZed}efddZed}efddZed}efddZed}efddZed}efddZed}efddZed}efddZ ed}efddZ!ed}efddZ"ed}efddZ#ed}efddZ$ed}efddZ%ed}efddZ&ed}efddZ'e(dkrdddddddddddddddgZ)ed1Z*e+e*,e) dS dS )    N)	dataclass)Enumauto)CallableDictListTuplec                   @   s   e Zd Ze Ze ZdS )ChatTemplateStyleN)__name__
__module____qualname__r   PLAINLLAMA2 r   r   M/home/ubuntu/.local/lib/python3.10/site-packages/sglang/lang/chat_template.pyr	      s    
r	   c                   @   s   e Zd ZU eed< eed< eeeeef f ed< dZee ed< dZ	eed< dZ
eed	< ejZeed
< dedee deeef fddZdee defddZdS )ChatTemplatenamedefault_system_promptrole_prefix_and_suffixr   stop_strz<image>image_tokenz<audio>audio_tokenstylerolehist_messagesreturnc           	      C   s   | j |d\}}| jtjkrC|dkr-|s-| j dd\}}| j dd\}}|| |fS |dkrCt|dkrC|d d d urCd|fS ||fS )N r   systemuser   r   contentr   )r   getr   r	   r   len)	selfr   r   prefixsuffixuser_prefix_system_prefixsystem_suffixr   r   r   get_prefix_and_suffix   s   z"ChatTemplate.get_prefix_and_suffixmessagesc           	      C   sx   d}t |D ]3\}}|d |d }}|dkr#|d u r#| j}|d u r#q| ||d | \}}|| | | 7 }q|S )Nr   r   r!   r   )	enumerater   r+   )	r$   r,   promptimessager   r!   r%   r&   r   r   r   
get_prompt+   s   zChatTemplate.get_promptN)r
   r   r   str__annotations__r   r   r   r   r   r   r	   r   r   r+   r1   r   r   r   r   r      s    
 

r   chat_template_registrymatching_function_registryc                 C   s   | t | j< d S N)r4   r   )templater   r   r   register_chat_template=      r8   c                 C   s   t |  d S r6   )r5   append)funcr   r   r   (register_chat_template_matching_functionA   r9   r<   c                 C   s   t |  S r6   )r4   )r   r   r   r   get_chat_templateE   s   r=   c                 C   s.   t D ]}|| }|d urt|  S qtdS )Ndefault)r5   r=   )
model_pathmatching_functemplate_namer   r   r   get_chat_template_by_model_pathI   s   rB   r>   )zSYSTEM:
)USER:rC   )
ASSISTANT:rC   )r   r   	assistant)r   r   r   clauder   )z	

Human: r   )z

Assistant:r   chatml)<|im_start|>system
<|im_end|>
)<|im_start|>user
rJ   )z<|im_start|>assistant
rJ   )
<|im_end|>)r   r   r   r   r   chatml-llavazYou are a helpful assistant.z<image>
)r   r   r   r   r   r   qwenqwen2-vlz+<|vision_start|><|image_pad|><|vision_end|>vicuna_v1.1zA chat between a curious user and an artificial intelligence assistant. The assistant gives helpful, detailed, and polite answers to the user's questions.)r    )rD   rQ   )rE   </s>z	 <image>
)r   r   r   r   llama-2-chat)z<<SYS>>
z
<</SYS>>

)z[INST] z [/INST])r   z </s><s>)r   r   r   r   mistral)z[SYSTEM_PROMPT] z [/SYSTEM_PROMPT])rR   z[IMG])r   r   r   r   r   llama-3-instruct)z,<|start_header_id|>system<|end_header_id|>


<|eot_id|>)z*<|start_header_id|>user<|end_header_id|>

rV   )z/<|start_header_id|>assistant<|end_header_id|>

rV   )rV   z	<|image|>minicpmv)zuser:rQ   )z
assistant:rR   )rL   <|endoftext|>z(<image>./</image>)	janus-pro)u   <｜User｜>r   )u   <｜Assistant｜>   <｜end▁of▁sentence｜>)r   UserrF   )rZ   z<image_placeholder>
minicpmoz(<audio>./</audio>))r   r   r   r   r   r   januszllama-3-instruct-llavazllama-4)z&<|header_start|>system<|header_end|>

<|eot|>)z$<|header_start|>user<|header_end|>

r^   )z)<|header_start|>assistant<|header_end|>

r^   )r^   yi-1.5)rK   z!<|im_end|>
<|im_start|>assistant
)r   rJ   yi-vlu  This is a chat between an inquisitive human and an AI assistant. Assume the role of the AI assistant. Read all the images carefully, and respond to the human's questions with informative, helpful, detailed and polite answers.这是一个好奇的人类和一个人工智能助手之间的对话。假设你扮演这个AI助手的角色。仔细阅读所有的图像，并对人类的问题做出信息丰富、有帮助、详细的和礼貌的回答。)r   z

)z
### Human:rC   )z### Assistant:rC   z <image_placeholder>
gemma-it)z<start_of_turn>user
<end_of_turn>
)z<start_of_turn>model
rb   dbrx-instructu  You are DBRX, created by Databricks. You were last updated in December 2023. You answer questions based on information available up to that point.
YOU PROVIDE SHORT RESPONSES TO SHORT QUESTIONS OR STATEMENTS, but provide thorough responses to more complex and open-ended questions.
You assist with various tasks, from writing to coding (using markdown for code blocks — remember to use ``` with code, JSON, and tables).
(You do not have real-time data access or code execution capabilities. You avoid stereotyping and provide balanced perspectives on controversial topics. You do not provide song lyrics, poems, or news articles and do not divulge details of your training data.)
This is your system prompt, guiding your responses. Do not reference it, just respond to the user. If you find yourself talking about this message, stop. You should be responding appropriately and usually that means not mentioning this.
YOU DO NOT MENTION ANY OF THIS INFORMATION ABOUT YOURSELF UNLESS THE INFORMATION IS DIRECTLY PERTINENT TO THE USER'S QUERY.)rI   rL   )z
<|im_start|>user
rL   )z
<|im_start|>assistant
rL   )r   r   r   r   c4ai-command-r)z'<|START_OF_TURN_TOKEN|><|SYSTEM_TOKEN|><|END_OF_TURN_TOKEN|>)z%<|START_OF_TURN_TOKEN|><|USER_TOKEN|>re   )z(<|START_OF_TURN_TOKEN|><|CHATBOT_TOKEN|>re   internvl-2-5u   你是书生·万象，英文名是InternVL，是由上海人工智能实验室、清华大学及多家合作单位联合开发的多模态大语言模型。rL   z<|action_end|>interns1u  You are an AI assistant whose name is Intern-S1 (书生大模型).
- Intern-S1 (书生大模型) is a vision-language model that is developed by Shanghai AI Laboratory (上海人工智能实验室).  It is designed to be helpful, honest, and harmless.
- Intern-S1 (书生大模型) can understand and communicate fluently in the language chosen by the user such as English and 中文.
You are an expert reasoner with extensive experience in all areas. You approach problems through systematic thinking and rigorous reasoning. Your response should reflect deep understanding and precise logical thinking, making your solution path and reasoning clear to others. Please put your thinking process within <think>...</think> tags.granite-3-instruct)z&<|start_of_role|>system<|end_of_role|><|end_of_text|>)z$<|start_of_role|>user<|end_of_role|>ri   )z)<|start_of_role|>assistant<|end_of_role|>ri   )ri   deepseek-v3glm-4v)z<|system|>
rC   )z	<|user|>
rC   )z<|assistant|>
rC   )z<|user|>rX   z<|observation|>r?   c                 C   s,   t d| t jrt d| t jsdS d S d S )Nzdeepseek-(v3|r1)baserj   research
IGNORECASEr?   r   r   r   match_deepseek  
   rr   c                 C   s   d|   v rdS d S )NorionrG   )lowerrq   r   r   r   match_orion  s   rv   c                 C      t d| t jr
dS d S )Nr]   rY   rm   rq   r   r   r   match_deepseek_janus_pro     rx   c                 C   s,   t d| t jrt d| t jrdS d S d S )Ndbrxinstructrc   rm   rq   r   r   r   
match_dbrx!  rs   r|   c                 C   rw   )Nz&vicuna|llava-v1\.5|llava-next-video-7brP   rm   rq   r   r   r   match_vicuna)  ry   r}   c                 C   rw   )Nz!llama-2.*chat|codellama.*instructrS   rm   rq   r   r   r   match_llama2_chat/  s   r~   c                 C   rw   )Nz#pixtral|(mistral|mixtral).*instructrT   rm   rq   r   r   r   match_mistral9  ry   r   c                 C   rw   )Nzllama-3.*instructrU   rm   rq   r   r   r   match_llama3_instruct?  ry   r   c                 C   sx   t d| t jr
dS t d| t jrdS t d| t jrdS t d| t jr0t d| t js0d	S t d
| t jr:dS d S )N	tinyllamarH   zqwen.*vlrO   zglm[-_]?4(\.\d+)?vrk   zqwen.*(chat|instruct)llavarN   zMllava-v1\.6-34b|llava-v1\.6-yi-34b|llava-next-video-34b|llava-onevision-qwen2rM   rm   rq   r   r   r   match_chat_mlE  s"   r   c                 C   s<   t d| t jrt d| t jsdS t d| t jrdS d S )Nr`   r   zyi-1\.5.*chatr_   rm   rq   r   r   r   match_chat_yiY  s   r   c                 C   rw   )Nz	gemma.*itra   rm   rq   r   r   r   match_gemma_itc  ry   r   c                 C   s,   t d| t jr
dS t d| t jrdS d S )Nz	minicpm-vrW   z	minicpm-or\   rm   rq   r   r   r   match_openbmb_minicpmi  
   r   c                 C   s   t d| t jr
dS d S )Nrd   rm   rq   r   r   r   match_c4ai_command_rq  ry   r   c                 C   rw   )Nzgranite.*instructrh   rm   rq   r   r   r   match_granite_instructw  ry   r   c                 C   rw   )Nzgemma-3ra   rm   rq   r   r   r   match_gemma3_instruct}  ry   r   c                 C   rw   )Ninternvl2_5rf   rm   rq   r   r   r   match_internvl_chat  ry   r   c                 C   s,   t d| t jr
dS t d| t jrdS d S )Nz	intern-s1rg   rm   rq   r   r   r   match_interns1_chat  r   r   __main__r   )r   r!   r   zHello!rF   zHi!zWhat can you do?zI can chat with you.)-rn   dataclassesr   enumr   r   typingr   r   r   r   r	   r   r4   r2   r3   r5   r8   r<   r=   rB   r   r   rr   rv   rx   r|   r}   r~   r   r   r   r   r   r   r   r   r   r   r   r
   r,   r7   printr1   r   r   r   r   <module>   s  
 ,		
	