ALwrity version 0.5.5
This commit is contained in:
@@ -659,14 +659,19 @@ async def get_latest_generated_strategy(
|
||||
from models.enhanced_strategy_models import EnhancedContentStrategy
|
||||
from sqlalchemy import desc
|
||||
|
||||
logger.info(f"🔍 Querying database for strategies with user_id: {user_id}")
|
||||
|
||||
# Query for the most recent strategy with comprehensive AI analysis
|
||||
latest_db_strategy = db.query(EnhancedContentStrategy).filter(
|
||||
EnhancedContentStrategy.user_id == user_id,
|
||||
EnhancedContentStrategy.comprehensive_ai_analysis.isnot(None)
|
||||
).order_by(desc(EnhancedContentStrategy.created_at)).first()
|
||||
|
||||
logger.info(f"🔍 Database query result: {latest_db_strategy}")
|
||||
|
||||
if latest_db_strategy and latest_db_strategy.comprehensive_ai_analysis:
|
||||
logger.info(f"✅ Found latest strategy in database: {latest_db_strategy.id}")
|
||||
logger.info(f"🔍 Strategy comprehensive_ai_analysis keys: {list(latest_db_strategy.comprehensive_ai_analysis.keys()) if isinstance(latest_db_strategy.comprehensive_ai_analysis, dict) else 'Not a dict'}")
|
||||
return ResponseBuilder.create_success_response(
|
||||
message="Latest generated strategy retrieved successfully from database",
|
||||
data={
|
||||
@@ -676,8 +681,15 @@ async def get_latest_generated_strategy(
|
||||
"strategy_id": latest_db_strategy.id
|
||||
}
|
||||
)
|
||||
else:
|
||||
logger.info(f"⚠️ No strategy found in database for user: {user_id}")
|
||||
if latest_db_strategy:
|
||||
logger.info(f"🔍 Strategy found but no comprehensive_ai_analysis: {latest_db_strategy.id}")
|
||||
else:
|
||||
logger.info(f"🔍 No strategy record found at all for user: {user_id}")
|
||||
except Exception as db_error:
|
||||
logger.warning(f"⚠️ Database query failed: {str(db_error)}")
|
||||
logger.error(f"❌ Database error details: {type(db_error).__name__}: {str(db_error)}")
|
||||
|
||||
# Fallback: Check in-memory task status
|
||||
if not hasattr(generate_comprehensive_strategy_polling, '_task_status'):
|
||||
@@ -705,6 +717,7 @@ async def get_latest_generated_strategy(
|
||||
|
||||
completion_time = task_status.get("completed_at")
|
||||
logger.info(f"✅ Found completed strategy for user {user_id} at {completion_time}")
|
||||
logger.info(f"🔍 Strategy keys: {list(task_status.get('strategy', {}).keys())}")
|
||||
|
||||
if completion_time and (latest_completion_time is None or completion_time > latest_completion_time):
|
||||
latest_strategy = task_status.get("strategy")
|
||||
@@ -726,7 +739,7 @@ async def get_latest_generated_strategy(
|
||||
return ResponseBuilder.create_not_found_response(
|
||||
message="No completed strategy generation found",
|
||||
data={"user_id": user_id, "strategy": None}
|
||||
)
|
||||
)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"❌ Error getting latest generated strategy: {str(e)}")
|
||||
|
||||
@@ -592,9 +592,11 @@ class AIStrategyGenerator:
|
||||
raise RuntimeError("AI service returned empty implementation roadmap")
|
||||
|
||||
logger.info("✅ Implementation roadmap generated successfully")
|
||||
logger.info(f"🔍 Raw AI response for implementation roadmap: {json.dumps(response.get('data', {}), indent=2)}")
|
||||
|
||||
# Transform AI response to frontend format
|
||||
transformed_response = self._transform_ai_response_to_frontend_format(response.get("data", {}), "implementation_roadmap")
|
||||
logger.info(f"🔍 Transformed implementation roadmap: {json.dumps(transformed_response, indent=2)}")
|
||||
return transformed_response
|
||||
|
||||
except Exception as e:
|
||||
@@ -1019,6 +1021,8 @@ class AIStrategyGenerator:
|
||||
|
||||
def _transform_implementation_roadmap(self, ai_response: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Transform implementation roadmap to frontend format."""
|
||||
self.logger.info(f"🔍 Transforming implementation roadmap. Input: {json.dumps(ai_response, indent=2)}")
|
||||
|
||||
transformed = {
|
||||
"phases": [],
|
||||
"timeline": "12 months",
|
||||
@@ -1028,16 +1032,49 @@ class AIStrategyGenerator:
|
||||
"success_metrics": []
|
||||
}
|
||||
|
||||
# Extract roadmap data from AI response
|
||||
roadmap = ai_response.get("roadmap", {})
|
||||
if roadmap:
|
||||
if "phases" in roadmap:
|
||||
transformed["phases"] = roadmap["phases"][:4] # Limit to 4 phases
|
||||
if "timeline" in roadmap:
|
||||
transformed["timeline"] = roadmap["timeline"]
|
||||
if "milestones" in roadmap:
|
||||
transformed["milestones"] = roadmap["milestones"][:6] # Limit to 6 milestones
|
||||
# Extract roadmap data from AI response - data is at top level, not nested under "roadmap"
|
||||
if ai_response:
|
||||
# Extract phases
|
||||
phases = ai_response.get("phases", [])
|
||||
if phases:
|
||||
transformed["phases"] = phases[:4] # Limit to 4 phases
|
||||
|
||||
# Extract timeline
|
||||
timeline = ai_response.get("timeline", {})
|
||||
if timeline:
|
||||
if isinstance(timeline, dict):
|
||||
# If timeline is an object, extract the duration or use total_duration
|
||||
transformed["timeline"] = timeline.get("total_duration", "12 months")
|
||||
# Extract milestones from timeline object
|
||||
milestones = timeline.get("key_milestones", [])
|
||||
if milestones:
|
||||
transformed["milestones"] = milestones[:6]
|
||||
# Extract critical path from timeline object
|
||||
critical_path = timeline.get("critical_path", [])
|
||||
if critical_path:
|
||||
transformed["critical_path"] = critical_path[:5]
|
||||
else:
|
||||
# If timeline is a string, use it directly
|
||||
transformed["timeline"] = str(timeline)
|
||||
|
||||
# Extract total_duration if available
|
||||
total_duration = ai_response.get("total_duration")
|
||||
if total_duration:
|
||||
transformed["timeline"] = str(total_duration)
|
||||
|
||||
# Extract resource allocation
|
||||
resource_allocation = ai_response.get("resource_allocation", {})
|
||||
if resource_allocation:
|
||||
team_requirements = resource_allocation.get("team_requirements", [])
|
||||
if team_requirements:
|
||||
transformed["resource_requirements"] = team_requirements[:5]
|
||||
|
||||
# Extract success metrics
|
||||
success_metrics = ai_response.get("success_metrics", [])
|
||||
if success_metrics:
|
||||
transformed["success_metrics"] = success_metrics[:5]
|
||||
|
||||
self.logger.info(f"🔍 Final transformed implementation roadmap: {json.dumps(transformed, indent=2)}")
|
||||
return transformed
|
||||
|
||||
def _transform_risk_assessment(self, ai_response: Dict[str, Any]) -> Dict[str, Any]:
|
||||
|
||||
Reference in New Issue
Block a user