MCPcopy Index your code
hub / github.com/APIParkLab/APIPark / getLocalBalances

Method getLocalBalances

module/ai-balance/iml.go:262–289  ·  view source on GitHub ↗
(ctx context.Context, v string)

Source from the content-addressed store, hash-verified

260}
261
262func (i *imlBalanceModule) getLocalBalances(ctx context.Context, v string) ([]*gateway.DynamicRelease, error) {
263 balances, err := i.balanceService.Search(ctx, "", map[string]interface{}{"provider": ai_provider_local.ProviderLocal}, "priority asc")
264 if err != nil {
265 return nil, err
266 }
267 if v == "" {
268 var has bool
269 v, has = i.settingService.Get(ctx, "system.ai_model.ollama_address")
270 if !has {
271 //return nil, fmt.Errorf("ollama address not found")
272 return nil, nil
273 }
274 }
275
276 releases := make([]*gateway.DynamicRelease, 0, len(balances))
277 for _, item := range balances {
278 base := v
279 if item.Provider != ai_provider_local.ProviderLocal {
280 p, has := model_runtime.GetProvider(item.Provider)
281 if !has {
282 continue
283 }
284 base = fmt.Sprintf("%s://%s%s", p.URI().Scheme(), p.URI().Host(), p.URI().Path())
285 }
286 releases = append(releases, newRelease(item, base))
287 }
288 return releases, nil
289}
290
291func (i *imlBalanceModule) getBalances(ctx context.Context) ([]*gateway.DynamicRelease, error) {
292 balances, err := i.balanceService.Search(ctx, "", nil, "priority asc")

Callers 1

SyncLocalBalancesMethod · 0.95

Calls 7

newReleaseFunction · 0.85
SearchMethod · 0.65
GetMethod · 0.65
SchemeMethod · 0.65
URIMethod · 0.65
HostMethod · 0.65
PathMethod · 0.65

Tested by

no test coverage detected