diff --git a/handler/im.go b/handler/im.go index dde4a9f..abfba7c 100644 --- a/handler/im.go +++ b/handler/im.go @@ -187,6 +187,18 @@ func subscribeAndHandleIMMessages(ws *websocket.Conn, userId int) { } func doReceiveGenChatMessage(userId int, sessionID *uint, data *proto.WSMessageReq, chanel string) error { + var model dao.Model + //查看请求功能类型 + models, funcs := service.FindFuncModelByFunction(data.Function, userId) + //log.Println("find function model by function:", models, funcs) + //log.Println("funcs:", len(funcs), "\tmodels:", len(models)) + if len(funcs) == 0 { + return errors.New("function not exist") + } + if len(models) == 0 { + //log.Println("doReceiveGenChatMessage models:", models) + return errors.New("model not exist") + } var err error if *sessionID == 0 { //创建会话 @@ -196,18 +208,6 @@ func doReceiveGenChatMessage(userId int, sessionID *uint, data *proto.WSMessageR log.Println("Create session error:", err) } } - var model dao.Model - //查看请求功能类型 - models, funcs := service.FindFuncModelByFunction(data.Function, userId) - log.Println("find function model by function:", models, funcs) - log.Println("funcs:", len(funcs), "\tmodels:", len(models)) - if len(funcs) == 0 { - return errors.New("function not exist") - } - if len(models) == 0 { - log.Println("doReceiveGenChatMessage models:", models) - return errors.New("model not exist") - } model = models[0] //解析模型参数 var modelParam proto.ModelParam @@ -217,7 +217,7 @@ func doReceiveGenChatMessage(userId int, sessionID *uint, data *proto.WSMessageR } modelParam.Url = model.Url modelParam.System = funcs[0].Info //系统功能 - imContext := proto.IMParamContext{UserID: userId, SessionID: int(*sessionID), FunctionID: int(funcs[0].ID), ModelID: int(model.ID), Question: data.Msg, Channel: chanel} + imContext := proto.IMParamContext{UserID: userId, SessionID: int(*sessionID), FunctionID: int(funcs[0].ID), ModelID: int(model.ID), Question: data.Msg, Channel: chanel, ModelType: model.Type} var userMsgID uint //将消息存入数据库