prompt issues fixes
This commit is contained in:
@@ -206,13 +206,20 @@ def process_image_generation_queue(self, image_ids: list, account_id: int = None
|
||||
except IntegrationSettings.DoesNotExist:
|
||||
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:
|
||||
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:
|
||||
logger.warning(f"Failed to get prompt templates: {e}, using fallback")
|
||||
image_prompt_template = "{image_prompt}"
|
||||
logger.warning(f"Failed to get image prompt template: {e}, using fallback")
|
||||
image_prompt_template = 'Create a high-quality {image_type} image for a blog post titled "{post_title}". Image prompt: {image_prompt}'
|
||||
|
||||
# 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
|
||||
@@ -259,7 +266,7 @@ def process_image_generation_queue(self, image_ids: list, account_id: int = None
|
||||
failed += 1
|
||||
continue
|
||||
|
||||
# Get content for prompt formatting
|
||||
# Get content for template formatting
|
||||
content = image.content
|
||||
if not 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
|
||||
continue
|
||||
|
||||
# Format prompt using template
|
||||
# Format template with image prompt from database
|
||||
# Template has placeholders: {image_type}, {post_title}, {image_prompt}
|
||||
try:
|
||||
formatted_prompt = image_prompt_template.format(
|
||||
image_type=image_type,
|
||||
post_title=content.title or content.meta_title or f"Content #{content.id}",
|
||||
image_prompt=image.prompt,
|
||||
image_type=image_type
|
||||
image_prompt=image.prompt # Read directly from database field
|
||||
)
|
||||
except Exception as e:
|
||||
# Fallback to simple prompt
|
||||
logger.warning(f"Prompt template formatting failed: {e}, using fallback")
|
||||
formatted_prompt = f"{image.prompt}, {image_type} style"
|
||||
# Fallback if template formatting fails
|
||||
logger.warning(f"Prompt template formatting failed: {e}, using image prompt directly")
|
||||
formatted_prompt = image.prompt
|
||||
|
||||
# Generate image
|
||||
logger.info(f"Generating image {index}/{total_images} (ID: {image_id})")
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
import React, { useEffect, useState } from 'react';
|
||||
import { Modal } from '../ui/modal';
|
||||
import { FileIcon, TimeIcon, CheckCircleIcon, ErrorIcon } from '../../icons';
|
||||
import { fetchAPI } from '../../services/api';
|
||||
|
||||
export interface ImageQueueItem {
|
||||
imageId: number | null;
|
||||
@@ -56,12 +57,13 @@ export default function ImageQueueModal({
|
||||
|
||||
const pollInterval = setInterval(async () => {
|
||||
try {
|
||||
const response = await fetch(`/api/v1/system/settings/task_progress/${taskId}/`);
|
||||
if (!response.ok) {
|
||||
console.error('Failed to fetch task status');
|
||||
const data = await fetchAPI(`/v1/system/settings/task_progress/${taskId}/`);
|
||||
|
||||
// Check if data is valid (not HTML error page)
|
||||
if (!data || typeof data !== 'object') {
|
||||
console.warn('Invalid task status response:', data);
|
||||
return;
|
||||
}
|
||||
const data = await response.json();
|
||||
|
||||
// Check state (task_progress returns 'state', not 'status')
|
||||
const taskState = data.state || data.status;
|
||||
@@ -82,9 +84,27 @@ export default function ImageQueueModal({
|
||||
if (data.meta) {
|
||||
updateQueueFromTaskMeta(data.meta);
|
||||
}
|
||||
} catch (error) {
|
||||
} catch (error: any) {
|
||||
// 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
|
||||
|
||||
return () => clearInterval(pollInterval);
|
||||
|
||||
Reference in New Issue
Block a user