Havoc412 f263ead51d refactor(llm_factory): 新增 GLM 客户端未使用资源释放功能
- 在 NlpController 和 RagController 中添加了释放 GLM 客户端资源的逻辑
- 在 GlmClientHub 中增加了 UnavtiveOneGlmClient 方法,用于将客户端标记为未使用状态
- 优化了资源管理,提高了 GLM 客户端的利用率
2024-11-20 09:01:53 +08:00

35 lines
1021 B
Go

package web
import (
"catface/app/global/consts"
"catface/app/global/errcode"
"catface/app/global/variable"
"catface/app/service/nlp"
"catface/app/utils/llm_factory"
"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")
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])
}
defer variable.GlmClientHub.UnavtiveOneGlmClient(tempGlmKey)
defer variable.GlmClientHub.ReleaseOneGlmClient(tempGlmKey) // 临时使用,用完就释放。
newTitle := nlp.GenerateTitle(content, client)
if newTitle != "" {
response.Success(context, consts.CurdStatusOkMsg, gin.H{"title": newTitle})
} else {
response.Fail(context, consts.CurdStatusOkCode, consts.CurdStatusOkMsg, "")
}
}