File size: 1,828 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
45
46
47
48
49
50
51
52
53
54
55
56
import json
from typing import Dict, Any, Optional
from tinytroupe.agent import TinyPerson
from tinytroupe.agent.social_types import Content, Reaction
import tinytroupe.openai_utils as openai_utils

class LLMPredictor:
    """Use LLM reasoning for engagement prediction"""

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

    def predict(self, persona: TinyPerson, content: Content) -> Reaction:
        """Use LLM to predict engagement"""

        prompt = f"""
        You are predicting how a specific persona will react to content on a professional social network.

        PERSONA PROFILE:
        Name: {persona.name}
        Bio: {persona.minibio()}

        CONTENT TO EVALUATE:
        {content.text}

        TASK:
        Analyze whether this persona would engage with this content.
        Provide your prediction in JSON format:
        {{
            "will_engage": true/false,
            "probability": 0.0-1.0,
            "reasoning": "detailed explanation",
            "reaction_type": "like|comment|share|none",
            "comment": "predicted comment text if applicable"
        }}
        """

        response = openai_utils.client().send_message(
            [
                {"role": "system", "content": "You are an expert in social psychology and behavioral prediction."},
                {"role": "user", "content": prompt}
            ],
            temperature=0.3,
            response_format={"type": "json_object"}
        )

        prediction = json.loads(response["content"])

        return Reaction(
            will_engage=prediction["will_engage"],
            probability=prediction["probability"],
            reasoning=prediction["reasoning"],
            reaction_type=prediction["reaction_type"],
            comment=prediction.get("comment")
        )