Detailed Docs & Onboarding improvements

This commit is contained in:
ajaysi
2025-04-21 16:34:18 +05:30
parent 6e60a9fd28
commit c5b47bd32f
42 changed files with 5114 additions and 79 deletions

View File

@@ -2,6 +2,7 @@
import streamlit as st
from loguru import logger
import os
from typing import Dict, Any
from ..manager import APIKeyManager
from .base import render_navigation_buttons, render_step_indicator, render_tab_style
@@ -161,6 +162,15 @@ def render_alwrity_integrations(api_key_manager: APIKeyManager) -> Dict[str, Any
}
}
# Set INTEGRATION_DONE to True in .env file and environment
try:
with open('.env', 'a') as f:
f.write("\nINTEGRATION_DONE=True")
os.environ['INTEGRATION_DONE'] = "True"
logger.info("Set INTEGRATION_DONE=True in .env and environment")
except Exception as e:
logger.error(f"Failed to set INTEGRATION_DONE: {str(e)}")
# Update progress and move to next step
st.session_state['current_step'] = 6
st.rerun()

View File

@@ -62,10 +62,11 @@ def render_step_indicator(current_step: int, total_steps: int) -> None:
steps = [
("🔑", "AI LLM", 1),
("👤", "AI Research", 2),
("🎨", "Personalization", 3),
("🔄", "Integrations", 4),
("", "Complete", 5)
("🔍", "Website Analysis", 2),
("👤", "AI Research", 3),
("🎨", "Personalization", 4),
("🔄", "Integrations", 5),
("", "Complete", 6)
]
html = '<div class="step-indicator">'

View File

@@ -45,37 +45,139 @@ def render_final_setup(api_key_manager: APIKeyManager) -> Dict[str, Any]:
"""
logger.info("[render_final_setup] Rendering final setup component")
st.markdown("### Step 5: Final Setup")
st.markdown("### Step 6: Final Setup & Validation")
# Load main config
main_config = load_main_config()
# Display configuration summary
st.markdown("#### Configuration Summary")
# Create tabs for each step
tabs = st.tabs([
"Step 1: AI LLM Setup",
"Step 2: Website Analysis",
"Step 3: AI Research",
"Step 4: Personalization",
"Step 5: Integrations"
])
# Blog Content Characteristics
st.markdown("##### Blog Content Characteristics")
blog_settings = main_config.get("Blog Content Characteristics", {})
st.write(f"- Blog Length: {blog_settings.get('Blog Length', '2000')}")
st.write(f"- Blog Tone: {blog_settings.get('Blog Tone', 'Professional')}")
st.write(f"- Blog Demographic: {blog_settings.get('Blog Demographic', 'Professional')}")
st.write(f"- Blog Type: {blog_settings.get('Blog Type', 'Informational')}")
# Step 1: AI LLM Setup
with tabs[0]:
st.markdown("#### AI LLM Configuration")
# Get API keys from environment
openai_key = os.getenv('OPENAI_API_KEY', 'Not configured')
gemini_key = os.getenv('GEMINI_API_KEY', 'Not configured')
anthropic_key = os.getenv('ANTHROPIC_API_KEY', 'Not configured')
mistral_key = os.getenv('MISTRAL_API_KEY', 'Not configured')
# Display API keys (masked)
st.markdown("##### API Keys")
col1, col2 = st.columns(2)
with col1:
st.markdown(f"**OpenAI API Key:** {'*' * 8}{openai_key[-4:] if openai_key != 'Not configured' else ''}")
st.markdown(f"**Google Gemini API Key:** {'*' * 8}{gemini_key[-4:] if gemini_key != 'Not configured' else ''}")
with col2:
st.markdown(f"**Anthropic API Key:** {'*' * 8}{anthropic_key[-4:] if anthropic_key != 'Not configured' else ''}")
st.markdown(f"**Mistral API Key:** {'*' * 8}{mistral_key[-4:] if mistral_key != 'Not configured' else ''}")
# LLM Options
st.markdown("##### LLM Options")
llm_settings = main_config.get("LLM Options", {})
st.write(f"- GPT Provider: {llm_settings.get('GPT Provider', 'google')}")
st.write(f"- Model: {llm_settings.get('Model', 'gemini-1.5-flash-latest')}")
st.write(f"- Temperature: {llm_settings.get('Temperature', 0.7)}")
st.write(f"- Max Tokens: {llm_settings.get('Max Tokens', 4000)}")
# Step 2: Website Analysis
with tabs[1]:
st.markdown("#### Website Analysis Configuration")
# Get website URL from environment
website_url = os.getenv('WEBSITE_URL', 'Not configured')
# Display website URL
st.markdown("##### Website URL")
st.markdown(f"**Website URL:** {website_url}")
# Display website analysis settings
st.markdown("##### Analysis Settings")
st.markdown("Website analysis settings will be used to understand your content style and preferences.")
# Personalization Settings
st.markdown("##### Personalization Settings")
personalization = main_config.get("personalization", {})
st.write(f"- Writing Tone: {personalization.get('writing_tone', 'Professional')}")
st.write(f"- Target Audience: {personalization.get('target_audience', 'General')}")
st.write(f"- Content Type: {personalization.get('content_type', 'Blog Posts')}")
# Step 3: AI Research
with tabs[2]:
st.markdown("#### AI Research Configuration")
# Get research API keys from environment
serpapi_key = os.getenv('SERPAPI_KEY', 'Not configured')
tavily_key = os.getenv('TAVILY_API_KEY', 'Not configured')
metaphor_key = os.getenv('METAPHOR_API_KEY', 'Not configured')
firecrawl_key = os.getenv('FIRECRAWL_API_KEY', 'Not configured')
# Display API keys (masked)
st.markdown("##### Research API Keys")
col1, col2 = st.columns(2)
with col1:
st.markdown(f"**SerpAPI Key:** {'*' * 8}{serpapi_key[-4:] if serpapi_key != 'Not configured' else ''}")
st.markdown(f"**Tavily API Key:** {'*' * 8}{tavily_key[-4:] if tavily_key != 'Not configured' else ''}")
with col2:
st.markdown(f"**Metaphor API Key:** {'*' * 8}{metaphor_key[-4:] if metaphor_key != 'Not configured' else ''}")
st.markdown(f"**Firecrawl API Key:** {'*' * 8}{firecrawl_key[-4:] if firecrawl_key != 'Not configured' else ''}")
# Step 4: Personalization
with tabs[3]:
st.markdown("#### Personalization Configuration")
# Display personalization settings from main config
with st.popover("Blog Content Characteristics", help="Click to see details about blog content settings"):
st.markdown("##### Blog Content Characteristics")
blog_settings = main_config.get("Blog Content Characteristics", {})
st.write(f"- Blog Length: {blog_settings.get('Blog Length', '2000')}")
st.write(f"- Blog Tone: {blog_settings.get('Blog Tone', 'Professional')}")
st.write(f"- Blog Demographic: {blog_settings.get('Blog Demographic', 'Professional')}")
st.write(f"- Blog Type: {blog_settings.get('Blog Type', 'Informational')}")
st.write(f"- Blog Language: {blog_settings.get('Blog Language', 'English')}")
st.write(f"- Blog Output Format: {blog_settings.get('Blog Output Format', 'markdown')}")
st.markdown("These settings define the overall structure and style of your blog content.")
with st.popover("Blog Images Details", help="Click to see details about image generation settings"):
st.markdown("##### Blog Images Details")
image_settings = main_config.get("Blog Images Details", {})
st.write(f"- Image Generation Model: {image_settings.get('Image Generation Model', 'stable-diffusion')}")
st.write(f"- Number of Blog Images: {image_settings.get('Number of Blog Images', 1)}")
st.markdown("These settings control how images are generated for your blog posts.")
with st.popover("LLM Options", help="Click to see details about language model settings"):
st.markdown("##### LLM Options")
llm_settings = main_config.get("LLM Options", {})
st.write(f"- GPT Provider: {llm_settings.get('GPT Provider', 'google')}")
st.write(f"- Model: {llm_settings.get('Model', 'gemini-1.5-flash-latest')}")
st.write(f"- Temperature: {llm_settings.get('Temperature', 0.7)}")
st.write(f"- Top-p: {llm_settings.get('Top-p', 0.9)}")
st.write(f"- Max Tokens: {llm_settings.get('Max Tokens', 4000)}")
st.write(f"- Frequency Penalty: {llm_settings.get('Frequency Penalty', 1.0)}")
st.write(f"- Presence Penalty: {llm_settings.get('Presence Penalty', 1.0)}")
st.markdown("These settings control the behavior of the language model used for content generation.")
with st.popover("Search Engine Parameters", help="Click to see details about search engine settings"):
st.markdown("##### Search Engine Parameters")
search_settings = main_config.get("Search Engine Parameters", {})
st.write(f"- Geographic Location: {search_settings.get('Geographic Location', 'us')}")
st.write(f"- Search Language: {search_settings.get('Search Language', 'en')}")
st.write(f"- Number of Results: {search_settings.get('Number of Results', 10)}")
st.write(f"- Time Range: {search_settings.get('Time Range', 'anytime')}")
st.markdown("These settings control how search engines are used for research and content creation.")
# Step 5: Integrations
with tabs[4]:
st.markdown("#### ALwrity Integrations Configuration")
# Display integrations settings
st.markdown("##### Website Platforms")
st.info("WordPress integration will be available in the next update")
st.info("Wix integration will be available in the next update")
st.markdown("##### Social Media")
st.info("Facebook integration will be available in the next update")
st.info("Instagram integration will be available in the next update")
st.markdown("##### Analytics Tools")
st.info("Google Search Console integration will be available in the next update")
# Navigation buttons
col1, col2 = st.columns(2)
@@ -90,37 +192,37 @@ def render_final_setup(api_key_manager: APIKeyManager) -> Dict[str, Any]:
if st.button("Complete Setup →"):
logger.info("[render_final_setup] User clicked complete setup")
try:
# Verify all required API keys are present and valid
is_valid = check_all_api_keys(api_key_manager)
# Log the current API keys in the manager
logger.info("[render_final_setup] Current API keys in manager:")
for key, value in api_key_manager.api_keys.items():
if value:
logger.info(f" - {key}: {'*' * 8}{value[-4:]}")
else:
logger.info(f" - {key}: Not set")
if not is_valid:
st.error("⚠️ Some required API keys are missing")
st.markdown("### Missing API Keys and Impact")
# Display impact messages
st.warning("⚠️ Missing AI Provider: At least one AI provider (OpenAI, Google Gemini, Anthropic Claude, or Mistral) is required.")
st.warning("⚠️ Missing Research Provider: At least one research provider (SerpAPI, Tavily, Metaphor, or Firecrawl) is required.")
st.markdown("""
<div style='background-color: #fff3cd; color: #856404; padding: 1rem; border-radius: 0.25rem; margin-top: 1rem;'>
<h4 style='margin: 0;'>Required Keys:</h4>
<ul style='margin: 0.5rem 0 0;'>
<li>At least one AI provider (OpenAI, Google Gemini, Anthropic Claude, or Mistral)</li>
<li>At least one research provider (SerpAPI, Tavily, Metaphor, or Firecrawl)</li>
</ul>
<p style='margin: 0.5rem 0 0;'>Please configure the required keys before proceeding.</p>
</div>
""", unsafe_allow_html=True)
return {"current_step": 6, "changes_made": True}
# Log environment variables
logger.info("[render_final_setup] Checking environment variables:")
for key in os.environ.keys():
if any(provider in key for provider in ['API_KEY', 'SERPAPI', 'TAVILY', 'METAPHOR', 'FIRECRAWL']):
value = os.getenv(key)
if value:
logger.info(f" - {key}: {'*' * 8}{value[-4:]}")
else:
logger.error(f" - {key}: Not set")
# Save final configuration
if not os.path.exists("lib/workspace/alwrity_config"):
os.makedirs("lib/workspace/alwrity_config")
config_path = os.path.join("lib", "workspace", "alwrity_config", "main_config.json")
with open(config_path, 'w') as f:
json.dump(main_config, f, indent=4)
# Set FINAL_SETUP_COMPLETE to True in .env file and environment
try:
with open('.env', 'a') as f:
f.write("\nFINAL_SETUP_COMPLETE=True")
os.environ['FINAL_SETUP_COMPLETE'] = "True"
logger.info("Set FINAL_SETUP_COMPLETE=True in .env and environment")
except Exception as e:
logger.error(f"Failed to set FINAL_SETUP_COMPLETE: {str(e)}")
# Show success message with HTML formatting
st.markdown("""
<div style='background-color: #d4edda; color: #155724; padding: 1rem; border-radius: 0.25rem;'>
@@ -133,11 +235,11 @@ def render_final_setup(api_key_manager: APIKeyManager) -> Dict[str, Any]:
st.session_state['setup_completed'] = True
# Redirect to main application
st.switch_page("alwrity.py")
st.rerun()
except Exception as e:
error_msg = f"Error completing setup: {str(e)}"
logger.error(f"[render_final_setup] {error_msg}")
st.error(error_msg)
return {"current_step": 5, "changes_made": True}
return {"current_step": 6, "changes_made": True}

View File

@@ -4,6 +4,7 @@ import streamlit as st
from loguru import logger
import sys
import json
import os
from typing import Dict, Any
from ..manager import APIKeyManager
from ....web_crawlers.async_web_crawler import AsyncWebCrawlerService
@@ -495,6 +496,15 @@ def render_personalization_setup(api_key_manager: APIKeyManager) -> Dict[str, An
}
if save_main_config(main_config):
# Set PERSONALIZATION_DONE to True in .env file and environment
try:
with open('.env', 'a') as f:
f.write("\nPERSONALIZATION_DONE=True")
os.environ['PERSONALIZATION_DONE'] = "True"
logger.info("Set PERSONALIZATION_DONE=True in .env and environment")
except Exception as e:
logger.error(f"Failed to set PERSONALIZATION_DONE: {str(e)}")
st.success("✅ Your personalization settings have been saved successfully!")
else:
st.error("Unable to save settings. Please try again.")
@@ -702,8 +712,20 @@ def render_personalization_setup(api_key_manager: APIKeyManager) -> Dict[str, An
st.success("Configuration saved successfully!")
# Navigation buttons with correct arguments
if render_navigation_buttons(3, 4, changes_made=True):
st.session_state.current_step = 4
if render_navigation_buttons(4, 6, changes_made=True):
# Set PERSONALIZATION_DONE to False if not already set to True
if 'PERSONALIZATION_DONE' not in os.environ or os.environ['PERSONALIZATION_DONE'] != "True":
try:
with open('.env', 'a') as f:
f.write("\nPERSONALIZATION_DONE=False")
os.environ['PERSONALIZATION_DONE'] = "False"
logger.info("Set PERSONALIZATION_DONE=False in .env and environment")
except Exception as e:
logger.error(f"Failed to set PERSONALIZATION_DONE: {str(e)}")
# Update the current step to 5 (ALwrity integrations)
st.session_state.current_step = 5
logger.info("Moving to step 5: ALwrity integrations")
st.rerun()
return {"current_step": 3, "changes_made": True}
return {"current_step": 4, "changes_made": True}

View File

@@ -9,6 +9,7 @@ import sys
from typing import Dict, Any
from ..manager import APIKeyManager
from .base import render_navigation_buttons
import os
# Configure logger to output to both file and stdout
logger.remove() # Remove default handler
@@ -45,6 +46,24 @@ def render_website_setup(api_key_manager: APIKeyManager) -> Dict[str, Any]:
url = st.text_input("Enter your website URL, if you own one", placeholder="https://example.com")
logger.info(f"[render_website_setup] URL input value: {url}")
# Save URL to .env file
try:
if url:
# Save to .env file
with open('.env', 'a') as f:
f.write(f"\nWEBSITE_URL={url}")
# Set environment variable
os.environ['WEBSITE_URL'] = url
logger.info(f"[render_website_setup] Saved website URL to .env: {url}")
else:
# Set default value if no URL provided
with open('.env', 'a') as f:
f.write("\nWEBSITE_URL=no_website_provided")
os.environ['WEBSITE_URL'] = "no_website_provided"
logger.info("[render_website_setup] Set default website URL: no_website_provided")
except Exception as e:
logger.error(f"[render_website_setup] Failed to save website URL: {str(e)}")
analyze_type = st.radio(
"Analysis Type",
["Basic Website Analysis", "Full Website Analysis with SEO"],