Agnes 2.0-flash是推理模型,推理token占大量预算。 800仍不够→JSON截断(parse error: unexpected end of JSON input)。 1200确保推理+正文都够用。
72 lines
1.6 KiB
Go
72 lines
1.6 KiB
Go
// 织忆 MemoryWeave — 知识缺口 API
|
|
package routes
|
|
|
|
import (
|
|
"encoding/json"
|
|
"net/http"
|
|
|
|
"github.com/xiaoxue/memoryweave/internal/selfoptimize"
|
|
)
|
|
|
|
type GapAPI struct {
|
|
Detector *selfoptimize.GapDetector
|
|
}
|
|
|
|
func NewGapAPI(d *selfoptimize.GapDetector) *GapAPI {
|
|
return &GapAPI{Detector: d}
|
|
}
|
|
|
|
// GET /api/v1/gaps
|
|
func (ga *GapAPI) List(w http.ResponseWriter, r *http.Request) {
|
|
gaps := ga.Detector.List()
|
|
openCount := 0
|
|
for _, g := range gaps {
|
|
if !g.Closed {
|
|
openCount++
|
|
}
|
|
}
|
|
respond(w, 200, map[string]interface{}{
|
|
"gaps": gaps,
|
|
"count": len(gaps),
|
|
"open": openCount,
|
|
})
|
|
}
|
|
|
|
// POST /api/v1/gaps/{topic}/close
|
|
func (ga *GapAPI) Close(w http.ResponseWriter, r *http.Request) {
|
|
topic := r.PathValue("topic")
|
|
if topic == "" {
|
|
respondError(w, 400, "topic required")
|
|
return
|
|
}
|
|
|
|
ga.Detector.Close(topic)
|
|
selfoptimize.Dash.RecordGapClosed()
|
|
respond(w, 200, map[string]string{"status": "closed", "topic": topic})
|
|
}
|
|
|
|
// POST /api/v1/gaps/detect — 手动触发缺口检测(miss 计数)
|
|
func (ga *GapAPI) Detect(w http.ResponseWriter, r *http.Request) {
|
|
var req struct {
|
|
Topic string `json:"topic"`
|
|
}
|
|
if err := json.NewDecoder(r.Body).Decode(&req); err != nil {
|
|
respondError(w, 400, "invalid body")
|
|
return
|
|
}
|
|
if req.Topic == "" {
|
|
respondError(w, 400, "topic required")
|
|
return
|
|
}
|
|
|
|
gap := ga.Detector.RecordMiss(req.Topic)
|
|
if gap != nil {
|
|
PushGapDetected("system", req.Topic, string(gap.Type), "threshold_reached")
|
|
respond(w, 201, map[string]interface{}{
|
|
"status": "gap_detected", "gap": gap,
|
|
})
|
|
} else {
|
|
respond(w, 200, map[string]string{"status": "tracking", "topic": req.Topic})
|
|
}
|
|
}
|