fix(audit-ai): Add dynamic fallback for unknown action_types in content generation
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
Some checks are pending
NordaBiz Tests / Unit & Integration Tests (push) Waiting to run
NordaBiz Tests / E2E Tests (Playwright) (push) Blocked by required conditions
NordaBiz Tests / Smoke Tests (Production) (push) Blocked by required conditions
NordaBiz Tests / Send Failure Notification (push) Blocked by required conditions
AI analysis generates action_types dynamically (e.g. add_sitemap, add_nap) that don't always match predefined CONTENT_PROMPTS. Added fallback that builds a generic prompt using the action title/description from the DB. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
parent
44e7e1cb07
commit
8ad6299381
@ -713,9 +713,6 @@ def generate_content(company_id: int, action_type: str, context: dict = None, us
|
||||
Returns:
|
||||
dict with 'content' key
|
||||
"""
|
||||
if action_type not in CONTENT_PROMPTS:
|
||||
return {'error': f'Nieznany typ akcji: {action_type}'}
|
||||
|
||||
db = SessionLocal()
|
||||
try:
|
||||
company = db.query(Company).filter_by(id=company_id, status='active').first()
|
||||
@ -765,8 +762,33 @@ def generate_content(company_id: int, action_type: str, context: dict = None, us
|
||||
'platforms_missing': ', '.join(missing) if missing else 'brak',
|
||||
})
|
||||
|
||||
# Build prompt from template
|
||||
# Build prompt from template or generate dynamic fallback
|
||||
if action_type in CONTENT_PROMPTS:
|
||||
prompt_template = CONTENT_PROMPTS[action_type]
|
||||
else:
|
||||
# Dynamic fallback — look up action title/description from DB
|
||||
existing_action = db.query(AuditAction).filter_by(
|
||||
company_id=company_id,
|
||||
action_type=action_type,
|
||||
status='suggested'
|
||||
).order_by(AuditAction.created_at.desc()).first()
|
||||
action_title = existing_action.title if existing_action else action_type.replace('_', ' ')
|
||||
action_desc = existing_action.description if existing_action else ''
|
||||
prompt_template = f"""Jesteś ekspertem od marketingu cyfrowego i SEO dla lokalnych firm w Polsce.
|
||||
|
||||
Firma: {{company_name}}
|
||||
Branża: {{category}}
|
||||
Miasto: {{city}}
|
||||
Strona: {{website}}
|
||||
Usługi: {{services}}
|
||||
|
||||
ZADANIE: {action_title}
|
||||
{('KONTEKST: ' + action_desc) if action_desc else ''}
|
||||
|
||||
Przygotuj konkretną, gotową do wdrożenia treść lub instrukcję krok po kroku dla tego zadania.
|
||||
Pisz po polsku, bezpośrednio do właściciela firmy.
|
||||
Bądź konkretny — podaj gotowe przykłady kodu, tekstów lub konfiguracji, które właściciel może skopiować i użyć.
|
||||
Max 500 słów."""
|
||||
try:
|
||||
prompt = prompt_template.format(**prompt_context)
|
||||
except KeyError as e:
|
||||
|
||||
Loading…
Reference in New Issue
Block a user