"feat:enhance-podcast-topic-ai"
This commit is contained in:
@@ -23,9 +23,15 @@ def track_agent_usage_sync(user_id: str, model_name: str, prompt: str, response_
|
||||
provider_enum = APIProvider.GEMINI
|
||||
actual_provider_name = "gemini"
|
||||
elif "gpt" in model_lower or "openai" in model_lower or "mistral" in model_lower:
|
||||
# HuggingFace/Mistral often mapped to gpt-oss or mistral
|
||||
provider_enum = APIProvider.MISTRAL
|
||||
actual_provider_name = "huggingface"
|
||||
# Check if it's WaveSpeed vs HuggingFace based on context or model naming
|
||||
# WaveSpeed models don't have :cerebras suffix, HF models do
|
||||
if ":cerebras" in model_name.lower() or "huggingface" in model_name.lower():
|
||||
provider_enum = APIProvider.MISTRAL
|
||||
actual_provider_name = "huggingface"
|
||||
else:
|
||||
# Assume WaveSpeed for gpt models without provider suffix
|
||||
provider_enum = APIProvider.WAVESPEED
|
||||
actual_provider_name = "wavespeed"
|
||||
elif "claude" in model_lower or "anthropic" in model_lower:
|
||||
provider_enum = APIProvider.ANTHROPIC
|
||||
actual_provider_name = "anthropic"
|
||||
|
||||
@@ -340,6 +340,7 @@ class BaseALwrityAgent(ABC):
|
||||
prompt=prompt,
|
||||
user_id=self.user_id,
|
||||
preferred_hf_models=LOW_COST_REMOTE_MODELS,
|
||||
flow_type="sif_agent",
|
||||
),
|
||||
)
|
||||
logger.warning(
|
||||
|
||||
@@ -6,6 +6,7 @@ from datetime import datetime
|
||||
from loguru import logger
|
||||
from .base import SIFBaseAgent, TXTAI_AVAILABLE, Agent
|
||||
from services.intelligence.agents.core_agent_framework import BaseALwrityAgent, TaskProposal
|
||||
from services.database import has_onboarding_session
|
||||
|
||||
try:
|
||||
from services.intelligence.sif_integration import SIFIntegrationService
|
||||
@@ -22,11 +23,16 @@ class CompetitorResponseAgent(BaseALwrityAgent):
|
||||
super().__init__(user_id, "competitor_analyst", shared_llm_name, llm, **kwargs)
|
||||
|
||||
self.sif_service = None
|
||||
if SIF_AVAILABLE:
|
||||
if SIF_AVAILABLE and has_onboarding_session(user_id):
|
||||
try:
|
||||
self.sif_service = SIFIntegrationService(user_id)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to initialize SIF service for CompetitorResponseAgent: {e}")
|
||||
elif SIF_AVAILABLE:
|
||||
logger.debug(
|
||||
"Skipping SIF service initialization for CompetitorResponseAgent user {}: no onboarding session",
|
||||
user_id,
|
||||
)
|
||||
|
||||
def _create_txtai_agent(self):
|
||||
"""Create a specialized txtai Agent for competitor analysis."""
|
||||
|
||||
@@ -8,6 +8,7 @@ from .base import SIFBaseAgent, TXTAI_AVAILABLE, Agent
|
||||
from services.intelligence.agents.core_agent_framework import BaseALwrityAgent, TaskProposal
|
||||
from services.seo_tools.content_strategy_service import ContentStrategyService
|
||||
from services.analytics import PlatformAnalyticsService
|
||||
from services.database import has_onboarding_session
|
||||
|
||||
try:
|
||||
from services.intelligence.sif_integration import SIFIntegrationService
|
||||
@@ -26,11 +27,16 @@ class ContentStrategyAgent(BaseALwrityAgent):
|
||||
|
||||
self.sif_service = None
|
||||
self.content_strategy_service = ContentStrategyService()
|
||||
if SIF_AVAILABLE:
|
||||
if SIF_AVAILABLE and has_onboarding_session(user_id):
|
||||
try:
|
||||
self.sif_service = SIFIntegrationService(user_id)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to initialize SIF service for ContentStrategyAgent: {e}")
|
||||
elif SIF_AVAILABLE:
|
||||
logger.debug(
|
||||
"Skipping SIF service initialization for ContentStrategyAgent user {}: no onboarding session",
|
||||
user_id,
|
||||
)
|
||||
|
||||
def _create_txtai_agent(self):
|
||||
"""Create a specialized txtai Agent for content strategy with tools."""
|
||||
|
||||
@@ -6,6 +6,7 @@ from datetime import datetime
|
||||
from loguru import logger
|
||||
from .base import SIFBaseAgent, TXTAI_AVAILABLE, Agent
|
||||
from services.intelligence.agents.core_agent_framework import BaseALwrityAgent, TaskProposal
|
||||
from services.database import has_onboarding_session
|
||||
|
||||
try:
|
||||
from services.intelligence.sif_integration import SIFIntegrationService
|
||||
@@ -22,11 +23,16 @@ class SEOOptimizationAgent(BaseALwrityAgent):
|
||||
super().__init__(user_id, "seo_specialist", shared_llm_name, llm, **kwargs)
|
||||
|
||||
self.sif_service = None
|
||||
if SIF_AVAILABLE:
|
||||
if SIF_AVAILABLE and has_onboarding_session(user_id):
|
||||
try:
|
||||
self.sif_service = SIFIntegrationService(user_id)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to initialize SIF service for SEOOptimizationAgent: {e}")
|
||||
elif SIF_AVAILABLE:
|
||||
logger.debug(
|
||||
"Skipping SIF service initialization for SEOOptimizationAgent user {}: no onboarding session",
|
||||
user_id,
|
||||
)
|
||||
|
||||
def _create_txtai_agent(self):
|
||||
"""Create a specialized txtai Agent for SEO optimization."""
|
||||
|
||||
@@ -6,6 +6,7 @@ from datetime import datetime
|
||||
from loguru import logger
|
||||
from .base import SIFBaseAgent, TXTAI_AVAILABLE, Agent
|
||||
from services.intelligence.agents.core_agent_framework import BaseALwrityAgent, TaskProposal
|
||||
from services.database import has_onboarding_session
|
||||
|
||||
try:
|
||||
from services.intelligence.sif_integration import SIFIntegrationService
|
||||
@@ -22,11 +23,16 @@ class SocialAmplificationAgent(BaseALwrityAgent):
|
||||
super().__init__(user_id, "social_media_manager", shared_llm_name, llm, **kwargs)
|
||||
|
||||
self.sif_service = None
|
||||
if SIF_AVAILABLE:
|
||||
if SIF_AVAILABLE and has_onboarding_session(user_id):
|
||||
try:
|
||||
self.sif_service = SIFIntegrationService(user_id)
|
||||
except Exception as e:
|
||||
logger.warning(f"Failed to initialize SIF service for SocialAmplificationAgent: {e}")
|
||||
elif SIF_AVAILABLE:
|
||||
logger.debug(
|
||||
"Skipping SIF service initialization for SocialAmplificationAgent user {}: no onboarding session",
|
||||
user_id,
|
||||
)
|
||||
|
||||
def _create_txtai_agent(self):
|
||||
"""Create a specialized txtai Agent for social media."""
|
||||
|
||||
@@ -13,6 +13,7 @@ from datetime import datetime, timedelta
|
||||
from dataclasses import dataclass, asdict
|
||||
from loguru import logger
|
||||
|
||||
from services.database import has_onboarding_session
|
||||
from ..txtai_service import TxtaiIntelligenceService
|
||||
from ..semantic_cache import semantic_cache_manager
|
||||
from ..sif_integration import SIFIntegrationService
|
||||
@@ -74,9 +75,15 @@ class RealTimeSemanticMonitor:
|
||||
|
||||
def __init__(self, user_id: str):
|
||||
self.user_id = user_id
|
||||
self.intelligence_service = TxtaiIntelligenceService(user_id)
|
||||
self.cache_manager = semantic_cache_manager
|
||||
self.sif_service = SIFIntegrationService(user_id)
|
||||
self.sif_enabled = has_onboarding_session(user_id)
|
||||
self.intelligence_service = TxtaiIntelligenceService(user_id) if self.sif_enabled else None
|
||||
self.sif_service = SIFIntegrationService(user_id) if self.sif_enabled else None
|
||||
if not self.sif_enabled:
|
||||
logger.info(
|
||||
"Skipping semantic monitor SIF initialization for user {}: no onboarding session found",
|
||||
user_id,
|
||||
)
|
||||
|
||||
# Initialize monitoring agents (lazy initialization to avoid circular imports)
|
||||
self.strategy_agent = None
|
||||
@@ -239,6 +246,9 @@ class RealTimeSemanticMonitor:
|
||||
async def _check_semantic_health(self) -> List[SemanticHealthMetric]:
|
||||
"""Check overall semantic health of user's content."""
|
||||
metrics = []
|
||||
|
||||
if not self.sif_enabled or not self.sif_service:
|
||||
return metrics
|
||||
|
||||
try:
|
||||
# Get current semantic insights
|
||||
@@ -301,6 +311,8 @@ class RealTimeSemanticMonitor:
|
||||
async def _monitor_competitors(self) -> List[CompetitorSemanticSnapshot]:
|
||||
"""Monitor competitor semantic positioning."""
|
||||
snapshots = []
|
||||
if not self.sif_enabled or not self.intelligence_service:
|
||||
return snapshots
|
||||
try:
|
||||
# 1. Get competitors from SIF integration
|
||||
# We assume SIFIntegrationService has methods to get competitor data or we query index
|
||||
@@ -370,6 +382,9 @@ class RealTimeSemanticMonitor:
|
||||
async def _analyze_content_performance(self) -> List[ContentSemanticInsight]:
|
||||
"""Analyze content performance and identify insights using SIF Agents."""
|
||||
insights = []
|
||||
|
||||
if not self.sif_enabled or not self.sif_service:
|
||||
return insights
|
||||
|
||||
try:
|
||||
current_time = datetime.now()
|
||||
|
||||
@@ -34,7 +34,12 @@ class SharedLLMWrapper:
|
||||
try:
|
||||
# We ignore kwargs like 'max_tokens' as llm_text_gen handles defaults,
|
||||
# but we could map them if needed.
|
||||
return llm_text_gen(prompt, user_id=self.user_id)
|
||||
return llm_text_gen(
|
||||
prompt,
|
||||
user_id=self.user_id,
|
||||
preferred_hf_models=LOW_COST_SHARED_REMOTE_MODELS,
|
||||
flow_type="sif_agent",
|
||||
)
|
||||
except Exception as e:
|
||||
logger.error(f"SharedLLMWrapper failed to generate text: {e}")
|
||||
return f"[ERROR: Shared LLM generation failed for user {self.user_id}]"
|
||||
@@ -44,6 +49,12 @@ class SharedLLMWrapper:
|
||||
|
||||
_local_llm_cache = {}
|
||||
|
||||
LOW_COST_SHARED_REMOTE_MODELS = [
|
||||
"Qwen/Qwen2.5-1.5B-Instruct",
|
||||
"Qwen/Qwen2.5-0.5B-Instruct",
|
||||
"TinyLlama/TinyLlama-1.1B-Chat-v1.0",
|
||||
]
|
||||
|
||||
LOCAL_LLM_FALLBACKS = [
|
||||
"Qwen/Qwen2.5-1.5B-Instruct",
|
||||
"Qwen/Qwen2.5-0.5B-Instruct",
|
||||
|
||||
@@ -12,7 +12,7 @@ from datetime import datetime
|
||||
from sqlalchemy import select, desc
|
||||
import json
|
||||
|
||||
from services.database import get_session_for_user
|
||||
from services.database import get_session_for_user, has_onboarding_session
|
||||
from models.onboarding import WebsiteAnalysis, OnboardingSession, CompetitorAnalysis
|
||||
|
||||
# Import existing SIF components
|
||||
@@ -1070,8 +1070,14 @@ class SIFIntegrationAPI:
|
||||
def __init__(self):
|
||||
self.services: Dict[str, SIFIntegrationService] = {}
|
||||
|
||||
def get_service(self, user_id: str) -> SIFIntegrationService:
|
||||
def get_service(self, user_id: str) -> Optional[SIFIntegrationService]:
|
||||
"""Get or create SIF service for a user."""
|
||||
if not has_onboarding_session(user_id):
|
||||
logger.debug(
|
||||
"Skipping SIF service creation for user {} via SIFIntegrationAPI: no onboarding session",
|
||||
user_id,
|
||||
)
|
||||
return None
|
||||
if user_id not in self.services:
|
||||
self.services[user_id] = SIFIntegrationService(user_id)
|
||||
return self.services[user_id]
|
||||
@@ -1079,11 +1085,25 @@ class SIFIntegrationAPI:
|
||||
async def get_semantic_insights_with_cache(self, user_id: str, website_data: Dict[str, Any]) -> Dict[str, Any]:
|
||||
"""Get semantic insights with caching metadata."""
|
||||
service = self.get_service(user_id)
|
||||
if not service:
|
||||
return {
|
||||
"source": "skipped",
|
||||
"reason": "no_onboarding_session",
|
||||
"insights": {},
|
||||
}
|
||||
return await service.get_semantic_insights(website_data)
|
||||
|
||||
async def get_cache_performance(self, user_id: str) -> Dict[str, Any]:
|
||||
"""Get cache performance metrics for a user."""
|
||||
service = self.get_service(user_id)
|
||||
if not service:
|
||||
return {
|
||||
"user_id": user_id,
|
||||
"cache_enabled": False,
|
||||
"performance": {},
|
||||
"reason": "no_onboarding_session",
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
}
|
||||
stats = service.get_cache_performance_stats()
|
||||
|
||||
return {
|
||||
@@ -1096,6 +1116,13 @@ class SIFIntegrationAPI:
|
||||
async def invalidate_user_cache(self, user_id: str, reason: str = "api_request") -> Dict[str, Any]:
|
||||
"""Invalidate cache for a specific user."""
|
||||
service = self.get_service(user_id)
|
||||
if not service:
|
||||
return {
|
||||
"user_id": user_id,
|
||||
"success": False,
|
||||
"reason": "no_onboarding_session",
|
||||
"timestamp": datetime.now().isoformat(),
|
||||
}
|
||||
success = await service.invalidate_user_cache(reason)
|
||||
|
||||
return {
|
||||
|
||||
Reference in New Issue
Block a user