-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconversation_generation_test.py
More file actions
428 lines (357 loc) · 16.5 KB
/
conversation_generation_test.py
File metadata and controls
428 lines (357 loc) · 16.5 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
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
#!/usr/bin/env python3
"""
Test module for improved conversation generation system
"""
import requests
import json
import time
import os
import sys
from dotenv import load_dotenv
import uuid
def test_conversation_generation(API_URL, auth_token, run_test):
"""Test the improved conversation generation system"""
print("\n" + "="*80)
print("TESTING IMPROVED CONVERSATION GENERATION SYSTEM")
print("="*80)
# Check if we have auth token
if not auth_token:
print("❌ Cannot test conversation generation without authentication")
return False, "Authentication failed"
# Test 1: Create a new simulation
print("\nTest 1: Creating a new simulation")
simulation_start_test, simulation_start_response = run_test(
"Start simulation",
"/simulation/start",
method="POST",
auth=True,
expected_keys=["message", "state"]
)
if not simulation_start_test:
print("❌ Failed to start simulation")
return False, "Failed to start simulation"
print("✅ Successfully started simulation")
# Test 2: Create test agents
print("\nTest 2: Creating test agents")
# Create three agents with different archetypes
agent_data = [
{
"name": "Dr. James Wilson",
"archetype": "scientist",
"personality": {
"extroversion": 4,
"optimism": 6,
"curiosity": 9,
"cooperativeness": 7,
"energy": 6
},
"goal": "Advance scientific understanding of the project",
"expertise": "Quantum Physics",
"background": "Former lead researcher at CERN",
"memory_summary": "",
"avatar_prompt": "",
"avatar_url": ""
},
{
"name": "Sarah Johnson",
"archetype": "leader",
"personality": {
"extroversion": 9,
"optimism": 8,
"curiosity": 6,
"cooperativeness": 8,
"energy": 8
},
"goal": "Ensure project success and team coordination",
"expertise": "Project Management",
"background": "20 years experience in tech leadership",
"memory_summary": "",
"avatar_prompt": "",
"avatar_url": ""
},
{
"name": "Michael Chen",
"archetype": "skeptic",
"personality": {
"extroversion": 4,
"optimism": 3,
"curiosity": 7,
"cooperativeness": 5,
"energy": 5
},
"goal": "Identify and mitigate project risks",
"expertise": "Risk Assessment",
"background": "Former security consultant",
"memory_summary": "",
"avatar_prompt": "",
"avatar_url": ""
}
]
created_agents = []
for agent in agent_data:
create_agent_test, create_agent_response = run_test(
f"Create Agent: {agent['name']}",
"/agents",
method="POST",
data=agent,
auth=True,
expected_keys=["id", "name"]
)
if create_agent_test and create_agent_response:
print(f"✅ Created agent: {create_agent_response.get('name')} with ID: {create_agent_response.get('id')}")
created_agents.append(create_agent_response)
else:
print(f"❌ Failed to create agent: {agent['name']}")
if len(created_agents) < 3:
print(f"❌ Failed to create all test agents. Only created {len(created_agents)} out of 3.")
return False, "Failed to create all test agents"
# Test 3: Set a scenario
print("\nTest 3: Setting a scenario")
scenario_data = {
"scenario": "The team is discussing the implementation of a new quantum computing project with potential applications in cryptography.",
"scenario_name": "Quantum Computing Project"
}
set_scenario_test, set_scenario_response = run_test(
"Set Scenario",
"/simulation/set-scenario",
method="POST",
data=scenario_data,
auth=True,
expected_keys=["message", "scenario"]
)
if not set_scenario_test:
print("❌ Failed to set scenario")
return False, "Failed to set scenario"
print("✅ Successfully set scenario")
# Test 4: Generate multiple conversation rounds
print("\nTest 4: Generating multiple conversation rounds")
# Store all conversation rounds for analysis
conversation_rounds = []
# Generate 5 conversation rounds
for i in range(5):
print(f"\nGenerating conversation round {i+1}/5:")
generate_data = {
"round_number": i+1,
"time_period": f"Day {i+1} Morning",
"scenario": scenario_data["scenario"],
"scenario_name": scenario_data["scenario_name"]
}
generate_test, generate_response = run_test(
f"Generate Conversation Round {i+1}",
"/conversation/generate",
method="POST",
data=generate_data,
auth=True,
expected_keys=["id", "round_number", "messages"]
)
if generate_test and generate_response:
print(f"✅ Generated conversation round {i+1}")
conversation_rounds.append(generate_response)
else:
print(f"❌ Failed to generate conversation round {i+1}")
if len(conversation_rounds) < 3:
print(f"❌ Failed to generate enough conversation rounds. Only generated {len(conversation_rounds)} out of 5.")
return False, "Failed to generate enough conversation rounds"
# Test 5: Analyze conversation content for improvements
print("\nTest 5: Analyzing conversation content for improvements")
# Check for self-introductions after first round
print("\nChecking for self-introductions after first round:")
self_intro_count = 0
intro_phrases = [
"good morning", "good afternoon", "good evening",
"i'm", "and i'm here to", "my name is"
]
for i, round_data in enumerate(conversation_rounds):
if i == 0: # Skip first round
continue
for message in round_data.get("messages", []):
message_text = message.get("message", "").lower()
for phrase in intro_phrases:
if phrase in message_text:
self_intro_count += 1
print(f"Found self-introduction in round {i+1}: '{message.get('message')}'")
break
if self_intro_count == 0:
print("✅ No self-introductions found after first round")
else:
print(f"❌ Found {self_intro_count} self-introductions after first round")
# Check for repetitive phrases
print("\nChecking for repetitive phrases:")
repetitive_phrases = [
"alright team", "alright everyone",
"as an expert in", "this is concerning",
"this is interesting", "this is exciting",
"let me share my perspective"
]
repetitive_phrase_count = 0
for round_data in conversation_rounds:
for message in round_data.get("messages", []):
message_text = message.get("message", "").lower()
for phrase in repetitive_phrases:
if phrase in message_text:
repetitive_phrase_count += 1
print(f"Found repetitive phrase '{phrase}' in message: '{message.get('message')}'")
break
if repetitive_phrase_count == 0:
print("✅ No repetitive phrases found")
else:
print(f"❌ Found {repetitive_phrase_count} repetitive phrases")
# Check for solution-focused responses
print("\nChecking for solution-focused responses:")
solution_phrases = [
"suggest", "recommend", "propose", "implement",
"approach", "solution", "strategy", "plan",
"timeline", "schedule", "milestone", "next steps"
]
solution_focused_count = 0
total_messages = 0
for round_data in conversation_rounds:
for message in round_data.get("messages", []):
total_messages += 1
message_text = message.get("message", "").lower()
for phrase in solution_phrases:
if phrase in message_text:
solution_focused_count += 1
break
solution_percentage = (solution_focused_count / total_messages) * 100 if total_messages > 0 else 0
print(f"Solution-focused messages: {solution_focused_count}/{total_messages} ({solution_percentage:.1f}%)")
if solution_percentage >= 50:
print("✅ Conversations are solution-focused")
else:
print("❌ Conversations are not sufficiently solution-focused")
# Check for references to previous speakers
print("\nChecking for references to previous speakers:")
reference_count = 0
for round_data in conversation_rounds:
messages = round_data.get("messages", [])
for i, message in enumerate(messages):
if i == 0: # Skip first message in each round
continue
message_text = message.get("message", "").lower()
previous_speakers = [prev_msg.get("agent_name", "") for prev_msg in messages[:i]]
for speaker in previous_speakers:
if speaker.lower() in message_text:
reference_count += 1
break
reference_percentage = (reference_count / (total_messages - len(conversation_rounds))) * 100 if (total_messages - len(conversation_rounds)) > 0 else 0
print(f"Messages referencing previous speakers: {reference_count}/{total_messages - len(conversation_rounds)} ({reference_percentage:.1f}%)")
if reference_percentage >= 30:
print("✅ Conversations show good references to previous speakers")
else:
print("❌ Conversations don't sufficiently reference previous speakers")
# Check for conversation progression
print("\nChecking for conversation progression:")
# Early rounds should focus on analysis and brainstorming
early_analysis_terms = ["analyze", "consider", "explore", "understand", "identify", "assess"]
early_analysis_count = 0
# Later rounds should focus on concrete proposals and decisions
later_decision_terms = ["decide", "implement", "plan", "schedule", "assign", "commit", "vote"]
later_decision_count = 0
early_rounds = conversation_rounds[:2] if len(conversation_rounds) >= 2 else []
later_rounds = conversation_rounds[2:] if len(conversation_rounds) >= 3 else []
for round_data in early_rounds:
for message in round_data.get("messages", []):
message_text = message.get("message", "").lower()
for term in early_analysis_terms:
if term in message_text:
early_analysis_count += 1
break
for round_data in later_rounds:
for message in round_data.get("messages", []):
message_text = message.get("message", "").lower()
for term in later_decision_terms:
if term in message_text:
later_decision_count += 1
break
early_messages = sum(len(round_data.get("messages", [])) for round_data in early_rounds)
later_messages = sum(len(round_data.get("messages", [])) for round_data in later_rounds)
early_analysis_percentage = (early_analysis_count / early_messages) * 100 if early_messages > 0 else 0
later_decision_percentage = (later_decision_count / later_messages) * 100 if later_messages > 0 else 0
print(f"Early rounds analysis focus: {early_analysis_count}/{early_messages} ({early_analysis_percentage:.1f}%)")
print(f"Later rounds decision focus: {later_decision_count}/{later_messages} ({later_decision_percentage:.1f}%)")
progression_ok = early_analysis_percentage >= 30 and later_decision_percentage >= 30
if progression_ok:
print("✅ Conversations show good progression from analysis to decisions")
else:
print("❌ Conversations don't show clear progression")
# Test 6: Test fallback responses
print("\nTest 6: Testing fallback responses")
# Generate a conversation with a very short timeout to trigger fallbacks
fallback_data = {
"round_number": 99, # Use a high number to ensure it's a new round
"time_period": "Fallback Test",
"scenario": "This is a test scenario to trigger fallback responses",
"scenario_name": "Fallback Test"
}
fallback_test, fallback_response = run_test(
"Generate Fallback Conversation",
"/conversation/generate",
method="POST",
data=fallback_data,
auth=True,
expected_keys=["id", "round_number", "messages"]
)
if fallback_test and fallback_response:
print("✅ Generated fallback conversation")
# Check fallback responses for banned phrases
fallback_banned_phrases = 0
for message in fallback_response.get("messages", []):
message_text = message.get("message", "").lower()
for phrase in repetitive_phrases + intro_phrases:
if phrase in message_text:
fallback_banned_phrases += 1
print(f"Found banned phrase in fallback response: '{message.get('message')}'")
break
if fallback_banned_phrases == 0:
print("✅ No banned phrases found in fallback responses")
else:
print(f"❌ Found {fallback_banned_phrases} banned phrases in fallback responses")
# Check if fallback responses are solution-focused
fallback_solution_count = 0
fallback_total = len(fallback_response.get("messages", []))
for message in fallback_response.get("messages", []):
message_text = message.get("message", "").lower()
for phrase in solution_phrases:
if phrase in message_text:
fallback_solution_count += 1
break
fallback_solution_percentage = (fallback_solution_count / fallback_total) * 100 if fallback_total > 0 else 0
print(f"Fallback solution-focused messages: {fallback_solution_count}/{fallback_total} ({fallback_solution_percentage:.1f}%)")
if fallback_solution_percentage >= 50:
print("✅ Fallback responses are solution-focused")
else:
print("❌ Fallback responses are not sufficiently solution-focused")
else:
print("❌ Failed to generate fallback conversation")
# Print summary
print("\nIMPROVED CONVERSATION GENERATION SUMMARY:")
# Check if all tests passed
no_self_intros = self_intro_count == 0
no_repetitive_phrases = repetitive_phrase_count == 0
is_solution_focused = solution_percentage >= 50
has_references = reference_percentage >= 30
shows_progression = progression_ok
if no_self_intros and no_repetitive_phrases and is_solution_focused and has_references and shows_progression:
print("✅ Improved conversation generation system is working correctly!")
print("✅ No self-introductions after first round")
print("✅ No repetitive phrases")
print("✅ Conversations are solution-focused")
print("✅ Agents reference previous speakers")
print("✅ Conversations show progression from analysis to decisions")
return True, "Improved conversation generation system is working correctly"
else:
issues = []
if not no_self_intros:
issues.append(f"Found {self_intro_count} self-introductions after first round")
if not no_repetitive_phrases:
issues.append(f"Found {repetitive_phrase_count} repetitive phrases")
if not is_solution_focused:
issues.append(f"Only {solution_percentage:.1f}% of messages are solution-focused (target: 50%)")
if not has_references:
issues.append(f"Only {reference_percentage:.1f}% of messages reference previous speakers (target: 30%)")
if not shows_progression:
issues.append("Conversations don't show clear progression from analysis to decisions")
print("❌ Improved conversation generation system has issues:")
for issue in issues:
print(f" - {issue}")
return False, {"issues": issues}