-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbro_code_ai.yaml
More file actions
203 lines (164 loc) · 8.56 KB
/
bro_code_ai.yaml
File metadata and controls
203 lines (164 loc) · 8.56 KB
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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import random
# The sacred texts of the Bro Code (simplified and for demonstration)
BRO_CODE_RULES = {
"ex's_sister": {
"rule": "Never pursue a Bro's ex's sister or a close female relative.",
"penalty": "The Bro Code violation is severe. Must buy the Bro's next five rounds of drinks."
},
"wingman_duty": {
"rule": "Always be a reliable wingman. Distraction and defense are key.",
"advice": "Commit fully. Your mission is to make the Bro look good, even if it means telling a slightly embarrassing but heroic story about him."
},
"bathroom_emergency": {
"rule": "Always cover a Bro during a 'bathroom emergency' (especially if a phone is left behind).",
"advice": "Immediate security detail. Answer no calls, guard the phone with your life, and use only cryptic non-committal texts."
},
"girl_drama": {
"rule": "When a Bro is venting about girl drama, your response must be supportive and confirm his rightness.",
"advice": "Listen, nod, and repeat the phrase: 'That's messed up, man. You handled that like a champ.' Never suggest he might be wrong."
},
"last_slice": {
"rule": "The last slice of pizza/wing is communal property and must be offered before being claimed.",
"advice": "Make the offer, but with a look that clearly states you are prepared to fight for it. If declined, execute the 'Two-Bite Rule' (no more than two bites)."
}
}
def consult_bro_code(scenario: str) -> str:
"""
Consults the Bro Code for guidance on a specific scenario.
Args:
scenario: A keyword representing the situation (e.g., "wingman_duty").
Returns:
The official ruling or a default response.
"""
# Normalize the input to check against the rules
scenario_key = scenario.lower().replace(" ", "_").replace("'", "")
# Check for a specific rule
if scenario_key in BRO_CODE_RULES:
rule_data = BRO_CODE_RULES[scenario_key]
# Craft the response based on the rule data
response_parts = [
f"**Scenario: {scenario.title()}**",
"---",
f"**Official Rule:** {rule_data['rule']}"
]
if 'advice' in rule_data:
response_parts.append(f"**Bro-Tip/Guidance:** {rule_data['advice']}")
if 'penalty' in rule_data:
response_parts.append(f"**Violation Consequence:** {rule_data['penalty']}")
return "\n".join(response_parts)
# Default responses for unrecognized scenarios
else:
default_responses = [
"The Bro Code is silent on this specific matter. Proceed with caution and loyalty, Bro.",
"This situation requires a ruling from the Elder Bros. For now, defaulting to 'Don't be a jerk.'",
"I detect a gray area. When in doubt, defer to the Bro. His call is final.",
"Protocol suggests a high-five and a shared beverage. This will reset the situation.",
"Unindexed scenario. The spirit of the Bro Code dictates prioritizing the Bro's well-being and honor."
]
return f"**Scenario: {scenario.title()}**\n\n{random.choice(default_responses)}"
# --- Instances (per your preference for 'instances') ---
print("### 🤝 Bro Code AI Consultation ###\n")
# Instance 1: A clear-cut rule
ruling_1 = consult_bro_code("Wingman Duty")
print(ruling_1)
print("\n" + "="*40 + "\n")
# Instance 2: A severe violation
ruling_2 = consult_bro_code("Ex's Sister")
print(ruling_2)
print("\n" + "="*40 + "\n")
# Instance 3: An unrecognized scenario
ruling_3 = consult_bro_code("Borrowing the car")
print(ruling_3)
import pandas as pd
from sklearn.feature_extraction.text import TfidfVectorizer
from sklearn.svm import SVC
from sklearn.pipeline import Pipeline
from sklearn.model_selection import train_test_split
from sklearn.metrics import classification_report
# --- 1. Define the Bro Code Database (The "Knowledge Base") ---
BRO_CODE_KNOWLEDGE_BASE = {
"WINGMAN": {
"rule": "Absolute loyalty is mandatory. If a Bro is engaging, you are the distraction, the lookout, and the hype-man.",
"action": "Initiate Protocol 'Silent Support.' Maintain a 10-foot radius. Guard all beverages."
},
"EX_RELATIONS": {
"rule": "A Bro's ex is permanently off-limits. Violations incur severe penalties.",
"action": "Immediate self-correction is required. Distance yourself and initiate the 'Bro-fessor' meeting (requires beer and a formal apology)."
},
"PROPERTY_LENDING": {
"rule": "Lending items (especially vehicles/tech) requires mutual trust and an assumption of 'no questions asked' upon return.",
"action": "Do not inspect the item immediately. Wait 24 hours. If damage is discovered, only a nod is required—no words."
},
"EMERGENCY_COVER": {
"rule": "When a Bro needs an alibi or cover, it is provided without hesitation or detail.",
"action": "Execute the 'Plausible Deniability' response. Use vague but firm statements: 'He was helping me move a thing' or 'It was a prior commitment.'"
}
}
# --- 2. Create Training Data for the NLP Classifier ---
# The AI needs examples to learn how to categorize new, unseen scenarios.
training_data = [
# WINGMAN examples
("My friend is talking to someone, what should I do?", "WINGMAN"),
("He asked me to help him out with a girl at the bar.", "WINGMAN"),
("I need to back up my buddy.", "WINGMAN"),
# EX_RELATIONS examples
("I ran into my Bro's old flame, can I ask her out?", "EX_RELATIONS"),
("I think my friend is seeing his buddy's ex-girlfriend.", "EX_RELATIONS"),
("What's the rule on dating a sister of an ex?", "EX_RELATIONS"),
# PROPERTY_LENDING examples
("He wants to borrow my new TV for the game.", "PROPERTY_LENDING"),
("Can I lend my car to my friend for a weekend trip?", "PROPERTY_LENDING"),
("My buddy returned my jacket slightly ripped.", "PROPERTY_LENDING"),
# EMERGENCY_COVER examples
("I need a good excuse for missing work tomorrow.", "EMERGENCY_COVER"),
("He needs me to lie to his parents.", "EMERGENCY_COVER"),
("What is the best alibi for my friend?", "EMERGENCY_COVER"),
]
# Separate features (X) and labels (y)
X, y = zip(*training_data)
# --- 3. Build and Train the NLP Pipeline (The "AI Brain") ---
# A Pipeline combines the necessary steps: Vectorization (turning text into numbers) and Classification (the SVM model).
bro_code_classifier = Pipeline([
# Step 1: Feature Extraction using TF-IDF (converts words to weighted numbers)
('tfidf', TfidfVectorizer(stop_words='english')),
# Step 2: Classification using Support Vector Machine (SVC)
('clf', SVC(kernel='linear', C=1))
])
# Train the model
bro_code_classifier.fit(X, y)
def consult_advanced_bro_code(scenario: str) -> str:
"""
Classifies a free-form user scenario using the trained NLP model
and retrieves the appropriate Bro Code ruling and action.
"""
if not scenario:
return "Bro, you have to give me a scenario to consult the Code."
# Step 1: Predict the category using the trained model
predicted_category = bro_code_classifier.predict([scenario])[0]
# Step 2: Retrieve the ruling from the knowledge base
ruling_data = BRO_CODE_KNOWLEDGE_BASE.get(predicted_category, None)
if ruling_data:
# Step 3: Format the advanced, structured response
response = f"### 🧐 BRO CODE RULING - Category: **{predicted_category}** ###\n"
response += f"**Scenario:** *'{scenario}'*\n"
response += "---"
response += f"\n\n**📜 Official Rule:** {ruling_data['rule']}"
response += f"\n\n**🔨 Recommended Action:** {ruling_data['action']}"
return response
else:
return f"Bro Code Anomaly Detected: Could not find ruling for category '{predicted_category}'. Default to loyalty."
# --- Running Instances (as requested) ---
print("\n" + "="*50)
print("### 🧠 ADVANCED BRO CODE AI CONSULTATION ###")
print("="*50 + "\n")
# Instance 1: A complex scenario that the AI must classify as WINGMAN
scenario_1 = "My friend is shy and needs help talking to a group of people. What's the code?"
print(consult_advanced_bro_code(scenario_1))
print("\n" + "="*50 + "\n")
# Instance 2: A scenario requiring an ALIBI, which the AI classifies as EMERGENCY_COVER
scenario_2 = "I need an air-tight excuse for why he can't go to the family dinner."
print(consult_advanced_bro_code(scenario_2))
print("\n" + "="*50 + "\n")
# Instance 3: A test of a property rule
scenario_3 = "He gave me back my gaming controller, but I think he spilled something on it."
print(consult_advanced_bro_code(scenario_3))