LLM response models for prompting and response validation

This commit is contained in:
2026-10-02 22:36:19 +02:00
parent 3b93c5988b
commit 3754b3e4a9
4 changed files with 136 additions and 53 deletions
+6 -10
View File
@@ -21,9 +21,7 @@ def test_llm_session_mocked(test_photo):
mock_choice = MagicMock()
mock_message = MagicMock()
mock_message.content = (
'{"caption": "A beautiful sunset", "tags": ["sunset", "nature"]}'
)
mock_message.content = '{"text": "some text"}'
mock_choice.message = mock_message
mock_response.choices = [mock_choice]
@@ -39,11 +37,9 @@ def test_llm_session_mocked(test_photo):
)
# Verify the results
assert result["caption"] == "A beautiful sunset"
assert "sunset" in result["tags"]
assert "nature" in result["tags"]
assert result.text == "some text"
# Verify that the mock was called
# Verify that the mock was enough
assert mock_client.chat.completions.create.called
@@ -65,7 +61,7 @@ def test_llm_session_captions_and_keywords_mocked(test_photo):
mock_choice = MagicMock()
mock_message = MagicMock()
mock_message.content = '{"caption": "A mocked caption", "tags": ["mocked_tag"]}'
mock_message.content = '{"caption": "A mocked caption", "tags": ["architektur"]}'
mock_choice.message = mock_message
mock_response.choices = [mock_choice]
@@ -81,8 +77,8 @@ def test_llm_session_captions_and_keywords_mocked(test_photo):
result = mocked_session.call(photos=[test_photo])
# Verify the results
assert result["caption"] == "A mocked caption"
assert "mocked_tag" in result["tags"]
assert result.caption == "A mocked caption"
assert "architektur" in result.tags
# Verify that the mock was called
assert mock_client.chat.completions.create.called