ALwrity version 0.5.5
This commit is contained in:
@@ -332,7 +332,7 @@ async def generate_comprehensive_strategy_polling(
|
||||
"onboarding_data": onboarding_data,
|
||||
"user_id": user_id,
|
||||
"generation_config": config or {}
|
||||
}
|
||||
}
|
||||
|
||||
# Create strategy generation config
|
||||
generation_config = StrategyGenerationConfig(
|
||||
|
||||
@@ -26,6 +26,8 @@ class AutoFillRefreshService:
|
||||
- Optionally augments with AI overrides (hook, not persisted)
|
||||
- Returns payload in the same shape as AutoFillService.get_autofill, plus meta
|
||||
"""
|
||||
logger.info(f"AutoFillRefreshService: starting build_fresh_payload | user=%s | use_ai=%s | ai_only=%s", user_id, use_ai, ai_only)
|
||||
|
||||
# Base context from onboarding analysis (used for AI context only when ai_only)
|
||||
logger.debug("AutoFillRefreshService: processing onboarding context | user=%s", user_id)
|
||||
base_context = await self.autofill.integration.process_onboarding_data(user_id, self.db)
|
||||
@@ -37,6 +39,33 @@ class AutoFillRefreshService:
|
||||
bool((base_context or {}).get('api_keys_data')),
|
||||
bool((base_context or {}).get('onboarding_session')),
|
||||
)
|
||||
|
||||
# Log detailed context analysis
|
||||
logger.info(f"AutoFillRefreshService: detailed context analysis | user=%s", user_id)
|
||||
if base_context:
|
||||
website_analysis = base_context.get('website_analysis', {})
|
||||
research_preferences = base_context.get('research_preferences', {})
|
||||
api_keys_data = base_context.get('api_keys_data', {})
|
||||
onboarding_session = base_context.get('onboarding_session', {})
|
||||
|
||||
logger.info(f" - Website analysis keys: {list(website_analysis.keys()) if website_analysis else 'None'}")
|
||||
logger.info(f" - Research preferences keys: {list(research_preferences.keys()) if research_preferences else 'None'}")
|
||||
logger.info(f" - API keys data keys: {list(api_keys_data.keys()) if api_keys_data else 'None'}")
|
||||
logger.info(f" - Onboarding session keys: {list(onboarding_session.keys()) if onboarding_session else 'None'}")
|
||||
|
||||
# Log specific data points
|
||||
if website_analysis:
|
||||
logger.info(f" - Website URL: {website_analysis.get('website_url', 'Not found')}")
|
||||
logger.info(f" - Website status: {website_analysis.get('status', 'Unknown')}")
|
||||
if research_preferences:
|
||||
logger.info(f" - Research depth: {research_preferences.get('research_depth', 'Not found')}")
|
||||
logger.info(f" - Content types: {research_preferences.get('content_types', 'Not found')}")
|
||||
if api_keys_data:
|
||||
logger.info(f" - API providers: {api_keys_data.get('providers', [])}")
|
||||
logger.info(f" - Total keys: {api_keys_data.get('total_keys', 0)}")
|
||||
else:
|
||||
logger.warning(f"AutoFillRefreshService: no base context available | user=%s", user_id)
|
||||
|
||||
try:
|
||||
w = (base_context or {}).get('website_analysis') or {}
|
||||
r = (base_context or {}).get('research_preferences') or {}
|
||||
@@ -50,6 +79,16 @@ class AutoFillRefreshService:
|
||||
ai_payload = await self.structured_ai.generate_autofill_fields(user_id, base_context)
|
||||
meta = ai_payload.get('meta') or {}
|
||||
logger.info("AI-only payload meta: ai_used=%s overrides=%s", meta.get('ai_used'), meta.get('ai_overrides_count'))
|
||||
|
||||
# Log detailed AI payload analysis
|
||||
logger.info(f"AutoFillRefreshService: AI payload analysis | user=%s", user_id)
|
||||
logger.info(f" - AI used: {meta.get('ai_used', False)}")
|
||||
logger.info(f" - AI overrides count: {meta.get('ai_overrides_count', 0)}")
|
||||
logger.info(f" - Success rate: {meta.get('success_rate', 0):.1f}%")
|
||||
logger.info(f" - Attempts: {meta.get('attempts', 0)}")
|
||||
logger.info(f" - Missing fields: {len(meta.get('missing_fields', []))}")
|
||||
logger.info(f" - Fields generated: {len(ai_payload.get('fields', {}))}")
|
||||
|
||||
return ai_payload
|
||||
except Exception as e:
|
||||
logger.error("AI-only structured generation failed | user=%s | err=%s", user_id, repr(e))
|
||||
@@ -68,6 +107,7 @@ class AutoFillRefreshService:
|
||||
}
|
||||
|
||||
# Fallback to previous behavior (DB + sparse overrides)
|
||||
logger.info("AutoFillRefreshService: using fallback behavior (DB + sparse overrides)")
|
||||
payload = await self.autofill.get_autofill(user_id)
|
||||
logger.info("AutoFillRefreshService: Base payload fields: %d", len(payload.get('fields', {})))
|
||||
|
||||
|
||||
@@ -496,10 +496,21 @@ Generate the complete JSON with all 30 fields personalized for {website_url}:
|
||||
logger.info("AIStructuredAutofillService: generating %d fields | user=%s", len(CORE_FIELDS), user_id)
|
||||
logger.debug("AIStructuredAutofillService: properties=%d", len(schema.get('properties', {})))
|
||||
|
||||
# Log context summary for debugging
|
||||
logger.info("AIStructuredAutofillService: context summary | user=%s", user_id)
|
||||
logger.info(" - Website analysis exists: %s", bool(context_summary.get('user_profile', {}).get('website_url')))
|
||||
logger.info(" - Research config: %s", context_summary.get('research_config', {}).get('research_depth', 'None'))
|
||||
logger.info(" - API capabilities: %s", len(context_summary.get('api_capabilities', {}).get('providers', [])))
|
||||
logger.info(" - Content analysis: %s", bool(context_summary.get('content_analysis')))
|
||||
logger.info(" - Audience insights: %s", bool(context_summary.get('audience_insights')))
|
||||
|
||||
# Log prompt length for debugging
|
||||
logger.info("AIStructuredAutofillService: prompt length=%d chars | user=%s", len(prompt), user_id)
|
||||
|
||||
last_result = None
|
||||
for attempt in range(self.max_retries + 1):
|
||||
try:
|
||||
logger.info(f"AI structured call attempt {attempt + 1}/{self.max_retries + 1}")
|
||||
logger.info(f"AI structured call attempt {attempt + 1}/{self.max_retries + 1} | user=%s", user_id)
|
||||
result = await self.ai.execute_structured_json_call(
|
||||
service_type=AIServiceType.STRATEGIC_INTELLIGENCE,
|
||||
prompt=prompt,
|
||||
@@ -507,8 +518,34 @@ Generate the complete JSON with all 30 fields personalized for {website_url}:
|
||||
)
|
||||
last_result = result
|
||||
|
||||
# Log AI response details
|
||||
logger.info(f"AI response received | attempt={attempt + 1} | user=%s", user_id)
|
||||
if isinstance(result, dict):
|
||||
logger.info(f" - Response keys: {list(result.keys())}")
|
||||
logger.info(f" - Response type: dict with {len(result)} items")
|
||||
|
||||
# Handle wrapped response from AI service manager
|
||||
if 'data' in result and 'success' in result:
|
||||
# This is a wrapped response from AI service manager
|
||||
if result.get('success'):
|
||||
# Extract the actual AI response from the 'data' field
|
||||
ai_response = result.get('data', {})
|
||||
logger.info(f" - Extracted AI response from wrapped response")
|
||||
logger.info(f" - AI response keys: {list(ai_response.keys()) if isinstance(ai_response, dict) else 'N/A'}")
|
||||
last_result = ai_response
|
||||
else:
|
||||
# AI service failed
|
||||
error_msg = result.get('error', 'Unknown AI service error')
|
||||
logger.error(f" - AI service failed: {error_msg}")
|
||||
last_result = {'error': error_msg}
|
||||
elif 'error' in result:
|
||||
logger.error(f" - AI returned error: {result['error']}")
|
||||
else:
|
||||
logger.warning(f" - Response type: {type(result)}")
|
||||
|
||||
# Check if we should retry
|
||||
if not self._should_retry(result, attempt):
|
||||
if not self._should_retry(last_result, attempt):
|
||||
logger.info(f"Retry not needed | attempt={attempt + 1} | user=%s", user_id)
|
||||
break
|
||||
|
||||
# Add a small delay before retry
|
||||
|
||||
@@ -7,6 +7,7 @@ import logging
|
||||
from typing import Dict, Any, Optional, List
|
||||
from datetime import datetime, timedelta
|
||||
from sqlalchemy.orm import Session
|
||||
import traceback
|
||||
|
||||
# Import database models
|
||||
from models.enhanced_strategy_models import (
|
||||
@@ -39,6 +40,13 @@ class OnboardingDataIntegrationService:
|
||||
api_keys_data = self._get_api_keys_data(user_id, db)
|
||||
onboarding_session = self._get_onboarding_session(user_id, db)
|
||||
|
||||
# Log data source status
|
||||
logger.info(f"Data source status for user {user_id}:")
|
||||
logger.info(f" - Website analysis: {'✅ Found' if website_analysis else '❌ Missing'}")
|
||||
logger.info(f" - Research preferences: {'✅ Found' if research_preferences else '❌ Missing'}")
|
||||
logger.info(f" - API keys data: {'✅ Found' if api_keys_data else '❌ Missing'}")
|
||||
logger.info(f" - Onboarding session: {'✅ Found' if onboarding_session else '❌ Missing'}")
|
||||
|
||||
# Process and integrate data
|
||||
integrated_data = {
|
||||
'website_analysis': website_analysis,
|
||||
@@ -49,6 +57,14 @@ class OnboardingDataIntegrationService:
|
||||
'processing_timestamp': datetime.utcnow().isoformat()
|
||||
}
|
||||
|
||||
# Log data quality assessment
|
||||
data_quality = integrated_data['data_quality']
|
||||
logger.info(f"Data quality assessment for user {user_id}:")
|
||||
logger.info(f" - Completeness: {data_quality.get('completeness', 0):.2f}")
|
||||
logger.info(f" - Freshness: {data_quality.get('freshness', 0):.2f}")
|
||||
logger.info(f" - Relevance: {data_quality.get('relevance', 0):.2f}")
|
||||
logger.info(f" - Confidence: {data_quality.get('confidence', 0):.2f}")
|
||||
|
||||
# Store integrated data
|
||||
await self._store_integrated_data(user_id, integrated_data, db)
|
||||
|
||||
@@ -57,6 +73,7 @@ class OnboardingDataIntegrationService:
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"Error processing onboarding data for user {user_id}: {str(e)}")
|
||||
logger.error("Traceback:\n%s", traceback.format_exc())
|
||||
return self._get_fallback_data()
|
||||
|
||||
def _get_website_analysis(self, user_id: int, db: Session) -> Dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user