package middleware import ( "github.com/gin-gonic/gin" "github.com/tidwall/gjson" "kefu/lib" "kefu/models" "kefu/types" ) //获取个人设置的OpenAI KEY中间件 func GetCollectByKefuName(c *gin.Context) { entId, _ := c.Get("ent_id") configs := models.GetEntConfigsMap(entId.(string), "QdrantAICollect", "chatGPTUrl", "chatGPTSecret") collectName := configs["QdrantAICollect"] chatGPTUrl := configs["chatGPTUrl"] chatGPTSecret := configs["chatGPTSecret"] if collectName == "" || chatGPTUrl == "" || chatGPTSecret == "" { c.JSON(200, gin.H{ "code": types.ApiCode.COLLECT_NOT_EXIST, "msg": types.ApiCode.GetMessage(types.ApiCode.COLLECT_NOT_EXIST), }) c.Abort() return } lib.QdrantBase = models.FindConfig("QdrantBase") lib.QdrantPort = models.FindConfig("QdrantPort") c.Set("collect_name", collectName) c.Set("openai_url", chatGPTUrl) c.Set("openai_key", chatGPTSecret) collectInfo, err := lib.GetCollection(collectName) if err != nil { c.Writer.Write([]byte(err.Error())) c.Abort() return } collectInfoStatus := gjson.Get(string(collectInfo), "status").String() if collectInfoStatus != "ok" { c.Writer.Write(collectInfo) c.Abort() return } }