From 3d4e2c31655cbe0644d5e304cbee02807a4c7be0 Mon Sep 17 00:00:00 2001 From: sunanzhi Date: Fri, 7 Mar 2025 14:07:53 +0800 Subject: [PATCH] fix: resolve package error when LLMs list is empty --- module/ai/iml.go | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/module/ai/iml.go b/module/ai/iml.go index eb79576e..4fd70f10 100644 --- a/module/ai/iml.go +++ b/module/ai/iml.go @@ -503,10 +503,7 @@ func (i *imlProviderModule) LLMs(ctx context.Context, driver string) ([]*ai_dto. return nil, nil, fmt.Errorf("ai provider not found") } - llms, has := p.ModelsByType(model_runtime.ModelTypeLLM) - if !has { - return nil, nil, fmt.Errorf("ai provider not found") - } + llms, _ := p.ModelsByType(model_runtime.ModelTypeLLM) modelApiCountMap, _ := i.aiAPIService.CountMapByModel(ctx, "", map[string]interface{}{"provider": driver}) items := make([]*ai_dto.LLMItem, 0, len(llms)) for _, v := range llms { @@ -530,14 +527,15 @@ func (i *imlProviderModule) LLMs(ctx context.Context, driver string) ([]*ai_dto. if !errors.Is(err, gorm.ErrRecordNotFound) { return nil, nil, err } - defaultLLM, has := p.DefaultModel(model_runtime.ModelTypeLLM) - if !has { - return nil, nil, fmt.Errorf("ai provider default llm not found") + defaultLLMID := "" + defaultLLM, _ := p.DefaultModel(model_runtime.ModelTypeLLM) + if defaultLLM != nil { + defaultLLMID = defaultLLM.ID() } return items, &ai_dto.ProviderItem{ Id: p.ID(), Name: p.Name(), - DefaultLLM: defaultLLM.ID(), + DefaultLLM: defaultLLMID, Logo: p.Logo(), }, nil }