(ctx context.Context)
| 289 | } |
| 290 | |
| 291 | func (i *imlBalanceModule) getBalances(ctx context.Context) ([]*gateway.DynamicRelease, error) { |
| 292 | balances, err := i.balanceService.Search(ctx, "", nil, "priority asc") |
| 293 | if err != nil { |
| 294 | return nil, err |
| 295 | } |
| 296 | v, has := i.settingService.Get(ctx, "system.ai_model.ollama_address") |
| 297 | if !has { |
| 298 | //return nil, fmt.Errorf("ollama address not found") |
| 299 | return nil, nil |
| 300 | } |
| 301 | releases := make([]*gateway.DynamicRelease, 0, len(balances)) |
| 302 | for _, item := range balances { |
| 303 | base := v |
| 304 | if item.Provider != ai_provider_local.ProviderLocal { |
| 305 | p, has := model_runtime.GetProvider(item.Provider) |
| 306 | if !has { |
| 307 | continue |
| 308 | } |
| 309 | base = fmt.Sprintf("%s://%s%s", p.URI().Scheme(), p.URI().Host(), p.URI().Path()) |
| 310 | } else { |
| 311 | if v == "" { |
| 312 | continue |
| 313 | } |
| 314 | } |
| 315 | releases = append(releases, newRelease(item, base)) |
| 316 | } |
| 317 | return releases, nil |
| 318 | } |
| 319 | |
| 320 | func (i *imlBalanceModule) initGateway(ctx context.Context, clusterId string, clientDriver gateway.IClientDriver) error { |
| 321 | releases, err := i.getBalances(ctx) |
no test coverage detected