Skip to content

Commit

Permalink
Fix for error on self._prompt is None
Browse files Browse the repository at this point in the history
  • Loading branch information
simonw committed Feb 18, 2025
1 parent e32487e commit 4ab31d8
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 22 deletions.
2 changes: 1 addition & 1 deletion llm/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ def __init__(

@property
def prompt(self):
return "\n".join(self.fragments + [self._prompt])
return "\n".join(self.fragments + ([self._prompt] if self._prompt else []))

@property
def system(self):
Expand Down
4 changes: 2 additions & 2 deletions tests/test_cli_openai_models.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ def test_only_gpt4_audio_preview_allows_mp3_or_wav(httpx_mock, model, filetype):
else:
assert result.exit_code == 1
long = "audio/mpeg" if filetype == "mp3" else "audio/wav"
assert (
f"This model does not support attachments of type '{long}'" in result.output
assert f"This model does not support attachments of type '{long}'" in str(
result
)


Expand Down
37 changes: 18 additions & 19 deletions tests/test_llm.py
Original file line number Diff line number Diff line change
Expand Up @@ -529,25 +529,24 @@ def test_openai_completion(mocked_openai_completion, user_path):

def test_openai_completion_system_prompt_error():
runner = CliRunner()
result = runner.invoke(
cli,
[
"-m",
"gpt-3.5-turbo-instruct",
"Say this is a test",
"--no-stream",
"--key",
"x",
"--system",
"system prompts not allowed",
],
catch_exceptions=False,
)
assert result.exit_code == 1
assert (
result.output
== "Error: System prompts are not supported for OpenAI completion models\n"
)
with pytest.raises(NotImplementedError) as ex:
runner.invoke(
cli,
[
"-m",
"gpt-3.5-turbo-instruct",
"Say this is a test",
"--no-stream",
"--key",
"x",
"--system",
"system prompts not allowed",
],
catch_exceptions=False,
)
assert "System prompts are not supported for OpenAI completion models" in str(
ex
)


def test_openai_completion_logprobs_stream(
Expand Down

0 comments on commit 4ab31d8

Please sign in to comment.