AUXteam commited on
Commit
4ba3568
·
verified ·
1 Parent(s): 43cee92

Feat: Adapt tinytroupe_manager to use new persona_pipeline logic

Browse files
backend/services/tinytroupe_manager.py CHANGED
@@ -39,24 +39,60 @@ class TinyTroupeSimulationManager:
39
  if missing_count > 0:
40
  try:
41
  # Utilize the TinyPersonFactory dynamic population pattern
42
- # Utilize the TinyPersonFactory dynamic population pattern, but generate sequentially to avoid Google 429 rate limits
43
- factory = TinyPersonFactory(business_description)
44
 
45
- logger.info(f"Job {job_id}: Generating {missing_count} personas via TinyPersonFactory sequentially...")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
46
 
47
  for i in range(missing_count):
48
- logger.info(f"Job {job_id}: Requesting persona {i+1}/{missing_count} from LLM...")
49
- person = factory.generate_person(customer_profile)
 
 
 
 
 
 
 
 
 
50
 
51
  if person:
52
  persona_data = person._persona
53
- persona_data["_assureness_score"] = 100 # New ones are perfectly matched to the description
54
  new_personas.append(persona_data)
55
 
 
 
 
 
 
56
  # Save to local file system for git sync
57
  local_dir = "/app/personas"
58
  os.makedirs(local_dir, exist_ok=True)
59
- file_path = os.path.join(local_dir, f"{person.name.replace(' ', '_')}.json")
60
  with open(file_path, "w") as f:
61
  json.dump(persona_data, f, indent=4)
62
 
 
39
  if missing_count > 0:
40
  try:
41
  # Utilize the TinyPersonFactory dynamic population pattern
42
+ # Utilize the custom pipeline schema pattern for structured creation and validation
43
+ from backend.services.persona_pipeline import CompanyProfile, CustomerSegment, get_blablador_client, generate_validation_expectations, generate_single_persona, export_persona
44
 
45
+ company = CompanyProfile(
46
+ name="Unknown Company",
47
+ industry="General",
48
+ size="N/A",
49
+ market="General",
50
+ description=business_description,
51
+ challenges=[]
52
+ )
53
+
54
+ segment = CustomerSegment(
55
+ name="Target Segment",
56
+ description=customer_profile,
57
+ typical_needs=[],
58
+ typical_fears=[],
59
+ size_hint=missing_count
60
+ )
61
+
62
+ logger.info(f"Job {job_id}: Generating expectations for {missing_count} personas...")
63
+ client = get_blablador_client()
64
+ expectations = generate_validation_expectations(company, segment, client)
65
+
66
+ # Sleep to prevent 429
67
+ time.sleep(10)
68
 
69
  for i in range(missing_count):
70
+ logger.info(f"Job {job_id}: Requesting persona {i+1}/{missing_count} from Pipeline...")
71
+
72
+ person, score, justification = generate_single_persona(
73
+ company=company,
74
+ segment=segment,
75
+ expectations=expectations,
76
+ index=i,
77
+ total=missing_count,
78
+ min_score=0.7,
79
+ max_attempts=3
80
+ )
81
 
82
  if person:
83
  persona_data = person._persona
84
+ persona_data["_assureness_score"] = score * 100 if score else 100 # Default to 100 if validation fails parsing
85
  new_personas.append(persona_data)
86
 
87
+ # Safe filename parsing
88
+ safe_name = person.name.lower().strip()
89
+ safe_name = re.sub(r"[^\w\s-]", "", safe_name)
90
+ safe_name = re.sub(r"[\s-]+", "_", safe_name)[:60]
91
+
92
  # Save to local file system for git sync
93
  local_dir = "/app/personas"
94
  os.makedirs(local_dir, exist_ok=True)
95
+ file_path = os.path.join(local_dir, f"{safe_name}.json")
96
  with open(file_path, "w") as f:
97
  json.dump(persona_data, f, indent=4)
98