@@ -18,51 +18,61 @@ def _make_chat_response(content):
1818 return response
1919
2020
21- def test_simple_gpt_returns_model_content (mocker ):
22- """simple_gpt returns the text content from the g4f response."""
21+ def test_free_gpt_returns_model_content (mocker ):
22+ """FreeGpt.call_llm returns the text content from the g4f response."""
2323 mock_client = Mock ()
2424 mock_client .chat .completions .create .return_value = _make_chat_response (
2525 "Great surf day!"
2626 )
2727 mocker .patch ("src.gpt.Client" , return_value = mock_client )
2828
29- result = gpt .simple_gpt ("surf is 4ft" , "what board should I ride?" )
29+ result = gpt .FreeGpt ("gpt-3.5-turbo" ).call_llm (
30+ "surf is 4ft" , "what board should I ride?"
31+ )
3032
3133 assert result == "Great surf day!"
3234 mock_client .chat .completions .create .assert_called_once ()
3335
3436
35- def test_simple_gpt_returns_fallback_on_exception (mocker ):
36- """simple_gpt returns the error string when the g4f client raises."""
37- mocker .patch ("src.gpt.Client" , side_effect = Exception ("API down" ))
37+ def test_free_gpt_returns_fallback_on_exception (mocker ):
38+ """FreeGpt.call_llm returns the error string when the client raises."""
39+ mock_client = Mock ()
40+ mock_client .chat .completions .create .side_effect = Exception ("API down" )
41+ mocker .patch ("src.gpt.Client" , return_value = mock_client )
3842
39- result = gpt .simple_gpt ("surf is 4ft" , "what board?" )
43+ result = gpt .FreeGpt ("gpt-3.5-turbo" ).call_llm (
44+ "surf is 4ft" , "what board?"
45+ )
4046
4147 assert result == "Unable to generate GPT response."
4248
4349
44- def test_openai_gpt_returns_model_content (mocker ):
45- """openai_gpt returns the text content from the OpenAI response."""
50+ def test_openai_llm_returns_model_content (mocker ):
51+ """OpenAILlm.call_llm returns the text content from the OpenAI response."""
4652 mock_client = Mock ()
4753 mock_client .chat .completions .create .return_value = _make_chat_response (
4854 "Bring your longboard."
4955 )
5056 mocker .patch ("src.gpt.OpenAI" , return_value = mock_client )
5157
52- result = gpt .openai_gpt (
53- "surf is 2ft" , "recommend a board" , "sk-testkey" , "gpt-4"
58+ result = gpt .OpenAILlm ( "sk-testkey" , "gpt-4" ). call_llm (
59+ "surf is 2ft" , "recommend a board"
5460 )
5561
5662 assert result == "Bring your longboard."
5763 mock_client .chat .completions .create .assert_called_once ()
5864
5965
60- def test_openai_gpt_returns_fallback_on_exception (mocker ):
61- """openai_gpt returns the error string when the OpenAI client raises."""
62- mocker .patch ("src.gpt.OpenAI" , side_effect = Exception ("quota exceeded" ))
66+ def test_openai_llm_returns_fallback_on_exception (mocker ):
67+ """OpenAILlm.call_llm returns the error string when the client raises."""
68+ mock_client = Mock ()
69+ mock_client .chat .completions .create .side_effect = Exception (
70+ "quota exceeded"
71+ )
72+ mocker .patch ("src.gpt.OpenAI" , return_value = mock_client )
6373
64- result = gpt .openai_gpt (
65- "surf is 2ft" , "recommend a board" , "sk-key" , "gpt-4"
74+ result = gpt .OpenAILlm ( "sk-key" , "gpt-4" ). call_llm (
75+ "surf is 2ft" , "recommend a board"
6676 )
6777
6878 assert result == "Unable to generate GPT response."
0 commit comments