refactor(web): 优化 WebSocket 错误消息发送
- 移除了未使用的 fmt 包 - 更新了 Rag 结构的注释 - 简化了错误消息的发送逻辑,直接使用 errcode.ErrMsgForUser[code] 作为消息内容
This commit is contained in:
parent
dba6b16693
commit
d2f6f5da5a
@ -6,7 +6,6 @@ import (
|
|||||||
"catface/app/model_es"
|
"catface/app/model_es"
|
||||||
"catface/app/service/nlp"
|
"catface/app/service/nlp"
|
||||||
"catface/app/utils/response"
|
"catface/app/utils/response"
|
||||||
"fmt"
|
|
||||||
"io"
|
"io"
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
@ -18,7 +17,7 @@ import (
|
|||||||
type Rag struct {
|
type Rag struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
// v1 Http-POST 版本
|
// v1 Http-POST 版本; chat 需要不使用 ch 的版本。
|
||||||
// func (r *Rag) Chat(context *gin.Context) {
|
// func (r *Rag) Chat(context *gin.Context) {
|
||||||
// // 1. query embedding
|
// // 1. query embedding
|
||||||
// query := context.GetString(consts.ValidatorPrefix + "query")
|
// query := context.GetString(consts.ValidatorPrefix + "query")
|
||||||
@ -119,7 +118,7 @@ func (r *Rag) ChatWebSocket(context *gin.Context) {
|
|||||||
embedding, ok := nlp.GetEmbedding(query)
|
embedding, ok := nlp.GetEmbedding(query)
|
||||||
if !ok {
|
if !ok {
|
||||||
code := errcode.ErrServerDown
|
code := errcode.ErrServerDown
|
||||||
err := ws.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf("%d:%s", code, errcode.ErrMsgForUser[code])))
|
err := ws.WriteMessage(websocket.TextMessage, []byte(errcode.ErrMsgForUser[code]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
variable.ZapLog.Error("Failed to send error message via WebSocket", zap.Error(err))
|
variable.ZapLog.Error("Failed to send error message via WebSocket", zap.Error(err))
|
||||||
}
|
}
|
||||||
@ -132,7 +131,7 @@ func (r *Rag) ChatWebSocket(context *gin.Context) {
|
|||||||
variable.ZapLog.Error("ES TopK error", zap.Error(err))
|
variable.ZapLog.Error("ES TopK error", zap.Error(err))
|
||||||
|
|
||||||
code := errcode.ErrNoDocFound
|
code := errcode.ErrNoDocFound
|
||||||
err := ws.WriteMessage(websocket.TextMessage, []byte(fmt.Sprintf("%d:%s", code, errcode.ErrMsgForUser[code])))
|
err := ws.WriteMessage(websocket.TextMessage, []byte(errcode.ErrMsgForUser[code]))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
variable.ZapLog.Error("Failed to send error message via WebSocket", zap.Error(err))
|
variable.ZapLog.Error("Failed to send error message via WebSocket", zap.Error(err))
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user