You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
62 lines
1.5 KiB
62 lines
1.5 KiB
// Code scaffolded by goctl. Safe to edit.
|
|
// goctl 1.9.2
|
|
|
|
package ai
|
|
|
|
import (
|
|
"context"
|
|
|
|
"github.com/youruser/base/internal/svc"
|
|
"github.com/youruser/base/internal/types"
|
|
"github.com/youruser/base/model"
|
|
|
|
"github.com/zeromicro/go-zero/core/logx"
|
|
)
|
|
|
|
type AiModelListLogic struct {
|
|
logx.Logger
|
|
ctx context.Context
|
|
svcCtx *svc.ServiceContext
|
|
}
|
|
|
|
// 获取模型列表
|
|
func NewAiModelListLogic(ctx context.Context, svcCtx *svc.ServiceContext) *AiModelListLogic {
|
|
return &AiModelListLogic{
|
|
Logger: logx.WithContext(ctx),
|
|
ctx: ctx,
|
|
svcCtx: svcCtx,
|
|
}
|
|
}
|
|
|
|
func (l *AiModelListLogic) AiModelList() (resp *types.AIModelListResponse, err error) {
|
|
models, err := model.AIModelFindAllActive(l.ctx, l.svcCtx.DB)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
|
|
// Build provider name map
|
|
providerNames := make(map[int64]string)
|
|
providers, _ := model.AIProviderFindAllActive(l.ctx, l.svcCtx.DB)
|
|
for _, p := range providers {
|
|
providerNames[p.Id] = p.DisplayName
|
|
}
|
|
|
|
list := make([]types.AIModelInfo, len(models))
|
|
for i, m := range models {
|
|
list[i] = types.AIModelInfo{
|
|
Id: m.Id,
|
|
ProviderId: m.ProviderId,
|
|
ProviderName: providerNames[m.ProviderId],
|
|
ModelId: m.ModelId,
|
|
DisplayName: m.DisplayName,
|
|
InputPrice: m.InputPrice,
|
|
OutputPrice: m.OutputPrice,
|
|
MaxTokens: m.MaxTokens,
|
|
ContextWindow: m.ContextWindow,
|
|
SupportsStream: m.SupportsStream,
|
|
SupportsVision: m.SupportsVision,
|
|
}
|
|
}
|
|
|
|
return &types.AIModelListResponse{List: list}, nil
|
|
}
|
|
|