prompt issues fixes
This commit is contained in:
@@ -206,14 +206,21 @@ def process_image_generation_queue(self, image_ids: list, account_id: int = None
|
|||||||
except IntegrationSettings.DoesNotExist:
|
except IntegrationSettings.DoesNotExist:
|
||||||
return {'success': False, 'error': f'{provider} integration not found'}
|
return {'success': False, 'error': f'{provider} integration not found'}
|
||||||
|
|
||||||
# Get prompt templates
|
# Get image prompt template (has placeholders: {image_type}, {post_title}, {image_prompt})
|
||||||
try:
|
try:
|
||||||
image_prompt_template = PromptRegistry.get_image_prompt_template(account)
|
image_prompt_template = PromptRegistry.get_image_prompt_template(account)
|
||||||
negative_prompt = PromptRegistry.get_negative_prompt(account) if provider == 'runware' else None
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Failed to get prompt templates: {e}, using fallback")
|
logger.warning(f"Failed to get image prompt template: {e}, using fallback")
|
||||||
image_prompt_template = "{image_prompt}"
|
image_prompt_template = 'Create a high-quality {image_type} image for a blog post titled "{post_title}". Image prompt: {image_prompt}'
|
||||||
negative_prompt = None
|
|
||||||
|
# Get negative prompt for Runware (only needed for Runware provider)
|
||||||
|
negative_prompt = None
|
||||||
|
if provider == 'runware':
|
||||||
|
try:
|
||||||
|
negative_prompt = PromptRegistry.get_negative_prompt(account)
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Failed to get negative prompt: {e}")
|
||||||
|
negative_prompt = None
|
||||||
|
|
||||||
# Initialize AICore
|
# Initialize AICore
|
||||||
ai_core = AICore(account=account)
|
ai_core = AICore(account=account)
|
||||||
@@ -259,7 +266,7 @@ def process_image_generation_queue(self, image_ids: list, account_id: int = None
|
|||||||
failed += 1
|
failed += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Get content for prompt formatting
|
# Get content for template formatting
|
||||||
content = image.content
|
content = image.content
|
||||||
if not content:
|
if not content:
|
||||||
logger.warning(f"Image {image_id} has no content")
|
logger.warning(f"Image {image_id} has no content")
|
||||||
@@ -271,17 +278,18 @@ def process_image_generation_queue(self, image_ids: list, account_id: int = None
|
|||||||
failed += 1
|
failed += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Format prompt using template
|
# Format template with image prompt from database
|
||||||
|
# Template has placeholders: {image_type}, {post_title}, {image_prompt}
|
||||||
try:
|
try:
|
||||||
formatted_prompt = image_prompt_template.format(
|
formatted_prompt = image_prompt_template.format(
|
||||||
|
image_type=image_type,
|
||||||
post_title=content.title or content.meta_title or f"Content #{content.id}",
|
post_title=content.title or content.meta_title or f"Content #{content.id}",
|
||||||
image_prompt=image.prompt,
|
image_prompt=image.prompt # Read directly from database field
|
||||||
image_type=image_type
|
|
||||||
)
|
)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
# Fallback to simple prompt
|
# Fallback if template formatting fails
|
||||||
logger.warning(f"Prompt template formatting failed: {e}, using fallback")
|
logger.warning(f"Prompt template formatting failed: {e}, using image prompt directly")
|
||||||
formatted_prompt = f"{image.prompt}, {image_type} style"
|
formatted_prompt = image.prompt
|
||||||
|
|
||||||
# Generate image
|
# Generate image
|
||||||
logger.info(f"Generating image {index}/{total_images} (ID: {image_id})")
|
logger.info(f"Generating image {index}/{total_images} (ID: {image_id})")
|
||||||
@@ -346,4 +354,4 @@ def process_image_generation_queue(self, image_ids: list, account_id: int = None
|
|||||||
'completed': completed,
|
'completed': completed,
|
||||||
'failed': failed,
|
'failed': failed,
|
||||||
'results': results
|
'results': results
|
||||||
}
|
}
|
||||||
@@ -7,6 +7,7 @@
|
|||||||
import React, { useEffect, useState } from 'react';
|
import React, { useEffect, useState } from 'react';
|
||||||
import { Modal } from '../ui/modal';
|
import { Modal } from '../ui/modal';
|
||||||
import { FileIcon, TimeIcon, CheckCircleIcon, ErrorIcon } from '../../icons';
|
import { FileIcon, TimeIcon, CheckCircleIcon, ErrorIcon } from '../../icons';
|
||||||
|
import { fetchAPI } from '../../services/api';
|
||||||
|
|
||||||
export interface ImageQueueItem {
|
export interface ImageQueueItem {
|
||||||
imageId: number | null;
|
imageId: number | null;
|
||||||
@@ -56,12 +57,13 @@ export default function ImageQueueModal({
|
|||||||
|
|
||||||
const pollInterval = setInterval(async () => {
|
const pollInterval = setInterval(async () => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/v1/system/settings/task_progress/${taskId}/`);
|
const data = await fetchAPI(`/v1/system/settings/task_progress/${taskId}/`);
|
||||||
if (!response.ok) {
|
|
||||||
console.error('Failed to fetch task status');
|
// Check if data is valid (not HTML error page)
|
||||||
|
if (!data || typeof data !== 'object') {
|
||||||
|
console.warn('Invalid task status response:', data);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const data = await response.json();
|
|
||||||
|
|
||||||
// Check state (task_progress returns 'state', not 'status')
|
// Check state (task_progress returns 'state', not 'status')
|
||||||
const taskState = data.state || data.status;
|
const taskState = data.state || data.status;
|
||||||
@@ -82,8 +84,26 @@ export default function ImageQueueModal({
|
|||||||
if (data.meta) {
|
if (data.meta) {
|
||||||
updateQueueFromTaskMeta(data.meta);
|
updateQueueFromTaskMeta(data.meta);
|
||||||
}
|
}
|
||||||
} catch (error) {
|
} catch (error: any) {
|
||||||
console.error('Error polling task status:', error);
|
// Check if it's a JSON parse error (HTML response) or API error
|
||||||
|
if (error.message && (error.message.includes('JSON') || error.message.includes('API Error'))) {
|
||||||
|
console.error('Task status endpoint error:', {
|
||||||
|
message: error.message,
|
||||||
|
status: error.status,
|
||||||
|
taskId: taskId,
|
||||||
|
endpoint: `/v1/system/settings/task_progress/${taskId}/`,
|
||||||
|
error: error
|
||||||
|
});
|
||||||
|
// If it's a 404, the endpoint might not exist - stop polling after a few attempts
|
||||||
|
if (error.status === 404) {
|
||||||
|
console.error('Task progress endpoint not found (404). Stopping polling.');
|
||||||
|
clearInterval(pollInterval);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Don't stop polling for other errors, but log them
|
||||||
|
} else {
|
||||||
|
console.error('Error polling task status:', error);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}, 1000); // Poll every second
|
}, 1000); // Poll every second
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user