diff options
| author | Aiden Cline <[email protected]> | 2025-04-28 12:25:06 -0500 |
|---|---|---|
| committer | GitHub <[email protected]> | 2025-04-28 19:25:06 +0200 |
| commit | b3c0285db3dd5d5140481bf5118812e8dbc89795 (patch) | |
| tree | 3ead4b4447743c57cec2eef672d18615b7bdb2cb /internal/llm/agent | |
| parent | 805aeff83cad4c17e25acdd671d2731be104b3e0 (diff) | |
| download | opencode-b3c0285db3dd5d5140481bf5118812e8dbc89795.tar.gz opencode-b3c0285db3dd5d5140481bf5118812e8dbc89795.zip | |
feat: model selection for given provider (#57)
* feat: model selection for given provider
* tweak: adjust cfg validation func, remove duplicated logic, consolidate agent updating into agent.go
* tweak: make the model dialog scrollable, adjust padding slightly for modal"
* feat: add provider selection, add hints, simplify some logic, add horizontal scrolling support, additional scroll indicators"
* remove nav help
* update docs
* increase number of visible models, make horizontal scroll "wrap"
* add provider popularity rankings
Diffstat (limited to 'internal/llm/agent')
| -rw-r--r-- | internal/llm/agent/agent.go | 20 |
1 files changed, 20 insertions, 0 deletions
diff --git a/internal/llm/agent/agent.go b/internal/llm/agent/agent.go index c5f024073..80dfeb0fd 100644 --- a/internal/llm/agent/agent.go +++ b/internal/llm/agent/agent.go @@ -42,6 +42,7 @@ type Service interface { Cancel(sessionID string) IsSessionBusy(sessionID string) bool IsBusy() bool + Update(agentName config.AgentName, modelID models.ModelID) (models.Model, error) } type agent struct { @@ -436,6 +437,25 @@ func (a *agent) TrackUsage(ctx context.Context, sessionID string, model models.M return nil } +func (a *agent) Update(agentName config.AgentName, modelID models.ModelID) (models.Model, error) { + if a.IsBusy() { + return models.Model{}, fmt.Errorf("cannot change model while processing requests") + } + + if err := config.UpdateAgentModel(agentName, modelID); err != nil { + return models.Model{}, fmt.Errorf("failed to update config: %w", err) + } + + provider, err := createAgentProvider(agentName) + if err != nil { + return models.Model{}, fmt.Errorf("failed to create provider for model %s: %w", modelID, err) + } + + a.provider = provider + + return a.provider.Model(), nil +} + func createAgentProvider(agentName config.AgentName) (provider.Provider, error) { cfg := config.Get() agentConfig, ok := cfg.Agents[agentName] |
