2024-11-06 01:27:14 +08:00
|
|
|
package web
|
|
|
|
|
|
|
|
import (
|
|
|
|
"catface/app/global/consts"
|
2024-11-19 02:22:39 +08:00
|
|
|
"catface/app/global/errcode"
|
|
|
|
"catface/app/global/variable"
|
2024-11-16 02:38:34 +08:00
|
|
|
"catface/app/service/nlp"
|
2024-11-19 02:22:39 +08:00
|
|
|
"catface/app/utils/llm_factory"
|
2024-11-06 01:27:14 +08:00
|
|
|
"catface/app/utils/response"
|
|
|
|
|
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
|
|
|
type Nlp struct {
|
|
|
|
}
|
|
|
|
|
|
|
|
func (n *Nlp) Title(context *gin.Context) {
|
|
|
|
content := context.GetString(consts.ValidatorPrefix + "content")
|
|
|
|
|
2024-11-19 02:22:39 +08:00
|
|
|
tempGlmKey := variable.SnowFlake.GetIdAsString()
|
|
|
|
client, ercode := variable.GlmClientHub.GetOneGlmClient(tempGlmKey, llm_factory.GlmModeSimple)
|
|
|
|
if ercode > 0 {
|
|
|
|
response.Fail(context, ercode, errcode.ErrMsg[ercode], errcode.ErrMsgForUser[ercode])
|
|
|
|
}
|
2024-11-20 09:01:53 +08:00
|
|
|
defer variable.GlmClientHub.UnavtiveOneGlmClient(tempGlmKey)
|
2024-11-19 02:22:39 +08:00
|
|
|
defer variable.GlmClientHub.ReleaseOneGlmClient(tempGlmKey) // 临时使用,用完就释放。
|
|
|
|
|
|
|
|
newTitle := nlp.GenerateTitle(content, client)
|
2024-11-06 01:27:14 +08:00
|
|
|
if newTitle != "" {
|
|
|
|
response.Success(context, consts.CurdStatusOkMsg, gin.H{"title": newTitle})
|
|
|
|
} else {
|
|
|
|
response.Fail(context, consts.CurdStatusOkCode, consts.CurdStatusOkMsg, "")
|
|
|
|
}
|
|
|
|
}
|