Skip to content

Commit 428bf18

Browse files
committed
version update
1 parent 3d0330a commit 428bf18

4 files changed

Lines changed: 35 additions & 24 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "cli-surf"
3-
version = "2.3.1"
3+
version = "2.4.0"
44
description = "Command-line surf report tool"
55
license = "MIT"
66
authors = ["ryansurf <your@email.com>"] # TODO: email

src/gpt.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313

1414

1515
class Llm(ABC):
16-
1716
def __init__(self, model):
1817
self.model = model
1918
self.client: Any = None
@@ -22,7 +21,9 @@ def call_llm(self, surf_summary, gpt_prompt) -> str | None:
2221
try:
2322
response = self.client.chat.completions.create(
2423
model=self.model,
25-
messages=[{"role": "user", "content": surf_summary + gpt_prompt}],
24+
messages=[
25+
{"role": "user", "content": surf_summary + gpt_prompt}
26+
],
2627
)
2728
return response.choices[0].message.content
2829
except Exception as e:

tests/test_gpt.py

Lines changed: 26 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -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."

tests/test_helper.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,19 +426,19 @@ def test_set_location_unpacks_dict():
426426

427427

428428
def test_print_gpt_uses_openai_when_key_is_long_enough(mocker):
429-
"""print_gpt calls openai_gpt when the API key is at least 5 chars."""
429+
"""print_gpt uses OpenAILlm when the API key is at least 5 chars."""
430430
surf_data = {
431431
"Location": "Santa Cruz",
432432
"Height": "3",
433433
"Swell Direction": "270",
434434
"Period": "12",
435435
"Unit": "ft",
436436
}
437-
mock_openai = mocker.patch(
438-
"src.helper.gpt.openai_gpt", return_value="openai response"
439-
)
437+
mock_llm = mocker.MagicMock()
438+
mock_llm.call_llm.return_value = "openai response"
439+
mocker.patch("src.helper.gpt.OpenAILlm", return_value=mock_llm)
440440
result = helper.print_gpt(
441441
surf_data, "any prompt", ("sk-validkey", "gpt-4")
442442
)
443443
assert result == "openai response"
444-
mock_openai.assert_called_once()
444+
mock_llm.call_llm.assert_called_once()

0 commit comments

Comments
 (0)