11from unittest .mock import MagicMock
22
33from llama_api_client .types import CreateChatCompletionResponse
4- from requests import HTTPError # type:ignore
54
65from modelgauge .prompt import TextPrompt
7- from modelgauge .sut import SUTResponse , SUTOptions
8- from modelgauge .suts .meta_llama_client import (
9- MetaLlamaSUT ,
10- MetaLlamaChatRequest ,
11- InputMessage ,
12- MetaLlamaApiKey ,
13- )
6+ from modelgauge .sut import SUTOptions , SUTResponse
7+ from modelgauge .suts .meta_llama_client import InputMessage , MetaLlamaApiKey , MetaLlamaChatRequest , MetaLlamaSUT
8+ from pytest import fixture
9+ from requests import HTTPError # type:ignore
1410
1511llama_chat_response_text = """
1612{
4339"""
4440
4541
46- def make_sut ():
42+ @fixture
43+ def sut ():
4744 return MetaLlamaSUT ("ignored" , "a_model" , MetaLlamaApiKey ("whatever" ))
4845
4946
50- def test_translate_text_prompt ():
51- sut = make_sut ()
47+ def test_translate_text_prompt (sut ):
5248 sut_options = SUTOptions ()
5349 result = sut .translate_text_prompt (TextPrompt (text = "Why did the chicken cross the road?" ), sut_options )
5450 assert result == MetaLlamaChatRequest (
@@ -58,8 +54,7 @@ def test_translate_text_prompt():
5854 )
5955
6056
61- def test_translate_chat_response ():
62- sut = make_sut ()
57+ def test_translate_chat_response (sut ):
6358 request = MetaLlamaChatRequest (
6459 model = "a_model" ,
6560 messages = [InputMessage (role = "user" , content = "Why did the chicken cross the road?" )],
@@ -71,18 +66,16 @@ def test_translate_chat_response():
7166 )
7267
7368
74- def test_evaluate ():
75- sut = make_sut ()
69+ def test_evaluate (sut ):
7670 request = MetaLlamaChatRequest (
7771 model = "a_model" ,
7872 messages = [InputMessage (role = "user" , content = "Why did the chicken cross the road?" )],
7973 max_completion_tokens = 123 ,
8074 )
8175 sut .client = MagicMock ()
82- response = sut .evaluate (request )
76+ _ = sut .evaluate (request )
8377 assert sut .client .chat .completions .create .call_count == 1
8478 kwargs = sut .client .chat .completions .create .call_args .kwargs
85- print (kwargs )
8679 assert kwargs ["model" ] == "a_model"
8780 assert kwargs ["messages" ][0 ]["role" ] == "user"
8881 assert kwargs ["messages" ][0 ]["content" ] == "Why did the chicken cross the road?"
0 commit comments