a3a6f765e7
Schema: Added logic_level (INTEGER) and primary_use (TEXT) columns to model_groups table with auto-migration for existing databases. Seed: Three new default groups: heavy-logic (level 9) — Complex Coding, Logic, Agents standard-pro (level 5) — General Assistant, Long Docs fast-flow (level 2) — Classification, JSON, Basic Q&A Admin API: INSERT/UPDATE handlers now accept and persist the new fields. Dashboard: Table shows Level and Primary Use columns; form includes both fields with appropriate inputs and placeholders.
77 lines
2.2 KiB
Go
77 lines
2.2 KiB
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"gophergate/internal/db"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (s *Server) handleGetModelGroups(c *gin.Context) {
|
|
var groups []db.ModelGroup
|
|
if err := s.database.Select(&groups, "SELECT * FROM model_groups ORDER BY id"); err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
if groups == nil {
|
|
groups = []db.ModelGroup{}
|
|
}
|
|
c.JSON(http.StatusOK, SuccessResponse(groups))
|
|
}
|
|
|
|
func (s *Server) handleCreateModelGroup(c *gin.Context) {
|
|
var group db.ModelGroup
|
|
if err := c.ShouldBindJSON(&group); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
_, err := s.database.Exec(`
|
|
INSERT INTO model_groups (id, strategy, selector_model, targets, complexity_threshold, heuristic_rules, logic_level, primary_use)
|
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)`,
|
|
group.ID, group.Strategy, group.SelectorModel, group.Targets,
|
|
group.ComplexityThreshold, group.HeuristicRules, group.LogicLevel, group.PrimaryUse)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
s.refreshRouter()
|
|
c.JSON(http.StatusCreated, SuccessResponse(group))
|
|
}
|
|
|
|
func (s *Server) handleUpdateModelGroup(c *gin.Context) {
|
|
id := c.Param("id")
|
|
var group db.ModelGroup
|
|
if err := c.ShouldBindJSON(&group); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
_, err := s.database.Exec(`
|
|
UPDATE model_groups SET strategy=?, selector_model=?, targets=?, complexity_threshold=?, heuristic_rules=?, logic_level=?, primary_use=?, updated_at=CURRENT_TIMESTAMP
|
|
WHERE id=?`,
|
|
group.Strategy, group.SelectorModel, group.Targets,
|
|
group.ComplexityThreshold, group.HeuristicRules, group.LogicLevel, group.PrimaryUse, id)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
s.refreshRouter()
|
|
c.JSON(http.StatusOK, SuccessResponse(group))
|
|
}
|
|
|
|
func (s *Server) handleDeleteModelGroup(c *gin.Context) {
|
|
id := c.Param("id")
|
|
_, err := s.database.Exec("DELETE FROM model_groups WHERE id=?", id)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
|
|
return
|
|
}
|
|
|
|
s.refreshRouter()
|
|
c.JSON(http.StatusOK, gin.H{"status": "deleted"})
|
|
}
|