Spaces:
Sleeping
Sleeping
loic.ledreck
commited on
Commit
·
fab8c1b
1
Parent(s):
5057995
feat: new sequence
Browse files- app.py +4 -4
- helper_functions.py +0 -1
- static/index.html +101 -44
app.py
CHANGED
|
@@ -125,7 +125,6 @@ async def send_message(message: Message):
|
|
| 125 |
"user": "user",
|
| 126 |
"trump": "assistant" # Mapping 'trump' to 'assistant'
|
| 127 |
}
|
| 128 |
-
print(chat_history)
|
| 129 |
for interaction in chat_history:
|
| 130 |
for key, value in interaction.items():
|
| 131 |
user_message = value['user']['message'] if 'user' in value else "..."
|
|
@@ -145,8 +144,6 @@ async def send_message(message: Message):
|
|
| 145 |
|
| 146 |
messages = system + dynamic_history
|
| 147 |
|
| 148 |
-
print("messages", messages)
|
| 149 |
-
print("model", model)
|
| 150 |
chat_response = client.chat.complete(
|
| 151 |
model=model,
|
| 152 |
messages=messages
|
|
@@ -167,7 +164,10 @@ async def send_message(message: Message):
|
|
| 167 |
|
| 168 |
return {
|
| 169 |
"character_response": trump_response,
|
| 170 |
-
"chat_history": chat_history
|
|
|
|
|
|
|
|
|
|
| 171 |
}
|
| 172 |
except Exception as e:
|
| 173 |
print(e)
|
|
|
|
| 125 |
"user": "user",
|
| 126 |
"trump": "assistant" # Mapping 'trump' to 'assistant'
|
| 127 |
}
|
|
|
|
| 128 |
for interaction in chat_history:
|
| 129 |
for key, value in interaction.items():
|
| 130 |
user_message = value['user']['message'] if 'user' in value else "..."
|
|
|
|
| 144 |
|
| 145 |
messages = system + dynamic_history
|
| 146 |
|
|
|
|
|
|
|
| 147 |
chat_response = client.chat.complete(
|
| 148 |
model=model,
|
| 149 |
messages=messages
|
|
|
|
| 164 |
|
| 165 |
return {
|
| 166 |
"character_response": trump_response,
|
| 167 |
+
"chat_history": chat_history,
|
| 168 |
+
"chat_ended": is_ending,
|
| 169 |
+
"idea": idea,
|
| 170 |
+
"idea_is_accepted": idea_is_accepted,
|
| 171 |
}
|
| 172 |
except Exception as e:
|
| 173 |
print(e)
|
helper_functions.py
CHANGED
|
@@ -66,7 +66,6 @@ def initialize_game():
|
|
| 66 |
world_graph.save_graph_as_edgelist(f'games/game_{game_number}/world_graph.edgelist')
|
| 67 |
return game_number
|
| 68 |
|
| 69 |
-
|
| 70 |
def generate_round_context(game_number):
|
| 71 |
"""randomly generates a context and returns all the prompt elements needed"""
|
| 72 |
game_dir = f'games/game_{game_number}/'
|
|
|
|
| 66 |
world_graph.save_graph_as_edgelist(f'games/game_{game_number}/world_graph.edgelist')
|
| 67 |
return game_number
|
| 68 |
|
|
|
|
| 69 |
def generate_round_context(game_number):
|
| 70 |
"""randomly generates a context and returns all the prompt elements needed"""
|
| 71 |
game_dir = f'games/game_{game_number}/'
|
static/index.html
CHANGED
|
@@ -150,6 +150,10 @@
|
|
| 150 |
|
| 151 |
//updateChatMessage(trumpMessageDiv, data.character_response)
|
| 152 |
typeMessage(trumpMessageDiv, data.character_response)
|
|
|
|
|
|
|
|
|
|
|
|
|
| 153 |
//addMessageToChat(data.character_response, false);
|
| 154 |
})
|
| 155 |
.catch(error => {
|
|
@@ -157,6 +161,7 @@
|
|
| 157 |
addMessageToChat('Error: Failed to get response', false);
|
| 158 |
});
|
| 159 |
}
|
|
|
|
| 160 |
let receivedFirstMessage = false
|
| 161 |
function receiveFirstMessage() {
|
| 162 |
console.log("in receive first")
|
|
@@ -216,8 +221,35 @@
|
|
| 216 |
}
|
| 217 |
});
|
| 218 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 219 |
|
| 220 |
document.addEventListener('DOMContentLoaded', function() {
|
|
|
|
|
|
|
| 221 |
// Load the intro content
|
| 222 |
fetch('./intro.html')
|
| 223 |
.then(response => response.text())
|
|
@@ -245,6 +277,7 @@
|
|
| 245 |
const okBtn = popup.querySelector('.popup-ok');
|
| 246 |
|
| 247 |
minimizeBtn.addEventListener('click', () => {
|
|
|
|
| 248 |
popup.classList.add('minimized');
|
| 249 |
});
|
| 250 |
|
|
@@ -253,6 +286,7 @@
|
|
| 253 |
});
|
| 254 |
|
| 255 |
closeBtn.addEventListener('click', () => {
|
|
|
|
| 256 |
popup.style.display = 'none';
|
| 257 |
});
|
| 258 |
|
|
@@ -995,52 +1029,75 @@
|
|
| 995 |
'Other-Asia': ['AF', 'AM', 'AZ', 'BD', 'BT', 'CY', 'GE', 'ID', 'JP', 'KZ', 'KG', 'KH', 'KR', 'LA', 'LK', 'MM', 'MN', 'MY', 'NP', 'PH', 'PK', 'SG', 'TJ', 'TH', 'TL', 'TM', 'UZ', 'VN']
|
| 996 |
};
|
| 997 |
|
| 998 |
-
// Le dico qu'on reçoit
|
| 999 |
-
const regionData = {
|
| 1000 |
-
|
| 1001 |
-
|
| 1002 |
-
|
| 1003 |
-
|
| 1004 |
-
|
| 1005 |
-
|
| 1006 |
-
|
| 1007 |
-
|
| 1008 |
-
|
| 1009 |
-
|
| 1010 |
-
|
| 1011 |
-
|
| 1012 |
-
|
| 1013 |
-
|
| 1014 |
-
};
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1015 |
|
| 1016 |
-
|
| 1017 |
-
|
| 1018 |
-
|
| 1019 |
-
|
| 1020 |
-
|
| 1021 |
-
|
| 1022 |
-
|
| 1023 |
-
|
| 1024 |
-
}, {})
|
| 1025 |
-
|
| 1026 |
-
|
| 1027 |
-
|
| 1028 |
-
|
| 1029 |
-
|
| 1030 |
-
|
| 1031 |
-
|
| 1032 |
-
|
| 1033 |
-
|
| 1034 |
-
|
| 1035 |
-
|
| 1036 |
-
|
| 1037 |
-
|
| 1038 |
-
|
| 1039 |
-
|
| 1040 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1041 |
}
|
| 1042 |
-
});
|
| 1043 |
-
});
|
| 1044 |
|
| 1045 |
</script>
|
| 1046 |
</body>
|
|
|
|
| 150 |
|
| 151 |
//updateChatMessage(trumpMessageDiv, data.character_response)
|
| 152 |
typeMessage(trumpMessageDiv, data.character_response)
|
| 153 |
+
console.log("chat ended: ", data.chat_ended);
|
| 154 |
+
if (data.chat_ended === true) {
|
| 155 |
+
endSequence(data.idea, data.idea_accepted);
|
| 156 |
+
}
|
| 157 |
//addMessageToChat(data.character_response, false);
|
| 158 |
})
|
| 159 |
.catch(error => {
|
|
|
|
| 161 |
addMessageToChat('Error: Failed to get response', false);
|
| 162 |
});
|
| 163 |
}
|
| 164 |
+
|
| 165 |
let receivedFirstMessage = false
|
| 166 |
function receiveFirstMessage() {
|
| 167 |
console.log("in receive first")
|
|
|
|
| 221 |
}
|
| 222 |
});
|
| 223 |
|
| 224 |
+
function clearChatbox() {
|
| 225 |
+
const chatbox = document.getElementById("chatWindow"); // Get the chatbox element
|
| 226 |
+
if (!chatbox) {
|
| 227 |
+
console.error("Error: Chatbox element not found.");
|
| 228 |
+
return; // Exit if the chatbox is not found
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
// Remove all child elements from the chatbox
|
| 232 |
+
while (chatbox.firstChild) {
|
| 233 |
+
chatbox.removeChild(chatbox.firstChild);
|
| 234 |
+
}
|
| 235 |
+
}
|
| 236 |
+
|
| 237 |
+
function endSequence(idea, idea_accepted) {
|
| 238 |
+
// Vide le chat
|
| 239 |
+
clearChatbox()
|
| 240 |
+
|
| 241 |
+
//displaySequencePopup(idea, idea_accepted) // not available
|
| 242 |
+
|
| 243 |
+
fetchUpdateMap()
|
| 244 |
+
// Affiche pop up sequence result avec action prise par trump
|
| 245 |
+
// Update map
|
| 246 |
+
receivedFirstMessage = false
|
| 247 |
+
receiveFirstMessage()
|
| 248 |
+
}
|
| 249 |
|
| 250 |
document.addEventListener('DOMContentLoaded', function() {
|
| 251 |
+
updateMap(regionData)
|
| 252 |
+
|
| 253 |
// Load the intro content
|
| 254 |
fetch('./intro.html')
|
| 255 |
.then(response => response.text())
|
|
|
|
| 277 |
const okBtn = popup.querySelector('.popup-ok');
|
| 278 |
|
| 279 |
minimizeBtn.addEventListener('click', () => {
|
| 280 |
+
receiveFirstMessage()
|
| 281 |
popup.classList.add('minimized');
|
| 282 |
});
|
| 283 |
|
|
|
|
| 286 |
});
|
| 287 |
|
| 288 |
closeBtn.addEventListener('click', () => {
|
| 289 |
+
receiveFirstMessage()
|
| 290 |
popup.style.display = 'none';
|
| 291 |
});
|
| 292 |
|
|
|
|
| 1029 |
'Other-Asia': ['AF', 'AM', 'AZ', 'BD', 'BT', 'CY', 'GE', 'ID', 'JP', 'KZ', 'KG', 'KH', 'KR', 'LA', 'LK', 'MM', 'MN', 'MY', 'NP', 'PH', 'PK', 'SG', 'TJ', 'TH', 'TL', 'TM', 'UZ', 'VN']
|
| 1030 |
};
|
| 1031 |
|
| 1032 |
+
// Le dico qu'on reçoit
|
| 1033 |
+
const regionData = {
|
| 1034 |
+
"United-States": { "money": 100, "friendliness": -1 },
|
| 1035 |
+
"Canada": { "money": 50, "friendliness": -1 },
|
| 1036 |
+
"Mexico": { "money": 30, "friendliness": 2 },
|
| 1037 |
+
"South-America": { "money": 40, "friendliness": 3 },
|
| 1038 |
+
"Africa": { "money": 20, "friendliness": 1 },
|
| 1039 |
+
"Europe": { "money": 80, "friendliness": 2 },
|
| 1040 |
+
"Middle-East": { "money": 60, "friendliness": -2 },
|
| 1041 |
+
"Russia": { "money": 70, "friendliness": -3 },
|
| 1042 |
+
"China": { "money": 90, "friendliness": -1 },
|
| 1043 |
+
"India": { "money": 50, "friendliness": 2 },
|
| 1044 |
+
"Australia": { "money": 55, "friendliness": 1 },
|
| 1045 |
+
"Pacific": { "money": 25, "friendliness": 3 },
|
| 1046 |
+
"Taiwan": { "money": 65, "friendliness": 0 },
|
| 1047 |
+
"Greenland": { "money": 10, "friendliness": 1 }
|
| 1048 |
+
};
|
| 1049 |
+
|
| 1050 |
+
function fetchUpdateMap() {
|
| 1051 |
+
const regionData = {
|
| 1052 |
+
"United-States": { "money": 100, "friendliness": -1 },
|
| 1053 |
+
"Canada": { "money": 50, "friendliness": -3 },
|
| 1054 |
+
"Mexico": { "money": 30, "friendliness": 2 },
|
| 1055 |
+
"South-America": { "money": 40, "friendliness": 3 },
|
| 1056 |
+
"Africa": { "money": 20, "friendliness": 1 },
|
| 1057 |
+
"Europe": { "money": 80, "friendliness": 2 },
|
| 1058 |
+
"Middle-East": { "money": 60, "friendliness": -2 },
|
| 1059 |
+
"Russia": { "money": 70, "friendliness": -3 },
|
| 1060 |
+
"China": { "money": 90, "friendliness": -1 },
|
| 1061 |
+
"India": { "money": 50, "friendliness": 2 },
|
| 1062 |
+
"Australia": { "money": 55, "friendliness": 1 },
|
| 1063 |
+
"Pacific": { "money": 25, "friendliness": 3 },
|
| 1064 |
+
"Taiwan": { "money": 65, "friendliness": 0 },
|
| 1065 |
+
"Greenland": { "money": 10, "friendliness": 1 }
|
| 1066 |
+
};
|
| 1067 |
+
updateMap(regionData);
|
| 1068 |
+
}
|
| 1069 |
|
| 1070 |
+
function updateMap(regionData) {
|
| 1071 |
+
console.log("setup map")
|
| 1072 |
+
// Détermine la couleur de chaque région (vert si au moins un pays est "friendless: Yes", rouge sinon)
|
| 1073 |
+
const regionColors = Object.keys(regionData).reduce((acc, region) => {
|
| 1074 |
+
const friendliness = regionData[region].friendliness;
|
| 1075 |
+
// Convertir `friendliness` en une couleur allant de rouge vif (-3) à vert vif (3)
|
| 1076 |
+
const green = Math.max(0, 255 + friendliness * 85);
|
| 1077 |
+
const red = Math.max(0, 255 - friendliness * 85);
|
| 1078 |
+
acc[region] = `rgb(${red}, ${green}, 0)`; // Couleur calculée
|
| 1079 |
+
return acc;
|
| 1080 |
+
}, {});
|
| 1081 |
+
|
| 1082 |
+
|
| 1083 |
+
// Injecte les chemins des régions dans la carte SVG
|
| 1084 |
+
const worldMap = document.getElementById('worldMap');
|
| 1085 |
+
|
| 1086 |
+
Object.keys(regions).forEach((region) => {
|
| 1087 |
+
const countryCodes = regions[region]; // Pays de la région
|
| 1088 |
+
countryCodes.forEach((countryCode) => {
|
| 1089 |
+
const country = countries[countryCode];
|
| 1090 |
+
if (country && country.d) {
|
| 1091 |
+
// Créer un chemin pour chaque pays
|
| 1092 |
+
const path = document.createElementNS('http://www.w3.org/2000/svg', 'path');
|
| 1093 |
+
path.setAttribute('d', country.d); // Définir le chemin SVG
|
| 1094 |
+
path.setAttribute('fill', regionColors[region] || 'gray'); // Couleur basée sur la région
|
| 1095 |
+
path.setAttribute('stroke', '#000'); // Ajouter un contour noir
|
| 1096 |
+
worldMap.appendChild(path);
|
| 1097 |
+
}
|
| 1098 |
+
});
|
| 1099 |
+
});
|
| 1100 |
}
|
|
|
|
|
|
|
| 1101 |
|
| 1102 |
</script>
|
| 1103 |
</body>
|