All files / src/commands providerCommands.ts

25.35% Statements 18/71
100% Branches 1/1
25% Functions 1/4
25.35% Lines 18/71

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 721x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x       1x 1x                                                         1x 1x                                             1x  
import * as vscode from 'vscode';
 
import { Logger } from '../logger';
import { OllamaProvider } from '../ollamaProvider';
import { FramingProvider } from '../providers/framingProvider';
 
export class ProviderCommands {
    constructor(
        private ollamaProvider: OllamaProvider,
        private framingProvider: FramingProvider,
    ) {}
 
    refresh() {
        this.ollamaProvider.refresh();
        this.framingProvider.refresh();
    }
 
    async pull() {
        const POPULAR_MODELS = [
            'llama3.2',
            'mistral',
            'deepseek-r1',
            'qwen2.5',
            'gemma2',
            'phi3.5',
            'codellama',
            'dolphin-llama3',
            'llava',
            'starcoder2',
        ];

        const quickPick = vscode.window.createQuickPick();
        quickPick.items = POPULAR_MODELS.map((label) => ({ label }));
        quickPick.placeholder = 'Enter model name (e.g. llama3)';
        quickPick.canSelectMany = false;

        quickPick.onDidAccept(async () => {
            const selection = quickPick.selectedItems[0]?.label || quickPick.value;
            quickPick.hide();
            if (selection) {
                await this.pullModelInternal(selection);
            }
        });

        quickPick.show();
    }
 
    private async pullModelInternal(name: string) {
        vscode.window.withProgress(
            {
                location: vscode.ProgressLocation.Notification,
                title: `Pulling ${name}`,
                cancellable: true,
            },
            async (progress) => {
                try {
                    await this.ollamaProvider.getApi().pullModel(name, (status, completed, total) => {
                        const msg = total ? `${status} (${Math.round(((completed || 0) / total) * 100)}%)` : status;
                        progress.report({ message: msg });
                    });
                    vscode.window.showInformationMessage(`Successfully pulled ${name}`);
                    this.ollamaProvider.refresh();
                } catch (err: unknown) {
                    const error = err as Error;
                    Logger.error(`Failed to pull ${name}`, error);
                    vscode.window.showErrorMessage(`Failed to pull ${name}: ${error.message}`);
                }
            },
        );
    }
}