56 lines
1.1 KiB
Go
56 lines
1.1 KiB
Go
package handler
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"tencent_ocr/pkg/service"
|
|
)
|
|
|
|
type RateHandler struct {
|
|
geminiService *service.GeminiService
|
|
}
|
|
|
|
func NewRateHandler(geminiService *service.GeminiService) *RateHandler {
|
|
return &RateHandler{
|
|
geminiService: geminiService,
|
|
}
|
|
}
|
|
|
|
type RateRequest struct {
|
|
Text string `json:"text" binding:"required"`
|
|
Criteria string `json:"criteria"`
|
|
WritingRequirement string `json:"writing_requirement"`
|
|
}
|
|
|
|
type RateResponse struct {
|
|
Result string `json:"result"`
|
|
Success bool `json:"success"`
|
|
}
|
|
|
|
func (h *RateHandler) HandleRate(c *gin.Context) {
|
|
var req RateRequest
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
c.JSON(http.StatusBadRequest, RateResponse{
|
|
Success: false,
|
|
Result: "Invalid request format",
|
|
})
|
|
return
|
|
}
|
|
|
|
// Process with Gemini
|
|
criteria := req.Criteria
|
|
result, err := h.geminiService.ProcessText(c.Request.Context(), req.Text)
|
|
if err != nil {
|
|
c.JSON(http.StatusInternalServerError, RateResponse{
|
|
Success: false,
|
|
Result: "Text processing failed",
|
|
})
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, RateResponse{
|
|
Success: true,
|
|
Result: result,
|
|
})
|
|
} |