File size: 4,933 Bytes
e386167
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
import json
import random
from openai import OpenAI
import os
from dotenv import load_dotenv
from extract_features import parse_chat, extract_inside_jokes, random_memory

# Load environment variables
load_dotenv()

def generate_inside_jokes(count=3):
    # Configure Groq API
    client = OpenAI(
        api_key=os.environ.get("GROQ_API_KEY"),
        base_url="https://api.groq.com/openai/v1",
    )

    messages = parse_chat("chat.txt")
    data = extract_inside_jokes(messages)

    # meaningful memory for Sarah
    random_real_memory = select_meaningful_memory(messages, client)

    prompt = f"""

You are a comedian whoose task is to generate funny inside jokes for two best friends: Aman and Sarah.

They have a very close, playful, supportive and affectionate friendship.



Here is the context from their WhatsApp chats:



Funny lines they've said:

{json.dumps(data['funny'][:30], indent=2)}



Cute moments between them:

{json.dumps(data['cute'][:20], indent=2)}



Shared vocabulary & patterns:

{json.dumps(data['top_words'][:20], indent=2)}



One real memory to set the mood:

"{random_real_memory}"



Your Goal:

Generate {count} ORIGINAL inside jokes that sound exactly like something they would say to each other.

The jokes should be a mix of funny, teasing, and heartfelt(more of funny).



Guidelines:

1. **Be Human**: Use casual language, slang (if fits their vibe), and natural phrasing. Avoid robotic or stiff sentence structures.

2. **Show, Don't Tell**: Instead of saying "You are funny," say "Remember that time you tried to tell a joke and choked on water? Classic."

3. **Mix Humor and Heart**: The best inside jokes often come from a place of love. "Fries before guys" is funny but also shows loyalty.

4. **Use Context**: Reference their shared vocabulary or specific funny/cute moments provided above.

5. **Be creative**: The best inside jokes often come from a place of love. "Fries before guys" is funny but also shows loyalty.

6. Try to make atleast one line jokes





Output Format:



INSIDE JOKES:

1. [Joke/Phrase] 

2. [Joke/Phrase] 

...



MEMORY FOR SARAH:

"{random_real_memory}"

    """

    response = client.chat.completions.create(
        model="llama-3.3-70b-versatile",
        messages=[
            {"role": "user", "content": prompt}
        ]
    )

    return response.choices[0].message.content


def select_meaningful_memory(messages, client):
    """Selects a meaningful memory using LLM."""
    # Filter for potentially interesting messages to save tokens
    candidates = [m["text"] for m in messages if len(m["text"]) > 15]
    if not candidates:
        return "Remember that time we couldn't stop laughing? Good times."
    
    # Sample if too many
    if len(candidates) > 50:
        candidates = random.sample(candidates, 50)

    candidates_str = "\n".join([f"- {c}" for c in candidates])

    prompt = f"""

Here are some excerpts from a chat history between two best friends, Aman and Sarah:



{candidates_str}



Your Task:

Select ONE specific message from this list that represents a "meaningful memory".

Criteria for "meaningful":

- A plan to meet (e.g., "Let's go to that movie", "Dinner tonight?")

- A sweet/emotional moment

- An inside joke or funny observation

- NOT just "Hello" or "Okay"



Return ONLY the exact text of the selected message. Nothing else.

    """

    try:
        response = client.chat.completions.create(
            model="llama-3.3-70b-versatile",
            messages=[{"role": "user", "content": prompt}]
        )
        return response.choices[0].message.content.strip()
    except Exception:
        return random.choice(candidates)


def generate_motivation():
    # Configure Groq API
    client = OpenAI(
        api_key=os.environ.get("GROQ_API_KEY"),
        base_url="https://api.groq.com/openai/v1",
    )

    try:
        with open("sarah_about.txt", "r", encoding="utf-8") as f:
            about_sarah = f.read()
    except FileNotFoundError:
        return "You are stronger than you know. Keep shining! ✨"

    prompt = f"""

You are a supportive, wise, and kind friend.

Read this context about Sarah:

"{about_sarah}"



Your Task:

Generate a short, powerful, and personalized motivational thought for Sarah.

It should directly address her struggles (past burdens, insecurity) but focus on her strengths (kindness, resilience, future in Air Force).

Make it sound like it's coming from a place of deep understanding and belief in her.

Keep it under 2 sentences.



Output ONLY the motivational message.

    """

    response = client.chat.completions.create(
        model="llama-3.3-70b-versatile",
        messages=[
            {"role": "user", "content": prompt}
        ]
    )

    return response.choices[0].message.content


if __name__ == "__main__":
    print(generate_inside_jokes(5))