diff --git a/module/ai-api/dto/input.go b/module/ai-api/dto/input.go index f445f9cb..be94417e 100644 --- a/module/ai-api/dto/input.go +++ b/module/ai-api/dto/input.go @@ -24,8 +24,9 @@ type AiPromptVariable struct { } type AiModel struct { - Id string `json:"id"` - Config string `json:"config"` + Id string `json:"id"` + Config string `json:"config"` + Provider string `json:"provider"` } type EditAPI struct { diff --git a/module/ai-api/dto/output.go b/module/ai-api/dto/output.go index 1083f98f..912bb878 100644 --- a/module/ai-api/dto/output.go +++ b/module/ai-api/dto/output.go @@ -26,6 +26,7 @@ type APIItem struct { Updater auto.Label `json:"updater" aolabel:"user"` CreateTime auto.TimeLabel `json:"create_time"` UpdateTime auto.TimeLabel `json:"update_time"` + Provider ProviderItem `json:"provider"` Model ModelItem `json:"model"` } @@ -33,3 +34,9 @@ type ModelItem struct { Id string `json:"id"` Logo string `json:"logo"` } + +type ProviderItem struct { + Id string `json:"id"` + Name string `json:"name"` + Logo string `json:"logo"` +} diff --git a/module/ai-api/iml.go b/module/ai-api/iml.go index aadc019a..55a60fc2 100644 --- a/module/ai-api/iml.go +++ b/module/ai-api/iml.go @@ -9,6 +9,7 @@ import ( "strings" model_runtime "github.com/APIParkLab/APIPark/ai-provider/model-runtime" + ai_api_dto "github.com/APIParkLab/APIPark/module/ai-api/dto" ai_api "github.com/APIParkLab/APIPark/service/ai-api" "github.com/APIParkLab/APIPark/service/api" @@ -203,19 +204,8 @@ func (i *imlAPIModule) List(ctx context.Context, keyword string, serviceId strin if err != nil { return nil, err } - p, has := model_runtime.GetProvider(info.AdditionalConfig["provider"]) - if !has { - return nil, fmt.Errorf("provider not found") - } return utils.SliceToSlice(apis, func(t *ai_api.API) *ai_api_dto.APIItem { - modelItem := ai_api_dto.ModelItem{ - Id: t.Model, - } - model, has := p.DefaultModel(t.Model) - if has { - modelItem.Logo = model.Logo() - } - return &ai_api_dto.APIItem{ + item := &ai_api_dto.APIItem{ Id: t.ID, Name: t.Name, RequestPath: t.Path, @@ -225,8 +215,32 @@ func (i *imlAPIModule) List(ctx context.Context, keyword string, serviceId strin Updater: auto.UUID(t.Updater), CreateTime: auto.TimeLabel(t.CreateAt), UpdateTime: auto.TimeLabel(t.UpdateAt), - Model: modelItem, } + aiModel, err := ConvertStruct[ai_api_dto.AiModel](t.AdditionalConfig["ai_model"]) + if err != nil { + return item + } + p, has := model_runtime.GetProvider(aiModel.Provider) + if has { + item.Provider = ai_api_dto.ProviderItem{ + Id: p.ID(), + Name: p.Name(), + Logo: p.Logo(), + } + m, has := p.GetModel(t.Model) + if has { + item.Model = ai_api_dto.ModelItem{ + Id: m.ID(), + Logo: m.Logo(), + } + } + } else { + + item.Model = ai_api_dto.ModelItem{ + Id: aiModel.Id, + } + } + return item }), nil } diff --git a/service/ai-api/model.go b/service/ai-api/model.go index ed25fd12..bf9e7d41 100644 --- a/service/ai-api/model.go +++ b/service/ai-api/model.go @@ -2,8 +2,9 @@ package ai_api import ( "encoding/json" - "github.com/APIParkLab/APIPark/stores/api" "time" + + "github.com/APIParkLab/APIPark/stores/api" ) type API struct {