MCPcopy Create free account
hub / github.com/diillson/chatcli / refreshModelCache

Method refreshModelCache

cli/cli_llm.go:488–507  ·  view source on GitHub ↗

refreshModelCache fetches available models for the current provider in background and caches them for autocomplete suggestions.

(ctx context.Context)

Source from the content-addressed store, hash-verified

486// refreshModelCache fetches available models for the current provider in background
487// and caches them for autocomplete suggestions.
488func (cli *ChatCLI) refreshModelCache(ctx context.Context) {
489 go func() {
490 // The warmer must outlive the triggering request; detach
491 // cancellation while inheriting context values.
492 ctx, cancel := context.WithTimeout(context.WithoutCancel(ctx), 15*time.Second)
493 defer cancel()
494
495 models, err := cli.manager.ListModelsForProvider(ctx, cli.Provider)
496 if err != nil {
497 cli.logger.Debug("Failed to refresh model cache", zap.String("provider", cli.Provider), zap.Error(err))
498 return
499 }
500
501 cli.cachedModelsMu.Lock()
502 cli.cachedModels = models
503 cli.cachedModelsMu.Unlock()
504
505 cli.logger.Debug("Model cache refreshed", zap.String("provider", cli.Provider), zap.Int("count", len(models)))
506 }()
507}
508
509// getCachedModels returns the cached model list (thread-safe).
510func (cli *ChatCLI) getCachedModels() []client.ModelInfo {

Callers 7

reloadConfigurationMethod · 0.95
ApplyOverridesMethod · 0.95
NewChatCLIFunction · 0.95
applyProviderSwitchMethod · 0.95
handleConnectCommandMethod · 0.80
autoSwitchProviderMethod · 0.80

Calls 5

LockMethod · 0.80
UnlockMethod · 0.80
ListModelsForProviderMethod · 0.65
ErrorMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected