AUXteam commited on
Commit
ba1c332
·
verified ·
1 Parent(s): dbc1dab

Feat: Enable native parallelize=True flag for efficient batch persona generation

Browse files
backend/services/tinytroupe_manager.py CHANGED
@@ -40,48 +40,23 @@ class TinyTroupeSimulationManager:
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 is not None and getattr(person, '_persona', None) is not None:
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
@@ -98,10 +73,6 @@ class TinyTroupeSimulationManager:
98
 
99
  job_registry.update_job(job_id, progress_percentage=20 + int((i+1)/missing_count * 60))
100
 
101
- # Throttle consecutive requests to respect Google Gemini free tier limits
102
- if i < missing_count - 1:
103
- time.sleep(10)
104
-
105
  except Exception as e:
106
  logger.error(f"Error during persona generation: {e}")
107
  job_registry.update_job(job_id, status="FAILED", message=f"LLM Error: {str(e)}")
 
40
  try:
41
  # Utilize the TinyPersonFactory dynamic population pattern
42
  # Utilize the custom pipeline schema pattern for structured creation and validation
43
+ # Utilize the TinyPersonFactory dynamic population pattern natively with parallel generation
44
+ from tinytroupe.factory import TinyPersonFactory
45
 
46
+ factory = TinyPersonFactory(
47
+ sampling_space_description=customer_profile,
48
+ total_population_size=missing_count,
49
+ context=business_description
 
 
 
50
  )
51
 
52
+ logger.info(f"Job {job_id}: Generating {missing_count} personas via TinyPersonFactory with parallelize=True...")
 
 
 
 
 
 
 
 
 
 
53
 
54
+ people = factory.generate_people(missing_count, parallelize=True)
 
55
 
56
+ for i, person in enumerate(people):
 
 
 
 
 
 
 
 
 
 
 
 
57
  if person is not None and getattr(person, '_persona', None) is not None:
58
  persona_data = person._persona
59
+ persona_data["_assureness_score"] = 100 # New ones are perfectly matched to the description
60
  new_personas.append(persona_data)
61
 
62
  # Safe filename parsing
 
73
 
74
  job_registry.update_job(job_id, progress_percentage=20 + int((i+1)/missing_count * 60))
75
 
 
 
 
 
76
  except Exception as e:
77
  logger.error(f"Error during persona generation: {e}")
78
  job_registry.update_job(job_id, status="FAILED", message=f"LLM Error: {str(e)}")