o
    @i}                     @   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eef  deded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 medium,     
session_idcategory	objectivedetailsai_rolelearner_roleskills_to_assessis_adminroleplay_questionsroleplay_namerole
difficultydurationmax_attemptsreturnc                    s4  t |dkr|dd }|||||||
d}| |	}||I dH   s(dS g d}t fdd|D s@td|  dS tjdi d|d	|d
|d|d|d|d|d d d d d d d d d d d|
d|d|p||d|d|d|}| j|	 ||r|S td dS )zCreate a new roleplay scenario   N)r   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>1   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%   r&   zFailed to save scenarior   )
lenr   generate_scenarioallprintr   
create_newr   save_scenarioto_dict)r   r   r   r   r   r   r   r   r    r   r!   r"   r#   r$   r%   r&   admin_input
ai_servicerequired_keysscenarior   r0   r   create_scenario   sz   

	
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    r1   r   r   r   r?   R   s   
zScenarioGenerator.load_scenarioc                 C   s   | j |S )zList all available scenarios)r   list_scenarios)r   r    r   r   r   list_available_scenariosY   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)CommunicationrD   ProfessionalismAdaptabilityzResults Orientation)get)r   r   skill_mappingsr   r   r   get_default_skills_for_category]   s   &z1ScenarioGenerator.get_default_skills_for_category)NN)TNr   r   r   r   r   )__name__
__module____qualname__r   boolr   strr   r   r   intr   r   r>   r?   rB   rT   r   r   r   r   r
      sD    

@r
   N)typingr   r   r   r   models.scenarior   services.groq_servicer   services.ollama_servicer   utils.json_handlerr	   r
   r   r   r   r   <module>   s    