mirror of
https://github.com/tiennm99/goclaw.git
synced 2026-10-11 03:13:24 +00:00
Ollama has two separate request-building code paths: OllamaProvider (native /api/chat, used for num_ctx control) and OpenAIProvider (OpenAI-compat /v1/chat/completions). An earlier fix disabled thinking mode by hardcoding think=false, but only in the OpenAI-compat path -- OllamaProvider.buildRequest() never set the think field at all, so reasoning-capable models (qwq, deepseek-r1) defaulted to visible chain-of-thought reasoning regardless of that fix. Confirmed live via a docker-engineer agent streaming full reasoning traces despite the existing disable. Replaced the hardcoded always-off behavior with a provider-level tri-state setting (llm_providers.settings.thinking_enabled: unset = default off, explicit true/false overrides), configurable via the provider's Advanced settings dialog. Both OllamaProvider.buildRequest() and OpenAIProvider.buildRequestBody() now read and respect this same setting, so the toggle works regardless of which Ollama code path a given deployment routes through. Added tests for setting parsing (unset/true/false/malformed) and both provider request-builders' handling of the override. Co-authored-by: Bruno Clermont <bruno.clermont@gmail.com>
69 lines
1.3 KiB
Go
69 lines
1.3 KiB
Go
package store
|
|
|
|
import (
|
|
"encoding/json"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestParseThinkingEnabled(t *testing.T) {
|
|
trueVal := true
|
|
falseVal := false
|
|
|
|
tests := []struct {
|
|
name string
|
|
settings json.RawMessage
|
|
want *bool
|
|
}{
|
|
{
|
|
name: "unset settings",
|
|
settings: nil,
|
|
want: nil,
|
|
},
|
|
{
|
|
name: "empty object",
|
|
settings: json.RawMessage(`{}`),
|
|
want: nil,
|
|
},
|
|
{
|
|
name: "explicit true",
|
|
settings: json.RawMessage(`{"thinking_enabled":true}`),
|
|
want: &trueVal,
|
|
},
|
|
{
|
|
name: "explicit false",
|
|
settings: json.RawMessage(`{"thinking_enabled":false}`),
|
|
want: &falseVal,
|
|
},
|
|
{
|
|
name: "coexists with other settings keys",
|
|
settings: json.RawMessage(`{"num_ctx":8192,"thinking_enabled":true}`),
|
|
want: &trueVal,
|
|
},
|
|
{
|
|
name: "malformed json",
|
|
settings: json.RawMessage(`{not valid json`),
|
|
want: nil,
|
|
},
|
|
{
|
|
name: "wrong type is ignored",
|
|
settings: json.RawMessage(`{"thinking_enabled":"yes"}`),
|
|
want: nil,
|
|
},
|
|
}
|
|
|
|
for _, tc := range tests {
|
|
t.Run(tc.name, func(t *testing.T) {
|
|
got := ParseThinkingEnabled(tc.settings)
|
|
if tc.want == nil {
|
|
assert.Nil(t, got)
|
|
return
|
|
}
|
|
require.NotNil(t, got)
|
|
assert.Equal(t, *tc.want, *got)
|
|
})
|
|
}
|
|
}
|