o
    hW                     @   s   d dl mZ d dlmZ d dlmZmZ d dlZd dlZd dl	m
Z
 e
dd edZed	Zed
ZejdeeeddZejed G dd dejZG dd dejZG dd deZG dd deZdS )    )Type)BaseTool)	BaseModelFieldN)load_dotenvz7/home/azureuser/microlearn/backend/prompt_opt_dspy/.env)dotenv_pathAZURE_API_KEYAZURE_API_HOSTAZURE_API_VERSIONzazure/Csqr-gpt-4o-minig        )api_keyapi_baseapi_versiontemperature)lmc                   @   sv   e Zd ZU dZe Zeed< e Z	eed< e Z
eed< e Zeed< e Zeed< ejddZeed	< d
S )DurationEstimatorSignatureuN  
    You are a learning strategist designing microlearning journeys for non-technical professionals.

    I will provide you with:
    - The user’s job title
    - Their experience with the topic
    - Their current skills
    - A technical topic they need to learn
    - The desired proficiency level

    Instructions:
    1. Based on the user’s job title, current skills, and experience **with the topic**, estimate the gap between their current capabilities and the skills needed to reach the desired proficiency level for the given topic.
    2. Considering the user is non-technical and can dedicate a maximum of 360 minutes, suggest a suitable total time duration (in minutes, up to 360 minutes) that would be appropriate and realistic for a microlearning journey to bridge this gap.
    3. Only output the recommended total time duration in minutes — no explanation or other details.

    Follow this structured reasoning:
    1. **Topic Familiarity (Not Work Experience)**:
        Estimate the user's starting point based on their self-reported experience with the topic:
        - **Complete Beginner** → Starting from scratch
        - **Some Experience** → Aware of basic terms, limited application
        - **Intermediate** → Comfortable with fundamentals, can apply concepts
        - **Advanced** → Proficient, seeking mastery or advanced application

    2. **Job Context and Learning Bandwidth**:
        - **Executives / Senior Professionals**
        → Need only conceptual understanding + business value focus
        → Limited time, faster grasp of strategic value
        → Recommend **shorter durations**
        
        - **Mid-Level Professionals**
        → Require **understanding + application**
        → Moderate time, good motivation
        → Recommend **efficient durations**

        - **Junior Professionals**
        → May need more foundational context
        → More time available, learning is slower
        → Recommend **longer durations**

    3. **Proficiency Level Goals**:
        Match effort based on the target outcome:
        - **No-code** → Focus is on using tools or dashboards without scripting → typically fastest
        - **Low-code** → Involves configuration or automation with minimal scripting → moderate
        - **Hands-on Code** → Requires actual coding, debugging, and logic skills → longest duration
        - **Mixed Approach** → Combination of conceptual, tooling, and coding → variable but usually longer

    4. **Topic Complexity Factor**:
        Use judgment on how inherently complex the topic is. For example:
        - "APIs" is simpler than "Machine Learning" for most non-technical learners
        - "Data Visualization" (No-code) may be faster to teach than "Building ETL Pipelines" (Hands-on Code)

    5. **Make your estimate logical, realistic, and human-centered.**

    Output format:
    [Time Duration in minutes]

    User Profile:
    - Job Title: {Job_Title}
    - Experience with Topic: {Experience}
    - Current Skills: {Skills}
    - Target Topic: {topic}
    - Desired Proficiency Level: {Level}
    
    	Job_Title
ExperienceSkillstopicLevelzBRecommended learning journey duration in minutes (only the number))descduration_minutesN)__name__
__module____qualname____doc__dspy
InputFieldr   str__annotations__r   r   r   r   OutputFieldr    r!   r!   /home/azureuser/microlearn/backend/user_journey_with_openai/agentic_workflow/src/user_journey_service/tools/custom_duration_estimator_tool.pyr      s   
 Ar   c                       s$   e Zd Z fddZdd Z  ZS )DurationEstimatorModulec              
      s   t    tt}tjddddddddd	d
ddtjddddddddd	d
ddtjddddddddd	d
ddg}ddd}tj|d}|j||d| _	d S )NzData ScientistAdvancedzPython, StatisticszMachine LearningzHands-on coding240)r   r   r   r   r   r   r   r   r   r   r   zMarketing ManagerzCampaigns, Content StrategyzData AnalysiszLow-code approach180zProduct ManagerzSome experiencez(Strategy, Cross-functional collaborationzAI for BusinesszMixed approachc                 S   s>   zt |j }t d|  kodkW S   W S    Y dS )Nr   ih  )intr   strip)goldpredtracevalr!   r!   r"   duration_metric   s
   "z9DurationEstimatorModule.__init__.<locals>.duration_metric)metric)studenttrainset)N)
super__init__r   Predictr   Examplewith_inputsBootstrapFewShotcompileoptimized_predictor)self	predictorr0   r-   	optimizer	__class__r!   r"   r2   i   sH   


z DurationEstimatorModule.__init__c                 C   s   | j |||||dS N)r   r   r   r   r   )r8   )r9   r   r   r   r   r   r!   r!   r"   forward   s   zDurationEstimatorModule.forward)r   r   r   r2   r?   __classcell__r!   r!   r<   r"   r#   h   s    0r#   c                   @   sv   e Zd ZU dZedddZeed< edddZeed< edddZ	eed	< edd
dZ
eed< edddZeed< dS )DurationEstimatorInputz'Input schema for DurationEstimatorTool..zUser's job title)descriptionr   z&User's experience level with the topicr   zUser's current skillsr   zThe technical topic to learnr   zDesired proficiency levelr   N)r   r   r   r   r   r   r   r   r   r   r   r   r!   r!   r!   r"   rA      s   
 rA   c                   @   sX   e Zd ZU dZeed< dZeed< eZe	e
 ed< dededed	ed
edefddZdS )DurationEstimatorToolzDuration Estimator ToolnamezEstimates a realistic total duration (in minutes, max 360) for a microlearning journey based on the user's job role, skills, topic familiarity, and target proficiency level.rB   args_schemar   r   r   r   r   returnc                 C   s    t  }|j|||||d}|jS r>   )r#   r?   r   )r9   r   r   r   r   r   	estimatorresultr!   r!   r"   _run   s   zDurationEstimatorTool._runN)r   r   r   rD   r   r   rB   rA   rE   r   r   rI   r!   r!   r!   r"   rC      s   
 
&rC   )typingr   crewai.toolsr   pydanticr   r   r   osdotenvr   getenvazure_api_keyazure_api_hostazure_api_versionLMr   	configure	Signaturer   Moduler#   rA   rC   r!   r!   r!   r"   <module>   s,    



M<
