后端新增 preferences 与 prompt_customizations 表及对应接口, 支持 BYOK 模型渠道密钥落库(仅回显掩码)与按任务类型定制 平台提示词模板;前端新增 /settings 页面及入口。
53 lines
1.2 KiB
Go
53 lines
1.2 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
"github.com/ttstd/infinite-canvas/backend/internal/service"
|
|
)
|
|
|
|
type PromptHandler struct {
|
|
prompts *service.PromptService
|
|
}
|
|
|
|
func NewPromptHandler(prompts *service.PromptService) *PromptHandler {
|
|
return &PromptHandler{prompts: prompts}
|
|
}
|
|
|
|
func (h *PromptHandler) List(c *gin.Context) {
|
|
preferences, err := h.prompts.Preferences()
|
|
if err != nil {
|
|
respondError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"preferences": preferences})
|
|
}
|
|
|
|
func (h *PromptHandler) Customize(c *gin.Context) {
|
|
var body struct {
|
|
Mode string `json:"mode"`
|
|
Content string `json:"content"`
|
|
}
|
|
if err := c.ShouldBindJSON(&body); err != nil {
|
|
c.JSON(http.StatusBadRequest, gin.H{"error": "请求体格式不正确"})
|
|
return
|
|
}
|
|
|
|
preference, err := h.prompts.Customize(c.Param("operation"), body.Mode, body.Content)
|
|
if err != nil {
|
|
respondError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"preference": preference})
|
|
}
|
|
|
|
func (h *PromptHandler) Reset(c *gin.Context) {
|
|
if err := h.prompts.Reset(c.Param("operation")); err != nil {
|
|
respondError(c, err)
|
|
return
|
|
}
|
|
c.JSON(http.StatusOK, gin.H{"ok": true})
|
|
}
|