File size: 1,596 Bytes
c1d0c23
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
from typing import List, Dict, Any, Optional
import random
from tinytroupe.agent import TinyPerson
from tinytroupe.agent.social_types import Content
import tinytroupe.openai_utils as openai_utils

class ContentVariant:
    def __init__(self, text: str, strategy: str, parameters: Dict[str, Any], original_content: str):
        self.text = text
        self.strategy = strategy
        self.parameters = parameters
        self.original_content = original_content

class ContentVariantGenerator:
    """Generate multiple variants of input content"""

    def __init__(self, model: str = "gpt-4"):
        self.model = model

    def generate_variants(self, original_content: str, num_variants: int = 5,
                         target_personas: List[TinyPerson] = None) -> List[ContentVariant]:
        """Generate diverse variants of content"""
        variants = []

        # In a real implementation, we would use different prompts for different strategies
        # Here we use a simplified approach

        for i in range(num_variants):
            prompt = f"Rewrite the following content in a different style or tone:\n\n{original_content}"

            response = openai_utils.client().send_message(
                [{"role": "user", "content": prompt}]
            )

            variant_text = response["content"].strip()
            variants.append(ContentVariant(
                text=variant_text,
                strategy="style_variation",
                parameters={"variant_index": i},
                original_content=original_content
            ))

        return variants