AI Regenerator API Reference
The AI Regenerator module integrates Claude 3.5 Sonnet for advanced content analysis and generation in MacScrape.
Class: AIRegenerator
Initialization
Methods
async analyze_content(data: Dict, prompt: Optional[str] = None) -> Dict
Analyzes the given content using AI models.
Parameters:
data
: Dictionary containing the content to analyzeprompt
: Optional custom prompt for analysis
Returns:
- A dictionary containing the AI analysis results
results = await ai_regenerator.analyze_content(
{"url": "https://example.com", "content": "Example text..."},
prompt="Summarize the main points and sentiment"
)
generate_site(data: Dict, structure: Dict, styles: Dict) -> str
Generates an HTML website based on the analyzed data.
Parameters:
data
: Analyzed datastructure
: Website structure specificationstyles
: CSS styles for the website
Returns:
- A string containing the generated HTML
Internal Workflow
sequenceDiagram
participant Client
participant AIRegenerator
participant OpenAI
participant Anthropic
Client->>AIRegenerator: analyze_content(data, prompt)
AIRegenerator->>OpenAI: parse(prompt + content)
OpenAI-->>AIRegenerator: openai_result
AIRegenerator->>Anthropic: parse(prompt + content)
Anthropic-->>AIRegenerator: anthropic_result
AIRegenerator->>AIRegenerator: combine_results()
AIRegenerator-->>Client: combined_analysis
AI Models
-
OpenAI GPT Model
-
Used for general text analysis and generation
-
Provides diverse perspectives on content
-
Anthropic Claude 3.5 Sonnet
- Specialized in detailed content analysis
- Excels at summarization and insight extraction
Prompt Engineering
Effective prompt engineering is crucial for obtaining high-quality results. Here are some tips:
- Be specific in your instructions
- Provide context about the content and desired output
- Use examples to guide the AI's response format
- Break complex tasks into smaller, manageable prompts
Example prompt template:
Analyze the following web content:
{content}
Please provide:
1. A concise summary (50 words max)
2. The main topic or theme
3. Three key points
4. Overall sentiment (positive, negative, or neutral)
5. Any notable statistics or data points
Error Handling
- API call failures are retried with exponential backoff
- Timeout errors are caught and logged
- Invalid or insufficient responses trigger fallback analysis methods
Performance Optimization
- Implement caching for frequently analyzed content
- Use batch processing for multiple content pieces
- Adjust token limits based on content length and analysis depth
Ethical Considerations
- Implement content filtering to avoid processing sensitive or inappropriate material
- Clearly disclose AI usage in generated content
- Regularly audit AI outputs for bias and accuracy
Example: Custom Analysis Pipeline
class CustomAIRegenerator(AIRegenerator):
async def custom_analysis(self, content):
# Implement custom analysis logic
pass
async def analyze_content(self, data, prompt=None):
results = await super().analyze_content(data, prompt)
results['custom_analysis'] = await self.custom_analysis(data['content'])
return results
Next Steps
Explore how to integrate the AI Regenerator with the Orchestrator for a complete web analysis pipeline.