automation fixes
This commit is contained in:
@@ -140,7 +140,7 @@ class AutomationLogger:
|
||||
def _get_stage_log_path(self, account_id: int, site_id: int, run_id: str, stage_number: int) -> str:
|
||||
"""Get stage log file path"""
|
||||
run_dir = self._get_run_dir(account_id, site_id, run_id)
|
||||
return os.path.join(run_dir, f'stage_{stage_number}.log')
|
||||
return os.path.join(run_dir, f'stage_{str(stage_number)}.log')
|
||||
|
||||
def _append_to_main_log(self, account_id: int, site_id: int, run_id: str, message: str):
|
||||
"""Append message to main log file"""
|
||||
|
||||
@@ -17,6 +17,7 @@ from igny8_core.auth.models import Account, Site
|
||||
from igny8_core.modules.planner.models import Keywords, Clusters, ContentIdeas
|
||||
from igny8_core.modules.writer.models import Tasks, Content, Images
|
||||
from igny8_core.ai.models import AITaskLog
|
||||
from igny8_core.ai.engine import AIEngine
|
||||
|
||||
# AI Functions
|
||||
from igny8_core.ai.functions.auto_cluster import AutoClusterFunction
|
||||
@@ -79,8 +80,8 @@ class AutomationService:
|
||||
|
||||
# Check credit balance (with 20% buffer)
|
||||
required_credits = int(estimated_credits * 1.2)
|
||||
if self.account.credits_balance < required_credits:
|
||||
raise ValueError(f"Insufficient credits. Need ~{required_credits}, you have {self.account.credits_balance}")
|
||||
if self.account.credits < required_credits:
|
||||
raise ValueError(f"Insufficient credits. Need ~{required_credits}, you have {self.account.credits}")
|
||||
|
||||
# Create run_id and log files
|
||||
run_id = self.logger.start_run(self.account.id, self.site.id, trigger_type)
|
||||
@@ -102,7 +103,7 @@ class AutomationService:
|
||||
)
|
||||
self.logger.log_stage_progress(
|
||||
run_id, self.account.id, self.site.id, 0,
|
||||
f"Credit check: Account has {self.account.credits_balance} credits, estimated need: {estimated_credits} credits"
|
||||
f"Credit check: Account has {self.account.credits} credits, estimated need: {estimated_credits} credits"
|
||||
)
|
||||
|
||||
logger.info(f"[AutomationService] Started run: {run_id}")
|
||||
@@ -164,10 +165,11 @@ class AutomationService:
|
||||
stage_number, f"Processing batch {batch_num}/{total_batches} ({len(batch)} keywords)"
|
||||
)
|
||||
|
||||
# Call AI function
|
||||
result = AutoClusterFunction().execute(
|
||||
payload={'ids': batch},
|
||||
account=self.account
|
||||
# Call AI function via AIEngine
|
||||
engine = AIEngine(account=self.account)
|
||||
result = engine.execute(
|
||||
fn=AutoClusterFunction(),
|
||||
payload={'ids': batch}
|
||||
)
|
||||
|
||||
# Monitor task
|
||||
@@ -258,10 +260,11 @@ class AutomationService:
|
||||
stage_number, f"Generating ideas for cluster: {cluster.name}"
|
||||
)
|
||||
|
||||
# Call AI function
|
||||
result = GenerateIdeasFunction().execute(
|
||||
payload={'ids': [cluster.id]},
|
||||
account=self.account
|
||||
# Call AI function via AIEngine
|
||||
engine = AIEngine(account=self.account)
|
||||
result = engine.execute(
|
||||
fn=GenerateIdeasFunction(),
|
||||
payload={'ids': [cluster.id]}
|
||||
)
|
||||
|
||||
# Monitor task
|
||||
@@ -418,11 +421,10 @@ class AutomationService:
|
||||
stage_name = "Tasks → Content (AI)"
|
||||
start_time = time.time()
|
||||
|
||||
# Query queued tasks
|
||||
# Query queued tasks (all queued tasks need content generated)
|
||||
pending_tasks = Tasks.objects.filter(
|
||||
site=self.site,
|
||||
status='queued',
|
||||
content__isnull=True
|
||||
status='queued'
|
||||
)
|
||||
|
||||
total_count = pending_tasks.count()
|
||||
@@ -453,10 +455,11 @@ class AutomationService:
|
||||
stage_number, f"Generating content for task: {task.title}"
|
||||
)
|
||||
|
||||
# Call AI function
|
||||
result = GenerateContentFunction().execute(
|
||||
payload={'ids': [task.id]},
|
||||
account=self.account
|
||||
# Call AI function via AIEngine
|
||||
engine = AIEngine(account=self.account)
|
||||
result = engine.execute(
|
||||
fn=GenerateContentFunction(),
|
||||
payload={'ids': [task.id]}
|
||||
)
|
||||
|
||||
# Monitor task
|
||||
@@ -551,10 +554,11 @@ class AutomationService:
|
||||
stage_number, f"Extracting prompts from: {content.title}"
|
||||
)
|
||||
|
||||
# Call AI function
|
||||
result = GenerateImagePromptsFunction().execute(
|
||||
payload={'ids': [content.id]},
|
||||
account=self.account
|
||||
# Call AI function via AIEngine
|
||||
engine = AIEngine(account=self.account)
|
||||
result = engine.execute(
|
||||
fn=GenerateImagePromptsFunction(),
|
||||
payload={'ids': [content.id]}
|
||||
)
|
||||
|
||||
# Monitor task
|
||||
@@ -641,10 +645,11 @@ class AutomationService:
|
||||
stage_number, f"Generating image: {image.image_type} for '{content_title}'"
|
||||
)
|
||||
|
||||
# Call AI function
|
||||
result = GenerateImagesFunction().execute(
|
||||
payload={'image_ids': [image.id]},
|
||||
account=self.account
|
||||
# Call AI function via AIEngine
|
||||
engine = AIEngine(account=self.account)
|
||||
result = engine.execute(
|
||||
fn=GenerateImagesFunction(),
|
||||
payload={'image_ids': [image.id]}
|
||||
)
|
||||
|
||||
# Monitor task
|
||||
|
||||
Reference in New Issue
Block a user