You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 008d40a
Browse filesBrowse the repository at this point in the historyBrowse files
.Net: feat(ollama): add Think property to OllamaPromptExecutionSettings (#14122)
## Summary
- Adds `Think` (`bool?`) property to `OllamaPromptExecutionSettings` to
control thinking for Ollama reasoning models (deepseek-r1, qwen3,
phi4-reasoning)
- Maps `Think` to `GenerateRequest.Think` in
`OllamaTextGenerationService.CreateRequest()`
- Bumps OllamaSharp from 5.4.12 to 5.4.25 which introduces
`GenerateRequest.Think`
## Motivation
Fixes#14078. When a reasoning model has thinking enabled by default
(e.g. qwen3, phi4-reasoning), the model output lands in a separate
thinking stream rather than the standard response field. This causes
`GetTextContentsAsync` to return empty content. The only way to get a
usable response is to pass `think=false` to suppress thinking, but there
was no way to set that from `OllamaPromptExecutionSettings`.
## Changes
### `OllamaPromptExecutionSettings.cs`
- New `Think` property with `bool?` type, JSON name `think`,
`WhenWritingNull` ignore condition, `ThrowIfFrozen()` guard, and
`Clone()` support
### `OllamaTextGenerationService.cs`
- `CreateRequest()` maps `settings.Think` to `GenerateRequest.Think`
using `OllamaSharp.Models.Chat.ThinkValue`
### `Directory.Packages.props`
- OllamaSharp bumped from 5.4.12 to 5.4.25 (adds `GenerateRequest.Think`
and `ThinkValue`)
### Tests
- `OllamaPromptExecutionSettingsTests`: serialization round-trip, Clone,
Freeze guard for `Think`
- `OllamaTextGenerationTests`: verifies `Think` is present/absent in the
serialized request payload for both `GetTextContentsAsync` and
`GetStreamingTextContentsAsync`
## Test plan
- [ ] All 115 existing unit tests pass (1 pre-existing skip)
- [ ] `ThinkPropertyRoundTripsViaSerialization` - `true`/`false`
round-trips via JSON
- [ ] `ThinkPropertyIsPreservedByClone` - Clone copies the value
- [ ] `ThinkPropertyThrowsWhenFrozen` - setter throws after Freeze
- [ ] `GetTextContentsShouldSendThinkSettingAsync` - request payload
contains correct `think` field
- [ ] `GetTextContentsShouldNotSendThinkWhenNotSetAsync` - request
payload omits `think` when null
- [ ] `GetStreamingTextContentsShouldSendThinkSettingAsync` - streaming
path also sends `think`
---------
Co-authored-by: Roger Barreto <19890735+rogerbarreto@users.noreply.github.com>
0 commit comments