Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 0 additions & 10 deletions script.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ const STORAGE_KEYS = {

const API_ENDPOINT = 'https://text.pollinations.ai/openai';
const MODELS_ENDPOINT = 'https://text.pollinations.ai/models';
const LOCAL_MODELS_FALLBACK = 'data/models.json';
const API_REFERRER = 'www.unityailab.com';

const API_SEED_LENGTH = 8;
Expand Down Expand Up @@ -620,15 +619,6 @@ async function fetchModels() {
return await loadModelCatalog(apiUrl);
} catch (apiError) {
console.error('Unable to load Pollinations model catalog from API', apiError);

try {
const fallbackCatalog = await loadModelCatalog(LOCAL_MODELS_FALLBACK);
console.warn('Using bundled Pollinations model catalog as a fallback.');
return fallbackCatalog;
} catch (fallbackError) {
console.error('Unable to load bundled Pollinations model catalog', fallbackError);
}

throw apiError;
}
}
Expand Down
48 changes: 7 additions & 41 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ const path = require('path');

const ROOT = path.resolve(__dirname, '..');
const DIST = path.join(ROOT, 'dist');
const DATA_DIR = path.join(ROOT, 'data');
const THEMES_DIR = path.join(ROOT, 'themes');
const DIST_DATA_DIR = path.join(DIST, 'data');
const API_ROOT = 'https://text.pollinations.ai';
Expand Down Expand Up @@ -56,54 +55,23 @@ async function fetchRemoteModels(token) {
};
}

function readFallbackModels() {
const fallbackPath = path.join(DATA_DIR, 'models.json');
if (!fs.existsSync(fallbackPath)) {
return null;
}
try {
const raw = fs.readFileSync(fallbackPath, 'utf8');
return JSON.parse(raw);
} catch (error) {
console.warn('Unable to parse fallback model catalog:', error.message);
return null;
}
}

async function writeModelCatalog(token) {
ensureDir(DIST_DATA_DIR);

const fallback = readFallbackModels();
let catalog = null;

if (token) {
try {
catalog = await fetchRemoteModels(token);
if (catalog && fallback?.voices && !catalog.voices) {
catalog.voices = fallback.voices;
}
} catch (error) {
console.warn('Unable to fetch Pollinations model catalog with token:', error.message);
catalog = null;
}
if (!token) {
console.warn('No Pollinations token provided. Skipping model catalog bundling.');
return;
}

const outputPath = path.join(DIST_DATA_DIR, 'models.json');

if (catalog) {
try {
const catalog = await fetchRemoteModels(token);
fs.writeFileSync(outputPath, JSON.stringify(catalog, null, 2));
console.log('Wrote Pollinations model catalog to dist/data/models.json');
return;
}

if (fallback) {
ensureDir(path.dirname(outputPath));
fs.writeFileSync(outputPath, JSON.stringify(fallback, null, 2));
console.log('Copied fallback model catalog to dist/data/models.json');
return;
} catch (error) {
console.warn('Unable to fetch Pollinations model catalog with token:', error.message);
}

console.warn('No model catalog could be bundled. Ensure data/models.json exists.');
}

async function main() {
Expand All @@ -117,8 +85,6 @@ async function main() {

copyDirectory(path.join(ROOT, 'assets'), path.join(DIST, 'assets'));
copyDirectory(THEMES_DIR, path.join(DIST, 'themes'));
copyDirectory(DATA_DIR, DIST_DATA_DIR);

await writeModelCatalog(process.env.POLLINATIONS_TOKEN?.trim());

console.log('Build output prepared at', DIST);
Expand Down