Compare commits

...

1 Commits

Author SHA1 Message Date
Patrick Devine
f580006d10 thinking: force newer qwen3 models to always use thinking 2025-10-06 22:40:01 -07:00

View File

@@ -63,6 +63,15 @@ func shouldUseHarmony(model *Model) bool {
return false
}
func shouldForceThinking(model *Model) bool {
if model.Config.ModelFamily == "qwen3" && strings.Contains(model.Name, "thinking-2507") {
// Force thinking mode for the newer qwen3 thinking models otherwise they end up
// leaving the thinking trace in the return content w/ unmatched <think></think> tags
return true
}
return false
}
func experimentEnabled(name string) bool {
return slices.Contains(strings.Split(os.Getenv("OLLAMA_EXPERIMENT"), ","), name)
}
@@ -330,7 +339,10 @@ func (s *Server) GenerateHandler(c *gin.Context) {
if req.Suffix != "" {
caps = append(caps, model.CapabilityInsert)
}
if req.Think != nil && req.Think.Bool() {
if req.Think == nil && shouldForceThinking(m) {
req.Think = &api.ThinkValue{Value: true}
caps = append(caps, model.CapabilityThinking)
} else if req.Think != nil && req.Think.Bool() {
caps = append(caps, model.CapabilityThinking)
// TODO(drifkin): consider adding a warning if it's false and the model
// doesn't support thinking. It's not strictly required, but it can be a
@@ -1871,7 +1883,10 @@ func (s *Server) ChatHandler(c *gin.Context) {
if len(req.Tools) > 0 {
caps = append(caps, model.CapabilityTools)
}
if req.Think != nil && req.Think.Bool() {
if req.Think == nil && shouldForceThinking(m) {
req.Think = &api.ThinkValue{Value: true}
caps = append(caps, model.CapabilityThinking)
} else if req.Think != nil && req.Think.Bool() {
caps = append(caps, model.CapabilityThinking)
}