From e7c4f8ee98f9cb6b4eec814c422cbd65e9bb1870 Mon Sep 17 00:00:00 2001 From: voodoohop Date: Mon, 7 Sep 2026 22:03:43 +0100 Subject: [PATCH] fix: resolve Pollinations TTS model aliases (#6010) --- src/endpoints/speech.js | 2 +- tests/pollinations.test.js | 67 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 68 insertions(+), 1 deletion(-) create mode 100644 tests/pollinations.test.js diff --git a/src/endpoints/speech.js b/src/endpoints/speech.js index 0140532cd..091980fae 100644 --- a/src/endpoints/speech.js +++ b/src/endpoints/speech.js @@ -101,7 +101,7 @@ pollinations.post('/voices', async (req, res) => { throw new Error('Invalid data format received from Pollinations'); } - const audioModelData = data.find(m => m.name === model); + const audioModelData = data.find(m => m.name === model || m.aliases?.includes(model)); if (!audioModelData || !Array.isArray(audioModelData.voices)) { throw new Error('No voices found for the specified model'); } diff --git a/tests/pollinations.test.js b/tests/pollinations.test.js new file mode 100644 index 000000000..5d08f5ddc --- /dev/null +++ b/tests/pollinations.test.js @@ -0,0 +1,67 @@ +import { afterAll, beforeAll, beforeEach, describe, expect, jest, test } from '@jest/globals'; + +const fetchMock = jest.fn(); +jest.unstable_mockModule('node-fetch', () => ({ default: fetchMock })); +jest.unstable_mockModule('../src/transformers.js', () => ({ getPipeline: jest.fn() })); +jest.unstable_mockModule('../src/endpoints/secrets.js', () => ({ + readSecret: jest.fn(), + SECRET_KEYS: {}, +})); + +describe('Pollinations TTS model aliases', () => { + /** @type {import('node:http').Server} */ + let server; + let baseUrl; + + beforeAll(async () => { + const { default: express } = await import('express'); + const { router: speechRouter } = await import('../src/endpoints/speech.js'); + const app = express(); + app.use(express.json()); + app.use('/speech', speechRouter); + server = app.listen(0, '127.0.0.1'); + await new Promise(resolve => server.once('listening', resolve)); + const address = server.address(); + baseUrl = `http://127.0.0.1:${address.port}`; + }); + + afterAll(async () => { + await new Promise((resolve, reject) => server.close(error => error ? reject(error) : resolve())); + }); + + beforeEach(() => { + fetchMock.mockReset(); + }); + + test.each([undefined, 'openai-audio', 'openai/gpt-audio-mini'])('looks up voices for %s', async (model) => { + fetchMock.mockResolvedValue({ + ok: true, + json: async () => [{ name: 'openai/gpt-audio-mini', aliases: ['openai-audio'], voices: ['alloy', 'nova'] }], + }); + + const response = await fetch(`${baseUrl}/speech/pollinations/voices`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: JSON.stringify({ model }), + }); + + expect(response.status).toBe(200); + expect(await response.json()).toEqual(['alloy', 'nova']); + }); + + test('still accepts catalogs without aliases', async () => { + fetchMock.mockResolvedValue({ + ok: true, + json: async () => [{ name: 'openai-audio', voices: ['alloy'] }], + }); + + const response = await fetch(`${baseUrl}/speech/pollinations/voices`, { + method: 'POST', + headers: { 'Content-Type': 'application/json' }, + body: '{}', + }); + + expect(response.status).toBe(200); + expect(await response.json()).toEqual(['alloy']); + }); +});