fix: restrict tool-heavy/swe-bench tagging to software development or agent-related tasks
This commit is contained in:
@@ -1,6 +1,10 @@
|
|||||||
package server
|
package server
|
||||||
|
|
||||||
import "testing"
|
import (
|
||||||
|
"testing"
|
||||||
|
|
||||||
|
"gophergate/internal/router"
|
||||||
|
)
|
||||||
|
|
||||||
func TestIsSoftwareDevelopment(t *testing.T) {
|
func TestIsSoftwareDevelopment(t *testing.T) {
|
||||||
tests := []struct {
|
tests := []struct {
|
||||||
@@ -29,3 +33,68 @@ func TestIsSoftwareDevelopment(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestGetRouteCtxTags(t *testing.T) {
|
||||||
|
s := &Server{}
|
||||||
|
tests := []struct {
|
||||||
|
name string
|
||||||
|
routeCtx *router.RouteContext
|
||||||
|
expectedTags []string
|
||||||
|
mustContain []string
|
||||||
|
mustExclude []string
|
||||||
|
}{
|
||||||
|
{
|
||||||
|
name: "Standard query with tools",
|
||||||
|
routeCtx: &router.RouteContext{
|
||||||
|
UserMessage: "Search the web for weather in Paris",
|
||||||
|
RequiresToolCalling: true,
|
||||||
|
},
|
||||||
|
mustExclude: []string{"tool-heavy", "swe-bench"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Coding query with tools",
|
||||||
|
routeCtx: &router.RouteContext{
|
||||||
|
UserMessage: "Write a python script to parse logs",
|
||||||
|
RequiresToolCalling: true,
|
||||||
|
IsSoftwareDevelopment: true,
|
||||||
|
},
|
||||||
|
mustContain: []string{"tool-heavy", "swe-bench"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
name: "Agent query with tools",
|
||||||
|
routeCtx: &router.RouteContext{
|
||||||
|
UserMessage: "agent please orchestrate the multi-agent task",
|
||||||
|
RequiresToolCalling: true,
|
||||||
|
},
|
||||||
|
mustContain: []string{"tool-heavy", "swe-bench"},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, tt := range tests {
|
||||||
|
t.Run(tt.name, func(t *testing.T) {
|
||||||
|
tags := s.getRouteCtxTags(tt.routeCtx)
|
||||||
|
|
||||||
|
for _, expected := range tt.mustContain {
|
||||||
|
found := false
|
||||||
|
for _, tag := range tags {
|
||||||
|
if tag == expected {
|
||||||
|
found = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !found {
|
||||||
|
t.Errorf("expected tag %q to be present, but was not in %v", expected, tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for _, excluded := range tt.mustExclude {
|
||||||
|
for _, tag := range tags {
|
||||||
|
if tag == excluded {
|
||||||
|
t.Errorf("expected tag %q to be excluded, but was found in %v", excluded, tags)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -574,6 +574,31 @@ func (s *Server) handleChatCompletions(c *gin.Context) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Prune message history to sliding window if configured
|
||||||
|
if s.cfg.Server.MaxHistoryMessages > 0 && len(req.Messages) > s.cfg.Server.MaxHistoryMessages {
|
||||||
|
var systemMsgs []models.ChatMessage
|
||||||
|
var otherMsgs []models.ChatMessage
|
||||||
|
for _, msg := range req.Messages {
|
||||||
|
if msg.Role == "system" {
|
||||||
|
systemMsgs = append(systemMsgs, msg)
|
||||||
|
} else {
|
||||||
|
otherMsgs = append(otherMsgs, msg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
keepCount := s.cfg.Server.MaxHistoryMessages - len(systemMsgs)
|
||||||
|
if keepCount < 1 {
|
||||||
|
keepCount = 1
|
||||||
|
}
|
||||||
|
if len(otherMsgs) > keepCount {
|
||||||
|
startIndex := len(otherMsgs) - keepCount
|
||||||
|
otherMsgs = otherMsgs[startIndex:]
|
||||||
|
log.Printf("[DEBUG] Pruned message history: kept %d system messages and last %d messages (total %d out of %d)",
|
||||||
|
len(systemMsgs), len(otherMsgs), len(systemMsgs)+len(otherMsgs), len(req.Messages))
|
||||||
|
req.Messages = append(systemMsgs, otherMsgs...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Strip common prefixes and prepare model ID
|
// Strip common prefixes and prepare model ID
|
||||||
modelID := req.Model
|
modelID := req.Model
|
||||||
prefixes := []string{"gemini/", "google/", "openai/", "deepseek/", "moonshot/", "grok/", "ollama/", "xiaomi/"}
|
prefixes := []string{"gemini/", "google/", "openai/", "deepseek/", "moonshot/", "grok/", "ollama/", "xiaomi/"}
|
||||||
@@ -1119,7 +1144,15 @@ func (s *Server) getRouteCtxTags(routeCtx *router.RouteContext) []string {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if routeCtx.RequiresToolCalling {
|
hasHeavyLogic := false
|
||||||
|
for _, tag := range tags {
|
||||||
|
if tag == "heavy-logic" {
|
||||||
|
hasHeavyLogic = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if routeCtx.RequiresToolCalling && (routeCtx.IsSoftwareDevelopment || hasHeavyLogic) {
|
||||||
tags = append(tags, "tool-heavy", "multi-step-agent", "swe-bench")
|
tags = append(tags, "tool-heavy", "multi-step-agent", "swe-bench")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user