o
    1h%c                     @   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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_DEPLOYMENT_IDAZURE_API_VERSIONzazure/Csqr-gpt-4o-minig        )api_keyapi_baseapi_versiontemperature)lmc                   @   sf   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jddZeed< d	S )
RestructureSignatureu  
    Restructure like a syllabus for the user journey or update the existing user journeys based on feedback.
    read the content {content} and make a new user journey if the feedack is "First iteration", Otherwise update the user journey in the {content} according to the user feedback {feedback}
    The user's company context is as follows:
        Company Name : {Company_Name}
        Industry : {Industry}
        Company Size : {Company_Size}
        Business Model : {Business_Model}
        Top Use Cases : {Top_Use_Cases}
        Learning Focus : {Learning_Focus}
        Tech Stack : {Tech_stack}
        Compliance : {Compliance}
    
    # User journey Creation Task
    
    ## Objective
    You are an intelligent and experienced data restructuring agent.
    Your task is to review the researched content provided and make a structured user journey.
    
    You must strictly adhere to the following guidelines.
    ## Guidlines
    - Use the level {Level} and user's experience with the topic {Experience} to decide the depth and balance of the user journey.
    - The users motive for taking this micro learning user journey is {motive}.
    - The user's knowledge level to different skills are as follows: (In percentage)
      1. Knowlege in SQL - {SQL}
      2. Data visualisation skill - {Viz}
      3. Statistical Anlysis skill - {Stats}
      4. Business Communication skill - {Comm}
      5. Data storytelling skill - {Story}
    - Set the content accordingly.
    - Divide the provided content to different stages
    - The toatal available time to cover the user journey is {available_time}.
    - **The sum of all stage durations MUST equal {available_time}. Do not exceed this.**
    - Include case studies where relevant, but **no projects**.
    - Based on the total available time, logically organize the topics into a structured, multi-stage user journey.
    - Distribute the available time ({available_time}) across the stages depending on content, focus and complexity.
    - Ensure the **sum of durations** across **all stages** is **{available_time}**
    - The user is either non-technical or minimally technical.
    
    ## Additional Instructions
    - **Before generating the stages, calculate the total duration and verify that the sum equals {available_time}.**
    - If necessary, adjust durations proportionally to maintain balance and alignment with the available time.
    - Do not comment or explain anything outside of the user journey content.
 
    ## Here is the researched content :
     {content}

    
    A detailed, structured user journey for a user on the given content, tailored to the {Level} level.
    The user is either a non technical or minimally technical person.
    - Generate a compelling main heading based on the user's Job Title and Topic.
      - The heading should reflect the relevance of the topic in the context of the user's role and the user's industry.
      - Keep it professional, engaging, and suitable.
    Job Title: {Job_Title}
    

    Divide the user journey into multiple stages.
    Each stage should contain:
      1. **heading** for the stage (include the stage number)
      2. **Focus**
      3. **Outcome**
      4. **Duration**
      5. **Topics Covered** — select relevant topics from the researched user journey content.
    The final stage should focus on application of the user's existing skills.
    Ensure the sum of durations across all stages is {available_time}.
    Do not include any project in the user journey, can include case studies.
    Should not comment anything other than the user journey.
    Format as markdown without '```'.
    Ensure the sum of durations across all stages is **exactly {available_time}**.
 
    Example output with two stages:
    # **Main Heading**
    ## **Stage1-Sub Heading**
    ### **Focus**
      Focus of stage1
    ### **Outcome**
      Expected outcome of stage 1
    ### **Duration**
      Duration1(Specify **ONLY** the time required to complete the stage1)
    ### **Topics Covered**
      - Topic1
      - Topic2
    ## **Stage2-Sub Heading**
    ### **Focus**
      Focus of stage2
    ### **Outcome**
      Expected outcome of stage 2
    ### **Duration**
      Duration2(Specify **ONLY** the time required to complete the stage2)
    ### **Topics Covered**
      - Topic1
      - Topic2
    Note:
    Duration1 + Duration2 should be equal to {available_time}
    Example output with three stages:
    # **Main Heading**
    ## **Stage1-Sub Heading**
    ### **Focus**
      Focus of stage1
    ### **Outcome**
      Expected outcome of stage 1
    ### **Duration**
      Duration1(Specify **ONLY** the time required to complete the stage1)
    ### **Topics Covered**
      - Topic1
      - Topic2
    ## **Stage2-Sub Heading**
    ### **Focus**
      Focus of stage2
    ### **Outcome**
      Expected outcome of stage 2
    ### **Duration**
      Duration2(Specify **ONLY** the time required to complete the stage2)
    ### **Topics Covered**
      - Topic1
      - Topic2
    ## **Stage3-Sub Heading**
    ### **Focus**
      Focus of stage3
    ### **Outcome**
      Expected outcome of stage 3
    ### **Duration**
      Duration3(Specify **ONLY** the time required to complete the stage2)
    ### **Topics Covered**
      - Topic1
      - Topic2
    Note:
    Duration1 + Duration2 + Duration3 should be equal to {available_time}
    ## Important:
    - **Sum of durations must equal {available_time}.**
    - No projects, but case studies allowed.
    - Markdown format only, no extra text or commentary.     

    contentfeedbackcompany_contextuser_contextzgStructured multi-stage user journey in markdown format with durations summing exactly to available_time)descrestructured_journeyN)__name__
__module____qualname____doc__dspy
InputFieldr   str__annotations__r   r   r   OutputFieldr    r!   r!   /home/azureuser/microlearn/backend/user_journey_with_openai/agentic_workflow/src/user_journey_service/tools/custom_restructure_tool.pyr      s   
  r   c                       s$   e Zd Z fddZdd Z  ZS )RestructureModulec                    s   t    tt| _tt}tjddddddddd	d
tjddddddddd	d
g}dd }tj|d}|j	||d || _t
d t
| d S )Na	  
        - **Topic Area**: Fundamentals  
        - **Subtopics/Concepts**:  
            - Introduction to Artificial Intelligence in Healthcare  
            - Overview of Machine Learning and its Role in Patient Care  
            - Types of AI: Supervised, Unsupervised, and Reinforcement Learning  
            - Ethical Considerations in AI Applications  
            - Understanding Data Privacy: HIPAA and GDPR Compliance  

        - **Topic Area**: Applications  
        - **Subtopics/Concepts**:  
            - AI in Predictive Analytics: Enhancing Patient Outcomes  
            - AI in Patient Monitoring: Wearables and Remote Monitoring  
            - Use of Natural Language Processing (NLP) in Clinical Documentation  
            - Chatbots and Virtual Health Assistants for Patient Engagement  
            - Remote Diagnosis and Telemedicine Solutions  

        - **Topic Area**: Tools and Techniques  
        - **Subtopics/Concepts**:  
            - Overview of Data Analytics Tools: Python and PyTorch for healthcare  
            - Using AWS HealthLake for Data Management in Healthcare  
            - Data Visualization Tools for Presenting AI Insights  
            - Techniques in Data Preprocessing and Feature Engineering  
            - Implementing AI Models for Real-Time Patient Monitoring  

        - **Topic Area**: Advanced Topics  
        - **Subtopics/Concepts**:  
            - Deep Learning Applications in Medical Imaging  
            - AI-Driven Decision Support Systems for Healthcare Professionals  
            - Integrating AI into Existing Clinical Workflows  
            - Case Studies on AI Success Stories in Patient Care  
            - Challenges and Limitations of AI in Healthcare Practice  

        - **Topic Area**: Current Trends  
        - **Subtopics/Concepts**:  
            - Rise of Telehealth Solutions and AI Integration  
            - Innovations in Wearable Health Technology and AI  
            - The Role of AI in Addressing Pandemic Challenges  
            - The Future of AI in Personalized Medicine  
            - Collaborations Between Tech Companies and Healthcare Institutions  

        This structured user journey content is designed to provide a comprehensive overview of AI in Healthcare, particularly aligned with the interests and learning objectives of a Healthcare Analyst looking to explore how AI can improve patient care.
            
                zFirst iterationa  
                Company Name: MediCore Solutions
                Industry: Healthcare
                Company Size: 2000+ employees
                Business Model: B2B and B2C SaaS
                Top Use Cases: Predictive analytics, Patient monitoring
                Learning Focus: AI diagnostics and workflow automation
                Tech Stack: Python, PyTorch, AWS HealthLake
                Compliance: HIPAA, GDPR
                a  
                Job Title: Healthcare Analyst
                Level: Intermediate
                Experience: 2 year
                motive: Exploring AI applications to improve patient care
                Knowledge in SQL: 70%
                Data Visualization Skill: 60%
                Statistical Analysis Skill: 40%
                Business Communication Skill: 50%
                Data Storytelling Skill: 45%
                Available Time: 240 minutes
                u  
                                
                # **Enhancing Patient Care through AI: A Healthcare Analyst’s Guide** 

                ## **Stage 1 - Introduction to AI in Healthcare**  
                ### **Focus**  
                Understanding the fundamental concepts of AI and its role in the healthcare industry.  
                ### **Outcome**  
                Establish a foundational knowledge of AI and machine learning principles, and comprehend ethical considerations and compliance regulations in healthcare.  
                ### **Duration**  
                60 minutes  
                ### **Topics Covered**  
                - Introduction to Artificial Intelligence in Healthcare  
                - Overview of Machine Learning and its Role in Patient Care  
                - Ethical Considerations in AI Applications  
                - Understanding Data Privacy: HIPAA and GDPR Compliance  

                ## **Stage 2 - AI Applications in Patient Care**  
                ### **Focus**  
                Exploring how AI is applied to diverse aspects of patient care, enhancing outcomes and engagement.  
                ### **Outcome**  
                Gain insights into practical applications of AI in predictive analytics, patient monitoring, and telemedicine, including the role of NLP and chatbots.  
                ### **Duration**  
                90 minutes  
                ### **Topics Covered**  
                - AI in Predictive Analytics: Enhancing Patient Outcomes  
                - AI in Patient Monitoring: Wearables and Remote Monitoring  
                - Use of Natural Language Processing (NLP) in Clinical Documentation  
                - Chatbots and Virtual Health Assistants for Patient Engagement  
                - Remote Diagnosis and Telemedicine Solutions  

                ## **Stage 3 - Tools, Techniques, and Advanced Topics**  
                ### **Focus**  
                Familiarizing with the technical tools and advanced applications of AI in healthcare while reviewing success stories.  
                ### **Outcome**  
                Understand data analytics tools, case studies of successful AI applications, and integration strategies for AI within existing clinical workflows.  
                ### **Duration**  
                90 minutes  
                ### **Topics Covered**  
                - Overview of Data Analytics Tools: Python and PyTorch for healthcare  
                - Using AWS HealthLake for Data Management in Healthcare  
                - Deep Learning Applications in Medical Imaging  
                - AI-Driven Decision Support Systems for Healthcare Professionals  
                - Case Studies on AI Success Stories in Patient Care  

                Total Duration: 60 + 90 + 90 = 240 minutes
                )r   r   r   r   r   r   r   r   r   z'Research on SQL optimization techniquesz6Focus on advanced optimizations for experienced users.a  
                Company Name: FinNext Global
                Industry: FinTech
                Company Size: 1000-1500 employees
                Business Model: B2B
                Top Use Cases: Cross-border payments, Fraud prevention
                Learning Focus: Blockchain adoption and market opportunities
                Tech Stack: Ethereum, Hyperledger, Azure Blockchain Service
                Compliance: KYC, AML
                a  
                Job Title: Business Development Executive
                Level: Beginner
                Experience: 5 years
                motive: Understanding blockchain for business strategy alignment
                Knowledge in SQL: 60%
                Data Visualization Skill: 70%
                Statistical Analysis Skill: 40%
                Business Communication Skill: 50%
                Data Storytelling Skill: 45%
                Available Time: 240 minutes
                a  
         # **Understanding Blockchain for Business Strategy Alignment in FinTech** 

        ## **Stage 1 - Introduction to Blockchain Fundamentals**  
        ### **Focus**  
        Introduce the fundamental concepts of blockchain technology.
        ### **Outcome**  
        Gain foundational knowledge about blockchain and its significance in the FinTech landscape.  
        ### **Duration**  
        60 minutes  
        ### **Topics Covered**  
        - Introduction to Blockchain  
        - Key Terms  
        - Differences between Blockchain Types  
        - Basic Mechanisms  

        ## **Stage 2 - Blockchain Applications in FinTech**  
        ### **Focus**  
        Explore specific blockchain applications relevant to FinTech, particularly in payments and fraud detection.  
        ### **Outcome**  
        Understand how blockchain enhances business processes within the FinTech sector.  
        ### **Duration**  
        60 minutes  
        ### **Topics Covered**  
        - Cross-border Payments  
        - Fraud Prevention  
        - Digital Identity Management  

        ## **Stage 3 - Tools and Platforms for Blockchain**  
        ### **Focus**  
        Familiarize with key blockchain platforms and tools that can be leveraged in business strategies.  
        ### **Outcome**  
        Identify relevant blockchain tools and platforms that can integrate into existing FinTech systems.  
        ### **Duration**  
        50 minutes  
        ### **Topics Covered**  
        - Overview of Ethereum and Hyperledger  
        - Azure Blockchain Service  
        - Integration with Existing Systems  

        ## **Stage 4 - Identifying Market Opportunities**  
        ### **Focus**  
        Analyze current trends, competition, and customer engagement opportunities within blockchain adoption.  
        ### **Outcome**  
        Develop insights on market opportunities and strategic advantages offered by blockchain.  
        ### **Duration**  
        40 minutes  
        ### **Topics Covered**  
        - Trends in Blockchain Adoption  
        - Competitive Landscape  
        - Customer Engagement  

        ## **Stage 5 - Business Strategy Alignment**  
        ### **Focus**  
        Align blockchain knowledge with business strategy and growth opportunities.  
        ### **Outcome**  
        Formulate strategic partnerships and business models leveraging blockchain technology.  
        ### **Duration**  
        30 minutes  
        ### **Topics Covered**  
        - Strategic Partnerships  
        - Business Models leveraging Blockchain  
        - Measuring ROI  

        ## **Stage 6 - Future Developments and Skills Application**  
        ### **Focus**  
        Understand future trends and how to continue developing skills in blockchain.  
        ### **Outcome**  
        Identify emerging trends and resources for continuous learning, and apply existing skills in statistical analysis and data visualization to business scenarios.  
        ### **Duration**  
        40 minutes  
        ### **Topics Covered**  
        - Emerging Trends  
        - Regulatory Landscape  
        - Education and Skill Development  

        **Total Duration: 240 minutes** 
                c                 S   s$   t d|jv ot| jd|jv S )NStage)intr   r   count)goldpredtracer!   r!   r"   restructure_metric  s   $z6RestructureModule.__init__.<locals>.restructure_metric)metric)trainsetz=== Optimized ===)super__init__r   Predictr   restructure_predictorExamplewith_inputsBootstrapFewShotcompileprint)self	predictorr,   r*   	optimizer	__class__r!   r"   r.      s8   

,
s
g  bzRestructureModule.__init__c                 C   s   | j ||||dS )N)r   r   r   r   )r0   )r6   r   r   r   r   r!   r!   r"   forward  s   zRestructureModule.forward)r   r   r   r.   r;   __classcell__r!   r!   r9   r"   r#      s     rr#   c                   @   s  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< 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< 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!< 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 )-RestructureToolInputz)Input schema for RestructureAnalysisTool..z7The researched content to structure into a user journey)descriptionr   z1User feedback (First iteration or update request)r   zName of the companyCompany_NamezIndustry of the companyIndustryzSize of the companyCompany_SizezCompany's business modelBusiness_Modelz$Top use cases the company focuses onTop_Use_CaseszLearning focus for the userLearning_FocuszCompany's tech stack
Tech_stackz Relevant compliance requirements
CompliancezJob title of the user	Job_Titlez1Learning level (Beginner, Intermediate, Advanced)Levelz User's experience with the topic
ExperiencezUser's motive for researchmotivezKnowledge in SQL (percentage)SQLz%Data visualization skill (percentage)Vizz'Statistical analysis skill (percentage)Statsz)Business communication skill (percentage)Commz$Data storytelling skill (percentage)Storyz6Total available time for the user journey (in minutes)available_timeN)r   r   r   r   r   r   r   r   r   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   r%   rL   rM   rN   rO   rP   r!   r!   r!   r"   r=     s,   
 r=   c                *   @   s   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dededededededededededededededef*ddZdS )RestructureAnalysisToolzRestructure Analysis ToolnamezRestructures researched content into a structured user journey syllabus based on user feedback, company context, and user profile. Ensures durations sum exactly to available_time.r>   args_schemar   r   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   returnc                 C   s   d| d| d| d| d| d| d|	 d|
 d	}d
| d| d| d| d| d| d| d| d| d| d	}t  }|||||}|jS )Nz
        Company Name: z
        Industry: z
        Company Size: z
        Business Model: z
        Top Use Cases: z
        Learning Focus: z
        Tech Stack: z
        Compliance: z	
        z
        Job Title: z
        Level: z
        Experience: z
        Motive: z
        Knowledge in SQL: z$%
        Data Visualization Skill: z&%
        Statistical Analysis Skill: z(%
        Business Communication Skill: z#%
        Data Storytelling Skill: z%
        Available Time: )r#   r;   r   )r6   r   r   r?   r@   rA   rB   rC   rD   rE   rF   rG   rH   rI   rJ   rK   rL   rM   rN   rO   rP   r   r   restructureresultr!   r!   r"   _run  sR   	
zRestructureAnalysisTool._runN)r   r   r   rR   r   r   r>   r=   rS   r   r   r%   rW   r!   r!   r!   r"   rQ     s`   
 
	
rQ   )typingr   crewai.toolsr   pydanticr   r   r   osdotenvr   getenvazure_api_keyazure_api_hostazure_deployment_idazure_api_versionLMr   	configure	Signaturer   Moduler#   r=   rQ   r!   r!   r!   r"   <module>   s2    




  |