first commit
This commit is contained in:
@@ -1,9 +1,7 @@
|
||||
package handlers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
"os"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
"sproutclaw-web/internal/config"
|
||||
@@ -13,27 +11,23 @@ import (
|
||||
|
||||
// RegisterModels registers model-related routes.
|
||||
func RegisterModels(r *gin.RouterGroup, cfg *config.Config, piClient *rpc.Client) {
|
||||
r.GET("/models", handleGetModels(cfg, piClient))
|
||||
r.GET("/models", handleGetModels(piClient))
|
||||
r.POST("/model", handleSetModel(piClient))
|
||||
r.POST("/thinking", handleSetThinking(piClient))
|
||||
}
|
||||
|
||||
func handleGetModels(cfg *config.Config, piClient *rpc.Client) gin.HandlerFunc {
|
||||
func handleGetModels(piClient *rpc.Client) gin.HandlerFunc {
|
||||
return func(c *gin.Context) {
|
||||
resp, err := piClient.SendCmd(models.RPCCommand{Type: "list_models"})
|
||||
resp, err := piClient.SendCmd(models.RPCCommand{Type: "get_available_models"})
|
||||
if err != nil {
|
||||
// fallback: read models.json
|
||||
data, ferr := os.ReadFile(cfg.ModelsConfigFile)
|
||||
if ferr != nil {
|
||||
c.JSON(http.StatusOK, models.ModelsResponse{Models: []models.ModelEntry{}})
|
||||
return
|
||||
}
|
||||
var raw any
|
||||
_ = json.Unmarshal(data, &raw)
|
||||
c.JSON(http.StatusOK, raw)
|
||||
c.JSON(http.StatusInternalServerError, models.ErrorResponse{Error: err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, jsonRaw(resp.Result))
|
||||
if !resp.Success {
|
||||
c.JSON(http.StatusInternalServerError, models.ErrorResponse{Error: resp.Error})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, jsonRaw(resp.Data))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -53,7 +47,11 @@ func handleSetModel(piClient *rpc.Client) gin.HandlerFunc {
|
||||
c.JSON(http.StatusInternalServerError, models.ErrorResponse{Error: err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, jsonRaw(resp.Result))
|
||||
if !resp.Success {
|
||||
c.JSON(http.StatusInternalServerError, models.ErrorResponse{Error: resp.Error})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"model": jsonRaw(resp.Data)})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -65,13 +63,17 @@ func handleSetThinking(piClient *rpc.Client) gin.HandlerFunc {
|
||||
return
|
||||
}
|
||||
resp, err := piClient.SendCmd(models.RPCCommand{
|
||||
Type: "set_thinking",
|
||||
Budget: req.Budget,
|
||||
Type: "set_thinking_level",
|
||||
Level: req.Level,
|
||||
})
|
||||
if err != nil {
|
||||
c.JSON(http.StatusInternalServerError, models.ErrorResponse{Error: err.Error()})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, jsonRaw(resp.Result))
|
||||
if !resp.Success {
|
||||
c.JSON(http.StatusInternalServerError, models.ErrorResponse{Error: resp.Error})
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, models.OKResponse{OK: true})
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user