Skip to content

AI Regenerator API Reference

The AI Regenerator module integrates Claude 3.5 Sonnet for advanced content analysis and generation in MacScrape.

Class: AIRegenerator

Initialization

from ai_integration.ai_regenerator import AIRegenerator

ai_regenerator = AIRegenerator()

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 analyze
  • prompt: 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 data
  • structure: Website structure specification
  • styles: CSS styles for the website

Returns:

  • A string containing the generated HTML
html = ai_regenerator.generate_site(analyzed_data, site_structure, custom_styles)

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

  1. OpenAI GPT Model

  2. Used for general text analysis and generation

  3. Provides diverse perspectives on content

  4. Anthropic Claude 3.5 Sonnet

  5. Specialized in detailed content analysis
  6. Excels at summarization and insight extraction

Prompt Engineering

Effective prompt engineering is crucial for obtaining high-quality results. Here are some tips:

  1. Be specific in your instructions
  2. Provide context about the content and desired output
  3. Use examples to guide the AI's response format
  4. 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.