ALwrity version 0.5.5

This commit is contained in:
ajaysi
2025-08-19 21:48:33 +05:30
parent 5f104bf427
commit 74e22b421a
97 changed files with 16770 additions and 5000 deletions

View File

@@ -12,8 +12,8 @@ import json
from collections import Counter, defaultdict
# Import AI providers
from llm_providers.main_text_generation import llm_text_gen
from llm_providers.gemini_provider import gemini_structured_json_response
from services.llm_providers.main_text_generation import llm_text_gen
from services.llm_providers.gemini_provider import gemini_structured_json_response
# Import services
from services.ai_service_manager import AIServiceManager
@@ -213,8 +213,19 @@ class AIEngineService:
}
)
# Parse and return the AI response
result = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
result = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
result = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
recommendations = result.get('recommendations', [])
logger.info(f"✅ Generated {len(recommendations)} AI content recommendations")
return recommendations
@@ -355,8 +366,19 @@ class AIEngineService:
}
)
# Parse and return the AI response
predictions = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
predictions = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
predictions = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
logger.info("✅ AI performance predictions completed")
return predictions
@@ -495,7 +517,19 @@ class AIEngineService:
)
# Parse and return the AI response
competitive_intelligence = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
competitive_intelligence = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
competitive_intelligence = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
logger.info("✅ AI competitive intelligence completed")
return competitive_intelligence
@@ -633,8 +667,20 @@ class AIEngineService:
}
)
# Parse and return the AI response
result = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
result = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
result = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
strategic_insights = result.get('strategic_insights', [])
logger.info(f"✅ Generated {len(strategic_insights)} AI strategic insights")
return strategic_insights
@@ -733,8 +779,19 @@ class AIEngineService:
}
)
# Parse and return the AI response
quality_analysis = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
quality_analysis = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
quality_analysis = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
logger.info("✅ AI content quality analysis completed")
return quality_analysis

View File

@@ -12,8 +12,8 @@ import json
from collections import Counter, defaultdict
# Import AI providers
from llm_providers.main_text_generation import llm_text_gen
from llm_providers.gemini_provider import gemini_structured_json_response
from services.llm_providers.main_text_generation import llm_text_gen
from services.llm_providers.gemini_provider import gemini_structured_json_response
# Import existing modules (will be updated to use FastAPI services)
from services.database import get_db_session
@@ -194,8 +194,19 @@ class CompetitorAnalyzer:
}
)
# Parse and return the AI response
market_position = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
market_position = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
market_position = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
logger.info("✅ AI market position analysis completed")
return market_position
@@ -306,8 +317,20 @@ class CompetitorAnalyzer:
}
)
# Parse and return the AI response
result = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
result = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
result = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
content_gaps = result.get('content_gaps', [])
logger.info(f"✅ AI content gap identification completed: {len(content_gaps)} gaps found")
return content_gaps
@@ -399,8 +422,20 @@ class CompetitorAnalyzer:
}
)
# Parse and return the AI response
result = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
result = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
result = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
competitive_insights = result.get('competitive_insights', [])
logger.info(f"✅ AI competitive insights generated: {len(competitive_insights)} insights")
return competitive_insights

View File

@@ -12,8 +12,8 @@ import json
from collections import Counter, defaultdict
# Import AI providers
from llm_providers.main_text_generation import llm_text_gen
from llm_providers.gemini_provider import gemini_structured_json_response
from services.llm_providers.main_text_generation import llm_text_gen
from services.llm_providers.gemini_provider import gemini_structured_json_response
# Import existing modules (will be updated to use FastAPI services)
from services.database import get_db_session
@@ -155,8 +155,19 @@ class KeywordResearcher:
}
)
# Parse and return the AI response
trend_analysis = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
trend_analysis = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
trend_analysis = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
logger.info("✅ AI keyword trend analysis completed")
return trend_analysis
@@ -283,8 +294,20 @@ class KeywordResearcher:
}
)
# Parse and return the AI response
intent_analysis = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
intent_analysis = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
intent_analysis = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
logger.info("✅ AI search intent analysis completed")
return intent_analysis
@@ -396,8 +419,20 @@ class KeywordResearcher:
}
)
# Parse and return the AI response
result = json.loads(response)
# Handle response - gemini_structured_json_response returns dict directly
if isinstance(response, dict):
result = response
elif isinstance(response, str):
# If it's a string, try to parse as JSON
try:
result = json.loads(response)
except json.JSONDecodeError as e:
logger.error(f"Failed to parse AI response as JSON: {e}")
raise Exception(f"Invalid AI response format: {str(e)}")
else:
logger.error(f"Unexpected response type from AI service: {type(response)}")
raise Exception(f"Unexpected response type from AI service: {type(response)}")
opportunities = result.get('opportunities', [])
logger.info(f"✅ AI opportunity identification completed: {len(opportunities)} opportunities found")
return opportunities