fix: use portrait canvas for assistant flowcharts
This commit is contained in:
parent
808db2a7a0
commit
8410ffe77b
1 changed files with 17 additions and 2 deletions
|
|
@ -1097,15 +1097,30 @@ async function generateImage(prompt, model) {
|
|||
if (!process.env.LITELLM_API_BASE) throw new Error('LiteLLM is required for image generation');
|
||||
var headers = { 'Content-Type': 'application/json' };
|
||||
if (process.env.LITELLM_API_KEY) headers.Authorization = 'Bearer ' + process.env.LITELLM_API_KEY;
|
||||
var size = imageSizeForPrompt(prompt);
|
||||
var resp = await axios.post(gatewayUrl('/images/generations'), {
|
||||
model: model,
|
||||
prompt: prompt,
|
||||
size: '1024x1024'
|
||||
prompt: imagePromptForCanvas(prompt, size),
|
||||
size: size
|
||||
}, { headers: headers, timeout: 120000 });
|
||||
var item = resp.data && resp.data.data && resp.data.data[0] ? resp.data.data[0] : {};
|
||||
return { imageUrl: item.url || null, base64: item.b64_json || null, raw: (!item.url && !item.b64_json) ? resp.data : undefined };
|
||||
}
|
||||
|
||||
function imageSizeForPrompt(prompt) {
|
||||
var text = String(prompt || '');
|
||||
if (/\b(flow\s*chart|flowchart|algorithm|pathway|timeline|vertical|stepwise|decision\s*tree|age\s*group|0-21|22-28|29-60)\b/i.test(text)) return '1024x1792';
|
||||
if (/\b(table|matrix|comparison|wide|landscape|side-by-side)\b/i.test(text)) return '1792x1024';
|
||||
return '1024x1024';
|
||||
}
|
||||
|
||||
function imagePromptForCanvas(prompt, size) {
|
||||
var guidance = ' Keep all text and boxes fully inside the canvas with generous margins. Use fewer words per box, large readable type, and avoid cropping at edges.';
|
||||
if (size === '1024x1792') guidance += ' Use a vertical portrait layout with top-to-bottom flow and ample spacing between decision nodes.';
|
||||
if (size === '1792x1024') guidance += ' Use a wide landscape layout with columns and ample horizontal spacing.';
|
||||
return String(prompt || '').trim() + guidance;
|
||||
}
|
||||
|
||||
async function getSetting(key, fallback) {
|
||||
try {
|
||||
var val = await db.getSetting(key);
|
||||
|
|
|
|||
Loading…
Reference in a new issue