feat: Add SEO audits (PageSpeed) to AI chat context
- Import CompanyWebsiteAnalysis model - Query PageSpeed scores: SEO, performance, accessibility, best practices - Add SEO audits description to system prompt - Include website URLs and profile links - AI can now answer questions about website SEO scores Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
parent
1894272670
commit
3bcff9a2d3
@ -47,7 +47,8 @@ from database import (
|
||||
Person,
|
||||
CompanyPerson,
|
||||
CompanySocialMedia,
|
||||
GBPAudit
|
||||
GBPAudit,
|
||||
CompanyWebsiteAnalysis
|
||||
)
|
||||
|
||||
# Import feedback learning service for few-shot learning
|
||||
@ -483,6 +484,25 @@ class NordaBizChatEngine:
|
||||
for audit in latest_audits
|
||||
]
|
||||
|
||||
# Add SEO audits (PageSpeed scores) for companies with website analysis
|
||||
seo_audits = db.query(CompanyWebsiteAnalysis).filter(
|
||||
CompanyWebsiteAnalysis.pagespeed_seo_score.isnot(None)
|
||||
).options(joinedload(CompanyWebsiteAnalysis.company)).all()
|
||||
|
||||
context['seo_audits'] = [
|
||||
{
|
||||
'company': audit.company.name if audit.company else '',
|
||||
'seo': audit.pagespeed_seo_score or 0,
|
||||
'performance': audit.pagespeed_performance_score or 0,
|
||||
'accessibility': audit.pagespeed_accessibility_score or 0,
|
||||
'best_practices': audit.pagespeed_best_practices_score or 0,
|
||||
'overall': audit.seo_overall_score or 0,
|
||||
'url': audit.company.website if audit.company else '',
|
||||
'profile_url': f'https://nordabiznes.pl/company/{audit.company.slug}' if audit.company else ''
|
||||
}
|
||||
for audit in seo_audits
|
||||
]
|
||||
|
||||
return context
|
||||
|
||||
def _company_to_compact_dict(self, c: Company) -> Dict[str, Any]:
|
||||
@ -608,6 +628,7 @@ class NordaBizChatEngine:
|
||||
people_companies_count = len(context.get('company_people', {}))
|
||||
social_companies_count = len(context.get('company_social_media', {}))
|
||||
gbp_audits_count = len(context.get('gbp_audits', []))
|
||||
seo_audits_count = len(context.get('seo_audits', []))
|
||||
|
||||
system_prompt = f"""Jesteś pomocnym asystentem portalu Norda Biznes - katalogu firm zrzeszonych w stowarzyszeniu Norda Biznes z Wejherowa.
|
||||
|
||||
@ -622,6 +643,7 @@ class NordaBizChatEngine:
|
||||
- Firmy z danymi KRS (zarząd/wspólnicy): {people_companies_count}
|
||||
- Firmy z Social Media: {social_companies_count}
|
||||
- Audyty Google Business: {gbp_audits_count}
|
||||
- Audyty SEO (PageSpeed): {seo_audits_count}
|
||||
|
||||
🎯 TWOJA ROLA:
|
||||
- Analizujesz CAŁĄ bazę firm i wybierasz najlepsze dopasowania do pytania użytkownika
|
||||
@ -692,11 +714,21 @@ class NordaBizChatEngine:
|
||||
- maps_url: link do profilu Google Maps
|
||||
- profile_url: link do profilu firmy na nordabiznes.pl
|
||||
|
||||
🔍 AUDYT SEO (PageSpeed) - wyniki analizy stron www firm:
|
||||
- company: nazwa firmy
|
||||
- seo: wynik SEO (0-100)
|
||||
- performance: wydajność strony (0-100)
|
||||
- accessibility: dostępność (0-100)
|
||||
- best_practices: najlepsze praktyki (0-100)
|
||||
- overall: ogólny wynik SEO (0-100)
|
||||
- url: adres strony www
|
||||
- profile_url: link do profilu firmy na nordabiznes.pl
|
||||
|
||||
⚠️ WAŻNE:
|
||||
- ZAWSZE podawaj nazwę firmy i kontakt (tel/web/mail jeśli dostępne)
|
||||
- ZAWSZE dołączaj linki gdy są dostępne:
|
||||
• Profil firmy na nordabiznes.pl (pole "profile")
|
||||
• Strona www firmy (pole "web")
|
||||
• Strona www firmy (pole "web" lub "url")
|
||||
• Profil Google Maps (pole "maps_url")
|
||||
• Profile social media (pole "url")
|
||||
- Jeśli pytanie o osobę (np. "kto to Roszman") - szukaj w ZARZĄD I WSPÓLNICY lub w polu "history"
|
||||
@ -708,6 +740,7 @@ class NordaBizChatEngine:
|
||||
- Jeśli pytanie o dyskusje/tematy - sprawdź forum
|
||||
- Jeśli pytanie o social media/followers - sprawdź SOCIAL MEDIA (dołącz linki!)
|
||||
- Jeśli pytanie o Google opinie/recenzje - sprawdź AUDYT GOOGLE BUSINESS (dołącz link do Maps!)
|
||||
- Jeśli pytanie o SEO/wydajność strony/PageSpeed - sprawdź AUDYT SEO (dołącz link do strony!)
|
||||
- Odpowiadaj PO POLSKU
|
||||
"""
|
||||
|
||||
@ -777,6 +810,12 @@ class NordaBizChatEngine:
|
||||
system_prompt += json.dumps(context['gbp_audits'], ensure_ascii=False, indent=None)
|
||||
system_prompt += "\n"
|
||||
|
||||
# Add SEO audits (PageSpeed scores)
|
||||
if context.get('seo_audits'):
|
||||
system_prompt += "\n\n🔍 AUDYTY SEO (PageSpeed):\n"
|
||||
system_prompt += json.dumps(context['seo_audits'], ensure_ascii=False, indent=None)
|
||||
system_prompt += "\n"
|
||||
|
||||
# Add conversation history
|
||||
full_prompt = system_prompt + "\n\n# HISTORIA ROZMOWY:\n"
|
||||
for msg in context.get('recent_messages', []):
|
||||
|
||||
Loading…
Reference in New Issue
Block a user