This commit is contained in:
Patrick Devine 2025-10-08 01:24:17 +02:00 committed by GitHub
commit e02c487dbb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 17 additions and 2 deletions

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)
}