Skip to content
This repository was archived by the owner on Aug 18, 2026. It is now read-only.

feat: add /model slash command to switch named models from config.toml - #33

Merged
pranc1ngpegasus merged 3 commits into
mainfrom
feat/model-slash-command
Aug 13, 2026
Merged

feat: add /model slash command to switch named models from config.toml#33
pranc1ngpegasus merged 3 commits into
mainfrom
feat/model-slash-command

Conversation

@pranc1ngpegasus

Copy link
Copy Markdown
Member

What

Adds a /model slash command that switches between models configured in config.toml as named [[model."<name>"]] sections:

[[model."gemma4"]]
base_url = "http://localhost:11434"
model = "gemma4:latest"

[[model."gpt4o"]]
base_url = "https://api.openai.com/v1"
model = "gpt-4o"
env_key = "OPENAI_API_KEY"

Each section accepts base_url, model, and optionally api_key / env_key / api_mode. env_key reads the API key from the named environment variable, keeping secrets out of the config file.

Usage

  • Type /model (or /model <prefix>) — the suggestion panel lists the configured models, with the active one marked; Up/Down/Ctrl-N/Ctrl-P highlights, Enter switches.
  • /model <name> switches directly by name.
  • A bare /model with no models configured explains how to add sections.

Why

The single flat [llm] section could only configure one endpoint. Named sections make local (Ollama/vLLM) and cloud models switchable at runtime without editing config, mirroring pi's /model selector in this fork's simpler suggestion-panel architecture.

How it was validated

  • cargo test --workspace — all crates pass (107 sui-app, 56 sui-llm tests incl. new model parsing/env_key/reject cases)
  • cargo clippy --workspace --all-targets -- -D warnings — clean
  • cargo fmt --all --check — clean
  • Manual verification of the suggestion flow via the new slash_model_* tests

Legacy behavior is preserved: when no [[model."..."]] sections exist, startup falls back to the existing LlmClient::from_config_or_env ([llm] section or SUI_LLM_* env vars) path.

Commits

  • feat(sui-llm): parse named [[model."<name>"]] configs with env_key support
  • feat(sui-app): add /model slash command to switch named models
  • feat(sui): prefer named models from config.toml over legacy [llm]

…pport

Add LlmModel, a named model pairing a config.toml section name with an
LlmConfig. Each [[model.<name>]] section accepts base_url, model, optional
api_key, optional env_key (environment variable holding the API key), and
optional api_mode. Models are returned in lexicographic name order; duplicate
sections, empty or whitespace names, missing required fields, and invalid
env_key values are rejected.

The legacy [llm] section and SUI_LLM_* environment variables remain
supported unchanged.
Extend the slash suggestion panel with switchable model candidates: typing
/model (or /model <prefix>) lists the models attached via App::with_models,
with the active one marked; Up/Down/Ctrl-N/Ctrl-P selects and Enter switches.
/model <name> switches by name, and a bare /model cycles or explains how to
configure named models when none are set. Tab cycles model candidates without
replacing the command text.

App gains models + active_model state; with_models activates the first model,
and with_llm clears switchable state so single-client mode stays consistent.
At startup, load [[model.<name>]] sections via LlmModel::from_config and wire
them into App::with_models so /model switching works out of the box. When no
named models are configured, fall back to the legacy LlmClient::from_config_or_env
path so existing [llm] / SUI_LLM_* setups are unchanged.
@pranc1ngpegasus
pranc1ngpegasus merged commit d2f89e5 into main Aug 13, 2026
1 check passed
@pranc1ngpegasus
pranc1ngpegasus deleted the feat/model-slash-command branch August 13, 2026 12:51
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant