From 84c7802646ee4c7bf2eca7e1e4cd907fb55d3835 Mon Sep 17 00:00:00 2001 From: MartialBE Date: Mon, 1 Jan 2024 15:04:19 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20fix:=20Error=20caused=20by=20unk?= =?UTF-8?q?nown=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- controller/model.go | 14 +++++++++++++- web/src/views/Dashboard/component/SupportModels.js | 2 +- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/controller/model.go b/controller/model.go index f938d59d..76c4bb64 100644 --- a/controller/model.go +++ b/controller/model.go @@ -90,6 +90,12 @@ func ListModels(c *gin.Context) { // 根据 OwnedBy 排序 sort.Slice(groupOpenAIModels, func(i, j int) bool { + if groupOpenAIModels[i].OwnedBy == nil { + return true // 假设 nil 值小于任何非 nil 值 + } + if groupOpenAIModels[j].OwnedBy == nil { + return false // 假设任何非 nil 值大于 nil 值 + } return *groupOpenAIModels[i].OwnedBy < *groupOpenAIModels[j].OwnedBy }) @@ -100,7 +106,7 @@ func ListModels(c *gin.Context) { } func ListModelsForAdmin(c *gin.Context) { - openAIModels := make([]OpenAIModels, 0, len(common.ModelTypes)) + openAIModels := make([]OpenAIModels, 0, len(common.ModelRatio)) for modelId := range common.ModelRatio { openAIModels = append(openAIModels, OpenAIModels{ Id: modelId, @@ -114,6 +120,12 @@ func ListModelsForAdmin(c *gin.Context) { } // 根据 OwnedBy 排序 sort.Slice(openAIModels, func(i, j int) bool { + if openAIModels[i].OwnedBy == nil { + return true // 假设 nil 值小于任何非 nil 值 + } + if openAIModels[j].OwnedBy == nil { + return false // 假设任何非 nil 值大于 nil 值 + } return *openAIModels[i].OwnedBy < *openAIModels[j].OwnedBy }) diff --git a/web/src/views/Dashboard/component/SupportModels.js b/web/src/views/Dashboard/component/SupportModels.js index 43ff1f08..91636cab 100644 --- a/web/src/views/Dashboard/component/SupportModels.js +++ b/web/src/views/Dashboard/component/SupportModels.js @@ -42,7 +42,7 @@ const SupportModels = () => { {Object.entries(modelList).map(([title, models]) => ( - + {models.map((model) => (