o
    پi                     @   s&   d dl Z d dlZdZG dd dZdS )    NaH  
Please write an extremely detailed and vivid fantasy story, set in a world full of intricate magic systems, political intrigue, and complex characters.
Ensure that you thoroughly describe every scene, character's motivations, and the environment. Include long, engaging dialogues and elaborate on the inner thoughts of the characters.
Each section should be as comprehensive as possible to create a rich and immersive experience for the reader.
The story should span multiple events, challenges, and character developments over time. Aim to make the story at least 3,000 words long.
c                   @   sX   e Zd ZedddddfddZedddddfddZdd Zd	d
 Zdd Zdd Z	dS )MatchedStopMixin   Nc           
      C   s   || j dd|d}|d ur||d< |d ur||d< tj| jd |d}| }	tt|	 td t|ts:|g}|	d	 d d
 |ksTJ d| d|	d	 d d
  |	d	 d d |v snJ d| d|	d	 d d  d S )Nr   r   )promptmodeltemperaturetop_p
max_tokensstop
stop_regexz/v1/completionsjsond====================================================================================================choicesfinish_reasonExpected finish_reason: , but got: matched_stopExpected matched_stop: 	r   requestspostbase_urlr   printdumps
isinstancelist)
selfr   r   r	   r
   r   r   payloadresponse_completionsres r    U/home/ubuntu/.local/lib/python3.10/site-packages/sglang/test/kits/matched_stop_kit.py_run_completions_generation   s2   

z,MatchedStopMixin._run_completions_generationc           
      C   s   | j dddd|dgdd|d}|d ur||d< |d ur!||d	< tj| jd
 |d}| }	tt|	 td t|tsB|g}|	d d d |ks\J d| d|	d d d  |	d d d |v svJ d| d|	d d d  d S )NsystemzYou are a helpful AI assistant)rolecontentuserr   r   )r   messagesr   r   r   r	   r
   z/v1/chat/completionsr   r   r   r   r   r   r   r   r   )
r   r   r   r	   r
   r   r   chat_payloadresponse_chatr   r    r    r!    _run_chat_completions_generation7   s6   

z1MatchedStopMixin._run_chat_completions_generationc                 C   s(   | j ddddd | jddddd d S )N  
r	   )r   r	   r   r   r"   r*   r   r    r    r!   test_finish_stop_strc   s   
z%MatchedStopMixin.test_finish_stop_strc                 C   sB   d}| j d|d|d | jd|d|d d}| jd|d|d d S )Nzand|orr+   r	   )r   r
   r   r   z	[.!?]\s*$r-   )r   STOP_REGEX_STRSTOP_REGEX_STR_SENTENCEr    r    r!   test_finish_stop_regex_strk   s(   
z+MatchedStopMixin.test_finish_stop_regex_strc                 C   s4   d}g d}| j |dd|d | jddd|d d S )Nz<|begin_of_text|><|start_header_id|>system<|end_header_id|>
You are a helpful assistant.<|eot_id|><|start_header_id|>user<|end_header_id|>
What is 2 + 2?<|eot_id|><|start_header_id|>assistant<|end_header_id|>
        )i  i	    r+   r	   )r   r   r   r   zWhat is 2 + 2?r-   )r   llama_format_prompteos_token_idsr    r    r!   test_finish_stop_eos   s   
z%MatchedStopMixin.test_finish_stop_eosc                 C   s$   | j ddd d | jddd d d S )N   length)r   r   r   r-   r.   r    r    r!   test_finish_length   s   
z#MatchedStopMixin.test_finish_length)
__name__
__module____qualname__MANY_NEW_TOKENS_PROMPTr"   r*   r/   r2   r6   r9   r    r    r    r!   r      s&    
+
,r   )r   r   r=   r   r    r    r    r!   <module>   s    