Load pollinations models from an endpoint

This commit is contained in:
Cohee 2024-09-10 10:51:48 +00:00
parent 4522d3cbae
commit 8948354bf0
2 changed files with 36 additions and 22 deletions

View File

@ -1692,28 +1692,17 @@ async function loadStabilityModels() {
}
async function loadPollinationsModels() {
return [
{
value: 'flux',
text: 'FLUX.1 [schnell]',
},
{
value: 'flux-realism',
text: 'FLUX Realism',
},
{
value: 'flux-anime',
text: 'FLUX Anime',
},
{
value: 'flux-3d',
text: 'FLUX 3D',
},
{
value: 'turbo',
text: 'SDXL Turbo',
},
];
const result = await fetch('/api/sd/pollinations/models', {
method: 'POST',
headers: getRequestHeaders(),
});
if (result.ok) {
const data = await result.json();
return data;
}
return [];
}
async function loadTogetherAIModels() {

View File

@ -811,6 +811,31 @@ drawthings.post('/generate', jsonParser, async (request, response) => {
const pollinations = express.Router();
pollinations.post('/models', jsonParser, async (_request, response) => {
try {
const modelsUrl = new URL('https://image.pollinations.ai/models');
const result = await fetch(modelsUrl);
if (!result.ok) {
console.log('Pollinations returned an error.', result.status, result.statusText);
throw new Error('Pollinations request failed.');
}
const data = await result.json();
if (!Array.isArray(data)) {
console.log('Pollinations returned invalid data.');
throw new Error('Pollinations request failed.');
}
const models = data.map(x => ({ value: x, text: x }));
return response.send(models);
} catch (error) {
console.log(error);
return response.sendStatus(500);
}
});
pollinations.post('/generate', jsonParser, async (request, response) => {
try {
const promptUrl = new URL(`https://image.pollinations.ai/prompt/${encodeURIComponent(request.body.prompt)}`);