Skip to content

Commit

Permalink
🔖 chore: Model list deduplication(#350)
Browse files Browse the repository at this point in the history
  • Loading branch information
woodchen-ink authored Sep 19, 2024
1 parent 9109a35 commit 4160482
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion controller/channel-model.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,25 @@ func GetModelList(c *gin.Context) {
return
}

// 去除重复的模型名称
uniqueModels := removeDuplicates(modelList)

c.JSON(http.StatusOK, gin.H{
"success": true,
"message": "",
"data": modelList,
"data": uniqueModels,
})
}

// 辅助函数:去除切片中的重复元素
func removeDuplicates(slice []string) []string {
keys := make(map[string]bool)
list := []string{}
for _, entry := range slice {
if _, value := keys[entry]; !value {
keys[entry] = true
list = append(list, entry)
}
}
return list
}

0 comments on commit 4160482

Please sign in to comment.