commit
de8a257c8b
@ -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)
|
||||
}
|
@ -0,0 +1,43 @@
|
||||
package ai_recognition
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"goskeleton/app/global/consts"
|
||||
"goskeleton/app/http/controller/web"
|
||||
"goskeleton/app/http/validator/core/data_transfer"
|
||||
"goskeleton/app/utils/response"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type VocRecognition struct {
|
||||
Voc string `form:"voc" json:"voc" binding:"required"` // 必填、对于文本,表示它的长度>=1
|
||||
}
|
||||
|
||||
func (v VocRecognition) CheckParams(context *gin.Context) {
|
||||
if err := context.ShouldBind(&v); err != nil {
|
||||
// 将表单参数验证器出现的错误直接交给错误翻译器统一处理即可
|
||||
response.ValidatorError(context, err)
|
||||
return
|
||||
}
|
||||
// 该函数主要是将本结构体的字段(成员)按照 consts.ValidatorPrefix+ json标签对应的 键 => 值 形式绑定在上下文,便于下一步(控制器)可以直接通过 context.Get(键) 获取相关值
|
||||
extraAddBindDataContext := data_transfer.DataAddContext(v, consts.ValidatorPrefix, context)
|
||||
if extraAddBindDataContext == nil {
|
||||
response.ErrorSystem(context, "VocRecognition表单参数验证器json化失败", "")
|
||||
return
|
||||
}
|
||||
voc := v.Voc
|
||||
// 先进行 URL 解码
|
||||
// decodedVoc, err := url.QueryUnescape(voc)
|
||||
// if err != nil {
|
||||
// response.ErrorSystem(context, "VocRecognition表单参数验证器URL解码失败", "")
|
||||
// return
|
||||
// }
|
||||
// 再进行 Base64 解码
|
||||
_, err := base64.StdEncoding.DecodeString(voc)
|
||||
if err != nil {
|
||||
response.ErrorSystem(context, "VocRecognition表单参数验证器Base64解码失败", "")
|
||||
return
|
||||
}
|
||||
(&web.AiRecognition{}).VocRecognition(extraAddBindDataContext)
|
||||
}
|
File diff suppressed because one or more lines are too long
Binary file not shown.
After Width: | Height: | Size: 100 KiB |
File diff suppressed because one or more lines are too long
Loading…
Reference in new issue