add get simple ai provider api

This commit is contained in:
Liujian
2024-12-25 11:59:34 +08:00
parent cd4594f3ae
commit 4b1e1a22db
7 changed files with 29 additions and 2 deletions
+7
View File
@@ -4,6 +4,13 @@ import (
"github.com/eolinker/go-common/auto"
)
type SimpleProvider struct {
Id string `json:"id"`
Name string `json:"name"`
Logo string `json:"logo"`
GetAPIKeyUrl string `json:"get_apikey_url"`
}
type Provider struct {
Id string `json:"id"`
Name string `json:"name"`
+13
View File
@@ -60,6 +60,19 @@ type imlProviderModule struct {
transaction store.ITransaction `autowired:""`
}
func (i *imlProviderModule) SimpleProvider(ctx context.Context, id string) (*ai_dto.SimpleProvider, error) {
p, has := model_runtime.GetProvider(id)
if !has {
return nil, fmt.Errorf("ai provider not found")
}
return &ai_dto.SimpleProvider{
Id: p.ID(),
Name: p.Name(),
Logo: p.Logo(),
GetAPIKeyUrl: p.HelpUrl(),
}, nil
}
func (i *imlProviderModule) Sort(ctx context.Context, input *ai_dto.Sort) error {
return i.transaction.Transaction(ctx, func(txCtx context.Context) error {
list, err := i.providerService.List(ctx)
+1
View File
@@ -16,6 +16,7 @@ type IProviderModule interface {
UnConfiguredProviders(ctx context.Context) ([]*ai_dto.ProviderItem, error)
SimpleProviders(ctx context.Context) ([]*ai_dto.SimpleProviderItem, error)
Provider(ctx context.Context, id string) (*ai_dto.Provider, error)
SimpleProvider(ctx context.Context, id string) (*ai_dto.SimpleProvider, error)
LLMs(ctx context.Context, driver string) ([]*ai_dto.LLMItem, *ai_dto.ProviderItem, error)
UpdateProviderStatus(ctx context.Context, id string, enable bool) error
UpdateProviderConfig(ctx context.Context, id string, input *ai_dto.UpdateConfig) error