Files
gen2d/backend/internal/handler/prompt.go
T

43 lines
1.2 KiB
Go
Raw Normal View History

package handler
import (
"net/http"
"gen2d/internal/model"
"gen2d/internal/service"
"github.com/gin-gonic/gin"
)
// PromptOptimizeRequest 提示词优化请求。
type PromptOptimizeRequest struct {
Tags []string `json:"tags" binding:"required,min=1"` // 用户选择的标签
AssetType string `json:"assetType" binding:"required"` // 素材类型
Prompt string `json:"prompt"` // 用户原始提示词
UserNote string `json:"userNote"` // 用户额外描述
}
// PromptOptimize 提示词优化接口,接收用户标签并调用 LLM 生成规范提示词。
func PromptOptimize(c *gin.Context) {
var req PromptOptimizeRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, model.Fail(http.StatusBadRequest, "参数错误: "+err.Error()))
return
}
in := service.PromptAgentInput{
Tags: req.Tags,
AssetType: req.AssetType,
Prompt: req.Prompt,
UserNote: req.UserNote,
}
output, err := service.RunPromptAgent(c.Request.Context(), in)
if err != nil {
c.JSON(http.StatusInternalServerError, model.Fail(http.StatusInternalServerError, "提示词优化失败: "+err.Error()))
return
}
c.JSON(http.StatusOK, model.OK(output))
}