o
    1hV                     @   sZ   d dl mZmZmZmZ d dlmZ d dlmZ d dl	m
Z
 d dlmZ G dd dZdS )	    )DictListAnyOptional)RoleplayScenario)GroqService)OllamaService)JSONHandlerc                   @   s   e Zd ZdddZdefddZ	dded	ed
edeeef dedede	e de
dedee fddZdede
dee fddZde
de	eeef  fddZd	ede	e fddZdS )ScenarioGeneratorNc                 C   s$   |pt  | _|p
t | _t | _d S N)r   groq_servicer   ollama_servicer	   json_handler)selfr   r    r   M/var/www/eduai.edurigo.com/roleplay/production/services/scenario_generator.py__init__   s   zScenarioGenerator.__init__use_groqc                 C   s   |r| j S | jS )z9Get the appropriate AI service based on groqRoleplay flag)r   r   )r   r   r   r   r   _get_ai_service   s   z!ScenarioGenerator._get_ai_serviceT
session_idcategory	objectivedetailsai_rolelearner_roleskills_to_assessis_adminreturnc
                    s   t |dkr|dd }||||||d}
| |	}||
  s#dS g d}t fdd|D s;td|  dS tj||||||| d  d	  d
  d  d d}| j|	 ||rb|S td dS )zCreate a new roleplay scenario   N)r   r   r   r   r   r   )scenario_setupai_characterscenario_introconversation_startersuccess_criteriac                 3   s    | ]}| v V  qd S r   r   ).0keyscenario_datar   r   	<genexpr>-   s    z4ScenarioGenerator.create_scenario.<locals>.<genexpr>z*Generated scenario missing required keys: r   r    r!   r"   r#   )r   r   r   r   r   r   r   r   r    r!   r"   r#   zFailed to save scenario)
lenr   generate_scenarioallprintr   
create_newr   save_scenarioto_dict)r   r   r   r   r   r   r   r   r   r   admin_input
ai_servicerequired_keysscenarior   r&   r   create_scenario   sF   


z!ScenarioGenerator.create_scenarioc                 C   s    | j ||}|rt|S dS )zLoad an existing scenarioN)r   load_scenarior   	from_dict)r   r   r   r'   r   r   r   r5   H   s   
zScenarioGenerator.load_scenarioc                 C   s   | j |S )zList all available scenarios)r   list_scenarios)r   r   r   r   r   list_available_scenariosO   s   z*ScenarioGenerator.list_available_scenariosc                 C   s4   g dg dg dg dg dd}| |g dS )z'Get default skills for a given category)zPolicy AdherenceEmpathyzCommunication ClarityzConflict ResolutionProblem Solving)zNeeds AssessmentzProduct Knowledge
PersuasionzObjection HandlingzRelationship Building)zDecision MakingzTeam Communication
Motivation
DelegationzConflict Management)PreparationzActive ListeningzCreative Problem Solving
CompromisezRelationship Management)zProblem DiagnosiszTechnical CommunicationPatienceDocumentationz	Follow-up)zCustomer ServiceSales
LeadershipNegotiationzTechnical Support)Communicationr:   ProfessionalismAdaptabilityzResults Orientation)get)r   r   skill_mappingsr   r   r   get_default_skills_for_categoryS   s   &z1ScenarioGenerator.get_default_skills_for_category)NN)T)__name__
__module____qualname__r   boolr   strr   r   r   intr   r   r4   r5   r8   rJ   r   r   r   r   r
      s(    

6r
   N)typingr   r   r   r   models.scenarior   services.groq_servicer   services.ollama_servicer   utils.json_handlerr	   r
   r   r   r   r   <module>   s    