parent
6507272923
commit
3f57e45619
@ -0,0 +1,22 @@
|
|||||||
|
package web
|
||||||
|
|
||||||
|
import (
|
||||||
|
"goskeleton/app/global/consts"
|
||||||
|
"goskeleton/app/service/ai_model_cli"
|
||||||
|
"goskeleton/app/utils/response"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DocRefine struct {
|
||||||
|
}
|
||||||
|
|
||||||
|
// Ai 模型进行文档优化
|
||||||
|
|
||||||
|
func (u *DocRefine) DocRefine(context *gin.Context) {
|
||||||
|
if r, recogWords := ai_model_cli.RequestQianFan(context); r {
|
||||||
|
response.Success(context, consts.CurdStatusOkMsg, recogWords)
|
||||||
|
} else {
|
||||||
|
response.Fail(context, consts.DocRefineFailCode, consts.DocRefineFailMsg, "")
|
||||||
|
}
|
||||||
|
}
|
@ -0,0 +1,47 @@
|
|||||||
|
package ai_doc
|
||||||
|
|
||||||
|
import (
|
||||||
|
"goskeleton/app/global/consts"
|
||||||
|
"goskeleton/app/http/controller/web"
|
||||||
|
"goskeleton/app/http/validator/core/data_transfer"
|
||||||
|
"goskeleton/app/utils/response"
|
||||||
|
"strings"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
)
|
||||||
|
|
||||||
|
type DocRefine struct {
|
||||||
|
Type string `form:"type" json:"type" binding:"required"` // 必填、
|
||||||
|
Doc string `form:"doc" json:"doc" binding:"required"` // 必填、对于文本,表示它的长度>=1
|
||||||
|
Background string `form:"background" json:"background" `
|
||||||
|
}
|
||||||
|
|
||||||
|
var Types = []string{"abstract", "decorate", "sequel_writing", "rewrite_wrong", "translate"}
|
||||||
|
|
||||||
|
func (d DocRefine) CheckParams(context *gin.Context) {
|
||||||
|
if err := context.ShouldBind(&d); err != nil {
|
||||||
|
// 将表单参数验证器出现的错误直接交给错误翻译器统一处理即可
|
||||||
|
response.ValidatorError(context, err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 判断是否在类型中
|
||||||
|
t := d.Type
|
||||||
|
isExit := false
|
||||||
|
for _, e := range Types {
|
||||||
|
if strings.TrimSpace(t) == e {
|
||||||
|
isExit = true
|
||||||
|
break
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if !isExit {
|
||||||
|
response.ErrorSystem(context, "DocRefine表单参数验证器json化失败", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// 该函数主要是将本结构体的字段(成员)按照 consts.ValidatorPrefix+ json标签对应的 键 => 值 形式绑定在上下文,便于下一步(控制器)可以直接通过 context.Get(键) 获取相关值
|
||||||
|
extraAddBindDataContext := data_transfer.DataAddContext(d, consts.ValidatorPrefix, context)
|
||||||
|
if extraAddBindDataContext == nil {
|
||||||
|
response.ErrorSystem(context, "DocRefine表单参数验证器json化失败", "")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
(&web.DocRefine{}).DocRefine(extraAddBindDataContext)
|
||||||
|
}
|
Loading…
Reference in new issue