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

Method applyProviderSwitch

cli/cli_llm.go:271–289  ·  view source on GitHub ↗

applyProviderSwitch switches the active provider (and its default model), updating the client, model cache and gateway runtime mirror. Shared by the numbered /switch picker and the /provider command so both paths behave identically.

(ctx context.Context, newProvider string)

Source from the content-addressed store, hash-verified

269// numbered /switch picker and the /provider command so both paths behave
270// identically.
271func (cli *ChatCLI) applyProviderSwitch(ctx context.Context, newProvider string) error {
272 newModel := cli.providerDefaultModel(newProvider)
273 newClient, err := cli.manager.GetClient(newProvider, newModel)
274 if err != nil {
275 cli.logger.Error("Erro ao trocar de provedor", zap.Error(err))
276 fmt.Println(i18n.T("cli.error.switch_provider_failed"))
277 return err
278 }
279
280 cli.Client = newClient
281 cli.Provider = newProvider
282 cli.Model = newModel
283 fmt.Println(i18n.T("status.provider_switched", cli.Client.GetModelName(), cli.Provider))
284 fmt.Println()
285 cli.refreshModelCache(ctx)
286 // Mirror the live choice for a running/future gateway daemon (separate process).
287 cli.writeRuntimeModelState()
288 return nil
289}
290
291// handleProviderCommand switches the active LLM provider by name — the
292// single-command, navigable counterpart to the numbered /switch picker. Bare

Callers 2

handleProviderCommandMethod · 0.95

Calls 7

providerDefaultModelMethod · 0.95
refreshModelCacheMethod · 0.95
TFunction · 0.92
GetClientMethod · 0.65
ErrorMethod · 0.65
GetModelNameMethod · 0.65

Tested by

no test coverage detected