Interactive Model Selection Menu
Relevant source files
The following files were used as context for generating this wiki page:
The Interactive Model Selection Menu is a core component of the ollacc tool, designed to provide a user-friendly interface for choosing between various Ollama Cloud models. It serves as a bridge between the raw model catalog data and the final execution environment for Claude Code, allowing users to select popular models, enter custom model names, and persist their choices as defaults.
This system operates by scraping popular model lists from Ollama, intersecting them with the user's authorized catalog, and presenting a numbered terminal interface. It includes robust validation logic and integration with the project's configuration management system to ensure that model selections are valid and can be remembered for future sessions.
Sources: lib/menu.sh:1-3, README.md:21-27
Architecture and Data Flow
The menu system relies on a multi-stage process involving data retrieval, filtering, and user interaction. It interacts with several internal modules to manage state and configuration.
Data Retrieval and Filtering
Before the menu is rendered, the system resolves the available models by querying the Ollama API and scraping the "Popular" models list from the Ollama website. This ensures that the menu presents relevant and accessible choices to the user.
The logic above describes how MAPFILE is populated before interaction.
Sources: lib/catalog.sh:18-35, lib/menu.sh:4-7
Component Interaction Table
| Component | Responsibility | Relevant File |
|---|---|---|
| Catalog Resolver | Fetches and intersects popular/authorized models into MAPFILE. | lib/catalog.sh |
| Menu Renderer | Prints the formatted list of models and the custom entry option. | lib/menu.sh |
| Selection Logic | Validates user input and handles custom model entry. | lib/menu.sh |
| Config Manager | Persists model choices to the ~/.ollacc/config file. | lib/config.sh |
Menu Implementation Details
Rendering Logic
The menu_render function clears the terminal and prints a stylized header. It iterates through the global MAPFILE array to display models with numeric indices. It also appends a final option for "[Custom]" model entry, calculated as the length of the array plus one.
Sources: lib/menu.sh:10-26
Selection and Validation
The menu_choose function handles user input. It validates that the input is an integer to prevent shell evaluation errors (especially under set -u).
- Valid Index: Sets the
$MODELvariable to the corresponding entry inMAPFILE. - Custom Index: Prompts the user for a string. If empty, it defaults to
minimax-m3. - Invalid Input: Defaults to the first available model in
MAPFILE[0].
Sources: lib/menu.sh:30-54
Persistence and Defaults
The menu_offer_save_default function compares the selected $MODEL with the existing OLLAMA_CLAUDE_DEFAULT_MODEL. If they differ, the user is prompted to save the selection. If the user accepts, the config_set function is called to update the configuration file.
Sources: lib/menu.sh:58-75, lib/config.sh:42-65
Configuration and Flags
The menu behavior is influenced by the configuration file and runtime flags. Users can bypass or reset the menu state using specific commands.
Model Management Flags
The flag handling system allows users to clear their saved model preferences, forcing the menu to reappear on the next run.
| Flag | Action | Implementation |
|---|---|---|
--model-clear | Removes OLLAMA_CLAUDE_DEFAULT_MODEL from config. | lib/flags.sh:11-20 |
--model <name> | Bypasses the menu by providing a direct model name. | README.md:104-104 |
Sources: lib/flags.sh:1-20, README.md:103-107
Persistence Schema
Model defaults are stored in ~/.ollacc/config as standard shell assignments.
# ~/.ollacc/config
ANTHROPIC_AUTH_TOKEN="..."
ANTHROPIC_BASE_URL="https://ollama.com"
OLLAMA_CLAUDE_DEFAULT_MODEL="minimax-m3"
Sources: lib/auth.sh:7-14, README.md:118-122
Summary
The Interactive Model Selection Menu provides a robust mechanism for selecting AI models in the ollacc environment. By combining real-time catalog resolution from lib/catalog.sh with the interactive prompts in lib/menu.sh, it ensures that users can easily switch between popular cloud models or specify custom ones while maintaining a seamless experience through persistent configuration.