o
    }oi                     @   s^   d Z ddlZddlZddlmZmZmZ ddlmZ ddddd	igd
Z	dd Z
dd ZdS )zUtilities for adapter testing.    N)Flaskjsonifyrequest)wait_for_serverzchat.completionmessage	assistantz:This is a fake LLM response</think>This survives reasoning)rolecontent)objectchoicesc                  C   s2   t t} | jddgddd }| jddd d	S )
z*Create and run a fake OpenAI API endpoint.z/v1/chat/completionsPOST)methodsc                  S   s*   t j} d| v r| d }t|S t}t|S )Nfake_response)r   jsonDEFAULT_FAKE_RESPONSEr   )dataresponse r   X/home/ubuntu/.local/lib/python3.10/site-packages/tests/evaluation/adapters/test_utils.pychat_completion*   s   z5create_and_run_fake_endpoint.<locals>.chat_completion	localhost  )hostportN)r   __name__routerun)appr   r   r   r   create_and_run_fake_endpoint&   s   
r   c                  C   s4   t jtd} |   tdds|   td | S )zCreate a process running a fake OpenAI endpoint.

    Returns:
        The multiprocessing.Process object running the endpoint.
    )targetr   r   z<Fake OpenAI endpoint did not start within the timeout period)multiprocessingProcessr   startr   	terminatepytestfail)pr   r   r   create_fake_endpoint_process6   s   

r'   )__doc__r    r$   flaskr   r   r   .nemo.collections.llm.evaluation.adapters.utilsr   r   r   r'   r   r   r   r   <module>   s   