Commit fca7ac2
authored
fix(prompt): accept text/plain Content-Type on Ollama non-streaming responses (#1887)
Ollama sometimes replies to non-streaming `/api/chat` requests with
`Content-Type: text/plain; charset=utf-8` even though the body is valid
JSON. Ktor's `ContentNegotiation` plugin was only registered for
`application/json`, so the response failed with
`NoTransformationFoundException` before reaching
`OllamaChatResponseDTO`.
### Change
Register the same JSON deserializer for `text/plain` alongside
`application/json` in the Ollama client's `ContentNegotiation` config.
Streaming responses are unaffected — they read the body as a raw channel
and bypass content negotiation.
### Test
- Extended `MockOllamaChatServer` to allow overriding the response
`Content-Type`.
- Added `OllamaContentTypeTest` that sends a `text/plain; charset=utf-8`
reply and asserts the body is still parsed into an assistant message.
The test fails on `develop` without the fix and passes with it.
closes #12371 parent bb801c9 commit fca7ac2
3 files changed
Lines changed: 50 additions & 1 deletion
File tree
- prompt/prompt-executor/prompt-executor-clients/prompt-executor-ollama-client/src
- commonMain/kotlin/ai/koog/prompt/executor/ollama/client
- commonTest/kotlin/ai/koog/prompt/executor/ollama/client
Lines changed: 4 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
151 | 151 | | |
152 | 152 | | |
153 | 153 | | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
154 | 158 | | |
155 | 159 | | |
156 | 160 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
12 | 12 | | |
13 | 13 | | |
14 | 14 | | |
| 15 | + | |
15 | 16 | | |
16 | 17 | | |
17 | 18 | | |
| |||
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | | - | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
Lines changed: 44 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
0 commit comments