feat: upgrade to gpt-image-2, switch to response_format=url
- app_settings AI_IMAGE_MODEL: gpt-image-1-mini → gpt-image-2 - covers.js generateCoverViaImageGenerations: добавлен response_format='url' (рекомендация провайдера: url быстрее, b64 весит ~5MB) Порядок обработки ответа: url → b64_json (fallback для старых моделей) - aiUsage.js: добавлена цена gpt-image-2 в IMAGE_PRICES_USD
This commit is contained in:
@@ -30,8 +30,9 @@ const TEXT_PRICES_USD_PER_1M = {
|
|||||||
|
|
||||||
// USD за 1 картинку (приблизительно — aiguoguo не публикует точно).
|
// USD за 1 картинку (приблизительно — aiguoguo не публикует точно).
|
||||||
const IMAGE_PRICES_USD = {
|
const IMAGE_PRICES_USD = {
|
||||||
|
'gpt-image-2': 0.04, // новая модель, ориентировочно как gpt-image-1
|
||||||
'gpt-image-1': 0.04,
|
'gpt-image-1': 0.04,
|
||||||
'gpt-image-1-mini': 0.01, // оценка, поправь после первого месяца использования
|
'gpt-image-1-mini': 0.01,
|
||||||
'dall-e-3': 0.04,
|
'dall-e-3': 0.04,
|
||||||
'dall-e-2': 0.02,
|
'dall-e-2': 0.02,
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -278,6 +278,7 @@ async function generateCoverViaImageGenerations({ prompt }) {
|
|||||||
prompt: prompt.slice(0, 4000),
|
prompt: prompt.slice(0, 4000),
|
||||||
n: 1,
|
n: 1,
|
||||||
size: '1024x1024',
|
size: '1024x1024',
|
||||||
|
response_format: 'url', // рекомендовано провайдером: url быстрее чем b64 (~5MB)
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
headers: { Authorization: `Bearer ${config.ai.imageApiKey}` },
|
headers: { Authorization: `Bearer ${config.ai.imageApiKey}` },
|
||||||
@@ -308,14 +309,13 @@ async function generateCoverViaImageGenerations({ prompt }) {
|
|||||||
requestType: 'image', model, imageCount: 1,
|
requestType: 'image', model, imageCount: 1,
|
||||||
durationMs: Date.now() - started, succeeded: true,
|
durationMs: Date.now() - started, succeeded: true,
|
||||||
}).catch(() => {});
|
}).catch(() => {});
|
||||||
// b64_json или url
|
// Приоритет: url (быстро) → b64_json (fallback для старых моделей)
|
||||||
const b64 = item.b64_json;
|
|
||||||
if (b64) return { bytes: Buffer.from(b64, 'base64'), format: 'png' };
|
|
||||||
if (item.url) {
|
if (item.url) {
|
||||||
const r = await axios.get(item.url, { responseType: 'arraybuffer', timeout: 60_000 });
|
const r = await axios.get(item.url, { responseType: 'arraybuffer', timeout: 60_000 });
|
||||||
return { bytes: Buffer.from(r.data), format: 'png' };
|
return { bytes: Buffer.from(r.data), format: 'png' };
|
||||||
}
|
}
|
||||||
throw new Error('No b64_json or url in response');
|
if (item.b64_json) return { bytes: Buffer.from(item.b64_json, 'base64'), format: 'png' };
|
||||||
|
throw new Error('No url or b64_json in response');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user