feat: Handle empty Ollama responses gracefully

Introduce `OllamaError::EmptyResponse` to represent cases where the
Ollama
model returns an empty result due to silence rules or lack of keywords.

This change prevents treating an empty response as a parse error and
logs
it at a lower severity level. A new integration test verifies this
behavior.
This commit is contained in:
2026-04-20 11:24:44 +02:00
parent 3ad8c4c2e9
commit 224ee60363
4 changed files with 47 additions and 3 deletions
+25
View File
@@ -500,6 +500,31 @@ async fn ollama_oneliner_sends_keep_alive_and_model() {
// Mock::expect(1) + server drop verifies the matcher hit exactly once.
}
#[tokio::test]
async fn ollama_oneliner_empty_response_when_model_obeys_silence_rule() {
// Model followed the silence rule for a keyword-less transcript and
// returned empty content. That's a valid outcome, not a parse error.
let server = MockServer::start().await;
Mock::given(method("POST"))
.and(path("/api/chat"))
.respond_with(ResponseTemplate::new(200).set_body_json(ok_chat_body(" \n ")))
.mount(&server)
.await;
let client = reqwest::Client::new();
let err = generate_oneliner(
&client,
&server.uri(),
MODEL,
0,
"äh, Moment",
Duration::from_secs(5),
)
.await
.expect_err("expected EmptyResponse");
assert!(matches!(err, OllamaError::EmptyResponse), "got {err:?}");
}
#[tokio::test]
async fn ollama_oneliner_parse_error_on_missing_content() {
let server = MockServer::start().await;