o
    wi                      @   st   d dl mZmZ d dlZd dlZd dlmZmZm	Z	m
Z
 G dd dZG dd dZG dd	 d	ZG d
d dZdS )    )	MagicMockpatchN)NemoQueryLLMNemoQueryLLMBaseNemoQueryLLMHFNemoQueryLLMPyTorchc                   @   s   e Zd Zdd ZdS )TestNemoQueryLLMBasec                 C   s4   d}d}t ||d}|j|ksJ |j|ksJ d S Nlocalhost:8000
test-model)url
model_name)r   r   r   )selfr   r   query r   X/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/tests/deploy/test_query_llm.pytest_base_initialization   s
   z-TestNemoQueryLLMBase.test_base_initializationN)__name__
__module____qualname__r   r   r   r   r   r      s    r   c                   @   B   e Zd Zejdd Zdd Zeddd Zeddd	 Z	d
S )TestNemoQueryLLMPyTorchc                 C      t dddS r	   )r   r   r   r   r   r   !      zTestNemoQueryLLMPyTorch.queryc                 C   .   t |tsJ |jdksJ |jdksJ d S Nr
   r   
isinstancer   r   r   r   r   r   r   r   test_initialization%      z+TestNemoQueryLLMPyTorch.test_initialization%nemo.deploy.nlp.query_llm.ModelClientc                 C      t  }||jj_dtdgi|j_t tjdg|j_|j	dgddddd	}t
|ts-J d
|v s3J |d
 d d dks?J d S N	sentences   test responsedtypetest promptd   ffffff?   ?)prompts
max_lengthtemperaturetop_ktop_pchoicesr   texttest responser   return_value	__enter__nparrayinfer_batchbytes_model_configoutputs	query_llmr   dictr   mock_clientr   mock_instanceresponser   r   r   test_query_llm_basic*      
z,TestNemoQueryLLMPyTorch.test_query_llm_basicc                 C   s   t  }||jj_tdgtg dd|j_t tjdg|j_|j	dgddd}d	|d
 d v s4J d|d
 d d	 v s@J d S )Nr&   g?g?g333333?)r%   	log_probsr'   r)   r*   T)r.   r/   compute_logproblogprobsr3   r   token_logprobs
r   r7   r8   r9   r:   r;   r<   r=   r>   r?   rA   r   r   r   test_query_llm_with_logprobs9   s   


z4TestNemoQueryLLMPyTorch.test_query_llm_with_logprobsN)
r   r   r   pytestfixturer   r    r   rE   rM   r   r   r   r   r           

r   c                   @   r   )TestNemoQueryLLMHFc                 C   r   r	   )r   r   r   r   r   r   L   r   zTestNemoQueryLLMHF.queryc                 C   r   r   r   r   r   r   r   r    P   r!   z&TestNemoQueryLLMHF.test_initializationr"   c                 C   r#   r$   r6   rA   r   r   r   rE   U   rF   z'TestNemoQueryLLMHF.test_query_llm_basicc                 C   sf   t  }||jj_tdgtg dgd|j_t tjdg|j_|j	dgddd}d	|v s1J d S )
Nr&   rG   )r%   logitsr'   r)   r*   T)r.   r/   output_logitsrR   rL   rA   r   r   r   test_query_llm_with_logitsd   s   


z-TestNemoQueryLLMHF.test_query_llm_with_logitsN)
r   r   r   rN   rO   r   r    r   rE   rT   r   r   r   r   rQ   K   rP   rQ   c                   @   sr   e Zd Zejdd Zdd Zeddd Zeddd	 Z	ed
dd Z
eddd Zeddd ZdS )TestNemoQueryLLMc                 C   r   r	   )r   r   r   r   r   r   v   r   zTestNemoQueryLLM.queryc                 C   r   r   r   r   r   r   r   r    z   r!   z$TestNemoQueryLLM.test_initializationr"   c                 C   sr   t  }||jj_dtdgi|j_t tjdg|j_|j	dgddddd	}t
|d
 ts/J |d
 dks7J d S )Nr>   r&   r'   r)   r*   r+   r,   r-   )r.   max_output_lenr0   r1   r2   r   r5   r   r7   r8   r9   r:   r;   r<   r=   r>   r?   r   strrA   r   r   r   rE      s   
z%TestNemoQueryLLM.test_query_llm_basicc                 C   s~   t  }||jj_dtdgi|j_t tjdg|j_|j	dgddd}t
|ts+J d|v s1J |d d	 d
 dks=J d S )Nr>   r&   r'   r)   r*   T)r.   rV   openai_format_responser3   r   r4   r5   r6   rA   r   r   r   test_query_llm_openai_format   s   
z-TestNemoQueryLLM.test_query_llm_openai_formatz.nemo.deploy.nlp.query_llm.DecoupledModelClientc                 C   s   t  }||jj_dtdgidtdgig|j_t tjdg|j_t	|j
dgdd}t|dks5J |d	 d
ks=J |d dksEJ d S )Nr>   s   tests	    responser'   r)   r*   )r.   rV      r   testr,   z	 response)r   r7   r8   r9   r:   r;   r<   r=   r>   listquery_llm_streaminglen)r   rB   r   rC   	responsesr   r   r   test_query_llm_streaming   s   
z)TestNemoQueryLLM.test_query_llm_streamingc                 C   p   t  }||jj_dtdgi|j_t tjdg|j_|j	dgddgd}t
|d ts.J |d d	ks6J d S )
Nr>   r&   r'   r)   r*   stop)r.   rV   stop_words_listr   r5   rW   rA   r   r   r   test_query_llm_with_stop_words      
z/TestNemoQueryLLM.test_query_llm_with_stop_wordsc                 C   rb   )
Nr>   r&   r'   r)   r*   bad)r.   rV   bad_words_listr   r5   rW   rA   r   r   r   test_query_llm_with_bad_words   rf   z.TestNemoQueryLLM.test_query_llm_with_bad_wordsN)r   r   r   rN   rO   r   r    r   rE   rZ   ra   re   ri   r   r   r   r   rU   u   s    




rU   )unittest.mockr   r   numpyr9   rN   nemo.deploy.nlp.query_llmr   r   r   r   r   r   rQ   rU   r   r   r   r   <module>   s   	+*