#!/usr/bin/env node /** * Scrapes available Ollama models and their tags from ollama.com * Outputs a JSON file that can be used by the frontend for model selection. * * Usage: node scripts/scrape-ollama-models.mjs */ import { writeFileSync } from 'fs'; import { dirname, join } from 'path'; import { fileURLToPath } from 'url'; const __dirname = dirname(fileURLToPath(import.meta.url)); const OLLAMA_LIBRARY_URL = 'https://ollama.com/library'; /** * Fetches the list of all available models with their capabilities from Ollama's library page * @returns {Promise>} */ async function fetchModelsWithCapabilities() { console.log('Fetching model list from Ollama library...'); const response = await fetch(OLLAMA_LIBRARY_URL); const html = await response.text(); // Parse models and their capabilities from the HTML // Each model is in a
  • block const modelBlocks = html.split('
  • ]*>([^<]+) { const tags = await fetchModelTags(name); return { name, tags, capabilities }; }) ); for (const { name, tags, capabilities } of results) { models[name] = { tags, capabilities, }; console.log(` ${name}: ${tags.length} tags, capabilities: [${capabilities.join(', ')}]`); } } // Create output structure const output = { generatedAt: new Date().toISOString(), modelCount: Object.keys(models).length, models, }; // Write to public directory so it can be served statically const outputPath = join(__dirname, '..', 'public', 'ollama-models.json'); writeFileSync(outputPath, JSON.stringify(output, null, 2)); const elapsed = ((Date.now() - startTime) / 1000).toFixed(1); console.log(`\nDone! Scraped ${Object.keys(models).length} models in ${elapsed}s`); console.log(`Output written to: ${outputPath}`); } main().catch(console.error);