Load pollinations models from an endpoint
| @@ -1692,28 +1692,17 @@ async function loadStabilityModels() { | ||
| 1692 | 1692 | } |
| 1693 | 1693 | |
| 1694 | 1694 | async function loadPollinationsModels() { |
| 1695 | - return [ | |
| 1695 | + const result = await fetch('/api/sd/pollinations/models', { | |
| 1696 | - { | |
| 1696 | + method: 'POST', | |
| 1697 | - value: 'flux', | |
| 1697 | + headers: getRequestHeaders(), | |
| 1698 | - text: 'FLUX.1 [schnell]', | |
| 1698 | + }); | |
| 1699 | - }, | |
| 1699 | + | |
| 1700 | - { | |
| 1700 | + if (result.ok) { | |
| 1701 | - value: 'flux-realism', | |
| 1701 | + const data = await result.json(); | |
| 1702 | - text: 'FLUX Realism', | |
| 1702 | + return data; | |
| 1703 | - }, | |
| 1703 | + } | |
| 1704 | - { | |
| 1704 | + | |
| 1705 | - value: 'flux-anime', | |
| 1705 | + return []; | |
| 1706 | - text: 'FLUX Anime', | |
| 1707 | - }, | |
| 1708 | - { | |
| 1709 | - value: 'flux-3d', | |
| 1710 | - text: 'FLUX 3D', | |
| 1711 | - }, | |
| 1712 | - { | |
| 1713 | - value: 'turbo', | |
| 1714 | - text: 'SDXL Turbo', | |
| 1715 | - }, | |
| 1716 | - ]; | |
| 1717 | 1706 | } |
| 1718 | 1707 | |
| 1719 | 1708 | async function loadTogetherAIModels() { |
| @@ -811,6 +811,31 @@ drawthings.post('/generate', jsonParser, async (request, response) => { | ||
| 811 | 811 | |
| 812 | 812 | const pollinations = express.Router(); |
| 813 | 813 | |
| 814 | +pollinations.post('/models', jsonParser, async (_request, response) => { | |
| 815 | + try { | |
| 816 | + const modelsUrl = new URL('https://image.pollinations.ai/models'); | |
| 817 | + const result = await fetch(modelsUrl); | |
| 818 | + | |
| 819 | + if (!result.ok) { | |
| 820 | + console.log('Pollinations returned an error.', result.status, result.statusText); | |
| 821 | + throw new Error('Pollinations request failed.'); | |
| 822 | + } | |
| 823 | + | |
| 824 | + const data = await result.json(); | |
| 825 | + | |
| 826 | + if (!Array.isArray(data)) { | |
| 827 | + console.log('Pollinations returned invalid data.'); | |
| 828 | + throw new Error('Pollinations request failed.'); | |
| 829 | + } | |
| 830 | + | |
| 831 | + const models = data.map(x => ({ value: x, text: x })); | |
| 832 | + return response.send(models); | |
| 833 | + } catch (error) { | |
| 834 | + console.log(error); | |
| 835 | + return response.sendStatus(500); | |
| 836 | + } | |
| 837 | +}); | |
| 838 | + | |
| 814 | 839 | pollinations.post('/generate', jsonParser, async (request, response) => { |
| 815 | 840 | try { |
| 816 | 841 | const promptUrl = new URL(`https://image.pollinations.ai/prompt/${encodeURIComponent(request.body.prompt)}`); |