o
    -hZ                     @   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-minig333333?)api_keyapi_baseapi_versiontemperature)lmc                   @   s   e Zd ZU dZejddZeed< ejddZ	eed< ejddZ
eed< ejd	dZeed
< ejddZeed< ejddZeed< ejddZeed< dS )ContentCreatureSignaturea  
    You are an expert corporate trainer and experienced mentor.
    Create detailed, engaging course content for **audio narration** for Stage {stage} of a course titled **"{main_heading}"**.
    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}
    You are an expert corporate trainer and experienced mentor.
        Create detailed, engaging course content for **audio narration** for Stage {stage} of a course titled **"{main_heading}"**.
        This is the focus, outcome and topics to be covered in this stage
        {user_journey}
    
        ## Instructions:
        - Write in a clear, professional, yet naturally flowing spoken style suitable for audio narration.
        - The user is allowed to pick either of the four approaches for the content.
        1. Low-code approach    2. Hands-on coding    3. Mixed approach   4. Any other
        - The users content preference is {Level}
        - Set the content accordingly.
        - The users motive for learning this content is {motive}.
        - Structure the content with a warm **introduction**, a clear and connected **body** covering all concepts in detail, and a thoughtful **conclusion** for each stage.
        - Use smooth transitions between topics to ensure the narration feels connected and easy to follow.
        - Avoid overuse of bullet points or technical jargon; present information conversationally as if speaking directly to experienced professionals.
        - Include relevant examples.
        - Conclude with **3 reflection questions** designed to prompt self-assessment and application of the concepts discussed for each satge.
    
    Markdown, with the following structure for each stage:
    - ## Introduction
    - ## Main Content
    - ### {topics} - Not more than **600** words.
    - ## Conclusion
    - ## Reflection Questions
 
    Maintain a clear, engaging, motivational, and human-centered tone throughout, suitable for audio delivery.

    "Stage number or name of the course)descstageMain title of the coursemain_heading)Focus, outcome, and topics for this stageuser_journey<User's content preference (Low-code, Hands-on, Mixed, Other)LevelUser's motive for learningmotivez!Details about the company contextcompany_contextzXMarkdown content with Introduction, Main Content, Conclusion, and 3 Reflection Questionscontent_markdownN)__name__
__module____qualname____doc__dspy
InputFieldr   str__annotations__r   r   r   r   r   OutputFieldr    r(   r(   /home/azureuser/microlearn/backend/user_journey_with_openai/agentic_workflow/src/user_journey_service/tools/custom_content_creature_tool.pyr      s   
 (r   c                       s$   e Zd Z fddZdd Z  ZS )ContentCreatureModulec              
      s   t    tt| _tt}tjdd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ddg}dd }tj|d}|j	| j|d | j| _
td t| j
 d S )Nz'Stage 1 - Fundamentals of Data AnalysiszFIntegrated User Journey: Mastering Data Analysis for Business Analystsai  
                Stage: Stage 1 - Fundamentals of Data Analysis
                Focus: Understanding the foundational concepts of data analysis and its relevance in business contexts, particularly in financial services.
                Outcome: Gain a solid grasp of data analysis principles, key terminologies, and the data analysis process.
                Duration: 45 minutes
                Topics Covered:
                - Introduction to Data Analysis
                - Importance of Data Analysis in Business and Financial Services
                - Key Terminologies in Data Analysis (e.g., datasets, variables, data cleaning)
                - Overview of Data Analysis Process (Collecting, Processing, Analyzing, Interpreting)
                - Types of Data (Qualitative vs. Quantitative)
                - Data Sources (Internal vs. External)
                zLow-code approachzcareer advancementaw  
                Company Name: FinSight
                Industry: Financial Services
                Company Size: 250 employees
                Business Model: B2B 
                Top Use Cases: Financial modeling
                Learning Focus: Data Analysis
                Tech Stack:  Excel, Tableau, SQL Server
                Compliance: SOX, PCI DSS
                u!  
                
                ## Introduction

                Welcome to the first stage of our course, &quot;Integrated User Journey: Mastering Data Analysis for Business Analysts.&quot; In this module, we will explore the **Fundamentals of Data Analysis**. This stage is crucial as it lays the groundwork for your journey into understanding data, its significance in decision-making, and how to leverage it effectively in your role as a business analyst at {Company_Name} within the {Industry} sector. Whether your company is a small start-up or a large enterprise, mastering these fundamentals will not only enhance your analytical skills but also provide you with the tools to drive impactful business decisions.

                ## Main Content

                Let’s begin by discussing **SQL**, the language most business analysts use to interact with databases. SQL, or Structured Query Language, allows you to extract and manipulate data from relational databases. For our low-code approach, we will focus on understanding the basic commands that will enable you to retrieve meaningful information without delving too deep into complex coding.

                Consider a scenario where you need to analyze customer purchase data. Using a simple SQL query, you could write:

                ```sql
                SELECT CustomerID, PurchaseAmount, PurchaseDate 
                FROM Sales 
                WHERE PurchaseDate &gt;= &#39;2023-01-01&#39;;
                ```

                This command retrieves all purchases made in the year 2023. It’s straightforward, yet it provides valuable insights into customer behavior. 

                Now, let’s shift our focus to **Statistics**. Statistics is the backbone of data analysis. It helps you summarize and interpret data effectively. For instance, understanding measures of central tendency—mean, median, and mode—can help you identify trends in customer purchases. If your analysis indicates that the mean purchase amount is significantly higher than the median, it could suggest that a few customers are making exceptionally high purchases, which might skew your overall results. This insight can inform strategies on how to target different customer segments.

                Next, we arrive at the importance of **Communication**. As a business analyst, your role is not just to analyze data but to communicate findings effectively to stakeholders. This requires translating complex data insights into actionable business strategies. Consider this: after analyzing customer data, you may need to present your findings to your marketing team. Instead of presenting raw data, you could summarize your insights by saying, “Our analysis shows that customers aged 25-34 contribute to 60% of our sales. Tailoring our marketing efforts to this demographic could enhance our engagement significantly.” This form of communication ensures that your insights are actionable and relevant.

                Now, let’s delve into **Storytelling** with data. This is an art that combines your analytical skills with creativity. Storytelling allows you to weave a narrative around the data, making it more relatable and compelling. For example, if you discovered that customer satisfaction scores increased after implementing a new feature, you could narrate a story highlighting how this change positively impacted the user journey. By illustrating the before-and-after scenario, you create a powerful case for continuing to invest in user experience improvements.

                As we wrap up this stage, remember that the interplay between SQL, statistics, communication, and storytelling is what makes data analysis powerful. Each aspect complements the others, providing a holistic view of how to analyze and present data effectively in your role.

                ## Conclusion

                In this stage, we’ve covered the fundamentals of data analysis, focusing on SQL, statistics, communication, and storytelling. These components are essential for any business analyst seeking to leverage data for strategic decision-making. As you progress through this course, keep in mind how these fundamentals can be applied in real-world scenarios within {Company_Name}. 

                ## Reflection Questions

                1. How can you apply SQL queries to extract insights from your current data sets at {Company_Name}?
                2. Reflect on a time when you had to present data findings to a non-technical audience. How did you ensure your communication was effective?
                3. In what ways can storytelling enhance your presentations and make your data insights more impactful for stakeholders? 

                Thank you for joining me in this exploration of the fundamentals of data analysis. I look forward to guiding you further on this exciting journey!

                    )r   r   r   r   r   r   r   r   r   r   r   r   r   z)Stage 2 - Data Collection and PreparationaN  
                Stage: Stage 2 - Data Collection and Preparation
                Focus: Learning effective data collection methods and preparing collected data for analysis, while understanding ethical considerations.
                Outcome: Develop skills to collect reliable data, manage it effectively, and prepare it for analysis while ensuring quality and ethical compliance.
                Duration: 40 minutes
                Topics Covered:
                - Methods of Data Collection (Surveys, Interviews, Observations)
                - Best Practices for Data Collection
                - Ethical Considerations in Data Collection
                - Data Management Techniques
                - Data Cleaning (Dealing with missing values, outliers)
                - Data Transformation (Normalization, Aggregation)
                u  
                                
                ## Introduction

                Welcome to Stage 2 of our course, &quot;Integrated User Journey: Mastering Data Analysis for Business Analysts.&quot; In this stage, we will delve into **Data Collection and Preparation**, essential steps that set the foundation for effective data analysis. By gathering and refining data, you ensure that the insights derived are accurate and actionable. In our journey today, we will focus on various approaches to data collection that align with the context of your organization, {Company_Name}, in the {Industry} sector, emphasizing your specific business model and top use cases. 

                As business analysts, you will often face challenges in managing data from various sources, ensuring quality, and preparing it for analysis. This stage will equip you with best practices to tackle these challenges, whether you prefer a low-code approach, hands-on coding, or a mixed methodology. Let’s embark on this journey together!

                ## Main Content

                ### Understanding the Data Landscape

                First, let’s take a moment to understand the different types of data you might encounter. In the context of {Company_Name}, your data could range from customer interactions on your website to operational metrics derived from your tech stack, {Tech_stack}. It’s crucial to categorize your data into structured and unstructured forms. Structured data, like database entries, is easier to analyze, while unstructured data, such as customer feedback or social media posts, requires more effort to process.

                ### Identifying Data Sources

                Next, identify where your data resides. This could include databases, data lakes, or third-party tools aligned with your top use cases, such as customer segmentation or sales forecasting. Utilizing tools that integrate seamlessly with your existing tech stack can streamline this process significantly. For instance, if you’re using a CRM system, explore its API to pull data directly into your analysis environment, saving time and reducing manual entry errors.

                ### Data Collection Techniques

                Once you’ve identified your sources, it’s time to collect the data. Depending on your approach, you may choose to use SQL for querying databases or leverage low-code platforms that can connect to various data sources without extensive programming knowledge. For those who prefer a hands-on coding approach, familiarizing yourself with languages like Python or R can open up powerful data collection capabilities. 

                For example, if you’re using SQL, you might write a query to pull customer purchase history, which can look something like this:

                ```sql
                SELECT customer_id, purchase_date, purchase_amount 
                FROM purchases 
                WHERE purchase_date &gt;= &#39;2023-01-01&#39;;
                ```

                This query will help you analyze customer behavior over a specific period, giving you insights into purchasing trends.

                ### Data Cleaning and Preparation

                Now that we have collected our data, it’s essential to clean and prepare it for analysis. This step involves removing duplicates, correcting inconsistencies, and handling missing values. For those unfamiliar with data cleaning techniques, using libraries like Pandas in Python can make this process more manageable. For instance, you can identify and fill missing values with the following code:

                ```python
                import pandas as pd

                # Load your dataset
                data = pd.read_csv(&#39;customer_data.csv&#39;)

                # Fill missing values with the mean
                data[&#39;purchase_amount&#39;].fillna(data[&#39;purchase_amount&#39;].mean(), inplace=True)
                ```

                In this example, we are replacing any missing purchase amounts with the average value, ensuring our dataset remains robust for analysis.

                ### Ensuring Compliance

                As we work through data collection and preparation, compliance with regulations such as GDPR or HIPAA is paramount, particularly in the {Industry} sector. Make sure you have a clear understanding of data privacy laws that impact your data collection processes. Implementing proper data governance practices not only protects your organization but also builds trust with your users.

                ### Documentation and Communication

                Finally, documenting your data collection and preparation processes is critical. This documentation will serve as a reference for future projects and facilitate communication with stakeholders. Clear communication about the data you’re using, its quality, and its relevance to your business model will empower decision-makers to act on the insights you provide.

                ## Conclusion

                In conclusion, Stage 2 of our course has provided you with a roadmap to effectively collect and prepare data for analysis. By understanding the data landscape, identifying sources, employing appropriate collection techniques, ensuring compliance, and documenting your processes, you are laying a solid foundation for insightful data analysis. Remember, the quality of your analysis is only as good as the data you prepare.

                As we transition to the next stage, keep the importance of these foundational steps in mind. They will serve as the backbone of your analytical capabilities and ultimately drive better business decisions at {Company_Name}.

                ## Reflection Questions

                1. What are the primary data sources available to you at {Company_Name}, and how can you access them effectively?
                2. Reflect on a recent data collection experience. What challenges did you face, and how could you apply the techniques discussed today to improve that process?
                3. How do you plan to ensure compliance with data regulations in your future data collection and preparation efforts? 

                Thank you for your attention, and I look forward to seeing you in the next stage

                    c                    s,   g d}|j pd tt fdd|D S )z
            Custom metric to check if the generated content_markdown includes
            the required structure: Introduction, Main Content, Conclusion, and Reflection Questions.
            )z## Introductionz## Main Contentz## Conclusionz## Reflection Questions c                 3   s    | ]}| v V  qd S )Nr(   ).0sectionoutputr(   r)   	<genexpr>
  s    zIContentCreatureModule.__init__.<locals>.content_metric.<locals>.<genexpr>)r   intall)goldpredtracerequired_sectionsr(   r.   r)   content_metric  s   
z6ContentCreatureModule.__init__.<locals>.content_metric)metric)trainsetz=== Optimized Predictor ===)super__init__r#   Predictr   content_predictorExamplewith_inputsBootstrapFewShotcompileoptimized_predictorprint)self	predictorr9   r7   	optimizer	__class__r(   r)   r;   R   s@   


E
c  .
zContentCreatureModule.__init__c                 C   s   | j ||||||dS )Nr   r   r   r   r   r   )r=   )rD   r   r   r   r   r   r   r(   r(   r)   forward  s   zContentCreatureModule.forward)r   r    r!   r;   rJ   __classcell__r(   r(   rG   r)   r*   Q   s     Fr*   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< dS )ContentCreatureToolInputz%Input schema for ContentCreatureTool..r   )descriptionr   r   r   r   r   r   r   r   r   zName of the companyCompany_NamezIndustry of the companyIndustryzSize of the companyCompany_SizezBusiness model of the companyBusiness_Modelz$Top use cases the company focuses onTop_Use_CaseszLearning focus for the companyLearning_FocuszCompany's tech stack
Tech_stackz Relevant compliance requirements
ComplianceN)r   r    r!   r"   r   r   r%   r&   r   r   r   r   rN   rO   rP   rQ   rR   rS   rT   rU   r(   r(   r(   r)   rL   "  s   
 rL   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dedededededededefddZdS )ContentCreatureToolzContent Creature ToolnamezGenerates detailed, engaging course content in audio narration style for a given stage of a course, based on company context, user preferences, and user motives.rM   args_schemar   r   r   r   r   rN   rO   rP   rQ   rR   rS   rT   rU   returnc                 C   sX   d| d| d| d|	 d|
 d| d| d| d	}t  }|j||||||d
}|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	
        rI   )r*   rJ   r   )rD   r   r   r   r   r   rN   rO   rP   rQ   rR   rS   rT   rU   r   moduleresultr(   r(   r)   _run;  s6   	zContentCreatureTool._runN)r   r    r!   rW   r%   r&   rM   rL   rX   r   r   r\   r(   r(   r(   r)   rV   3  sD   
 
	
rV   )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*   rL   rV   r(   r(   r(   r)   <module>   s0    




6 R