o
    &hc                     @   sJ  d dl Z d dlZd dlmZmZ d dlZd dlmZ d dl	m
Z
 d dlmZ d dlmZ d dlmZ d dlmZ d dlmZ d d	lmZmZmZmZ d dlmZ d dl Z G d
d deZG dd deZG dd deZG dd deZdedefddZdd Zdd Zdd Zdd Zdd Z d d! Z!d"d# Z"d$d% Z#d&d' Z$d(d) Z%d*d+ Z&d,d- Z'd.d/ Z(e)d0krd1Z*d2gZ+d3gZ,d4Z-d5Z.d6Z/d7Z0d8Z1d9Z2ee-e.e/e0e1e2Z3e4d: e4e3 e5e3ere 6e3Z3e3d; Z7e j8e7d<d=d>Z9e:d?d@Z;e <e;Z=e>e=dA Z?e=d; Z@W d   n	1 sw   Y  d3ZAeeAZBe4dB e4eB e4dC e!eBe?ZCe4eC e4eDeC dDZEdDZFeCG D ]%ZHeHI JdErSeHdFd K ZEq?eHI JdGrceHdHd K ZFq?e4dEdIeE dI e4dGdIeF dI eEeFdJZLdKdL eCM D ZNe'e+eNe9ZOe&eFeNe9ZPe4dM e4eO e4dN e4eP dS dS )O    N)ListOptional)ChatGroq)
ChatOllama)PromptTemplate)LLMChain)r   )PydanticOutputParser)	BaseModelField	validatorValidationErrorc                   @   sJ   e Zd ZU eddZeed< eed< eed< eed< eddZeed< dS )	 SimpleOnlineCourseRecommendation )defaultplatformcourse_namereason_to_recommendrelevance_scorelinkN)	__name__
__module____qualname__r
   r   str__annotations__intr    r   r   A/var/www/eduai.edurigo.com/doc_train/edurigo_ai/Puru/tna_final.pyr      s   
 r   c                   @   s&   e Zd ZU eed< eed< eed< dS )!SimpleOfflineCourseRecommendationr   r   r   N)r   r   r   r   r   r   r   r   r   r   r      s   
 r   c                   @      e Zd ZU ee ed< dS )#CourseRecommendationsOutput_OfflinecoursesN)r   r   r   r   r   r   r   r   r   r   r         
 r   c                   @   r   )CourseRecommendationOutputrecommendationsN)r   r   r   r   r   r   r   r   r   r   r"       r!   r"   llm_responsereturnc              
   C   sl   zt | }tdi |}|W S  t jy# } ztd| d }~w ty5 } ztd| d }~ww )NzInvalid JSON format: zPydantic validation error:
r   )jsonloadsr"   JSONDecodeError
ValueErrorr   )r$   parsed_jsonvalidated_dataever   r   r   parse_simple_llm_response#   s   
r.   c                    sX  t | }|jj j |_|  }||jvr'td| dt|j ||  	 
 }t |}|jj j |_         g}	|	D ]}
|
|jvrmtd|
 dt|j qY|j|	d} fdd| D }||d}tdd	d
d}tj||dd W d    n1 sw   Y  tj|ddS )NzColumn 'z/' not found in skills file. Available columns: z0' not found in courses file. Available columns: )subsetc                    s(   g | ]\}}| |  | d qS ))namedescriptioncourseIdr   ).0_rowdescription_column	id_columnname_columnr   r   
<listcomp>H   s    z!excel_to_json.<locals>.<listcomp>organization_skillsr    DataIb1.jsonwutf-8encoding   indent)pd
read_excelcolumnsr   lowerstripr)   listdropnauniquetolistiterrowsopenr&   dumpdumps)skills_fileskills_columncourses_filer9   r7   r8   	df_skillsskills
df_coursesrequired_columnscolr    courses_listdata	json_filer   r6   r   excel_to_json-   s6   




r]   c                 C   s   t | trdd | dD } t |trdd |dD }t |tr-dd |dD }t|t|kr9tddd t||D }| |d}td	d
dd}tj||dd W d    n1 sbw   Y  tj	|ddS )Nc                 S      g | ]
}|  r|  qS r   rI   r3   skillr   r   r   r:   `       z'string_data_to_json.<locals>.<listcomp>,c                 S   r^   r   r_   )r3   r0   r   r   r   r:   c   rb   c                 S   r^   r   r_   )r3   descr   r   r   r:   f   rb   z=The number of course names and descriptions must be the same.c                 S   s   g | ]	\}}||d qS ))r0   r1   r   )r3   r0   rd   r   r   r   r:   m       r;   zDataFromString.jsonr>   r?   r@   rB   rC   )

isinstancer   splitlenr)   ziprO   r&   rP   rQ   )rV   course_namescourse_descriptionsrZ   r[   r\   r   r   r   string_data_to_json]   s    


rl   c                 C      t ddd}tdgdd}| }||B }d|i}||}i }d }|j dD ];}	|	 }	|	dr:|	}g ||< q(|	d	rF|	}g ||< q(|	d
rc|rcdd |	td
d  dD }
|
||< d }q(|S )N
gemma3:12br   modeltemperature	goals_strab  
            You are an industry expert with over 10 years of experience in analyzing business goals and identifying the most critical skills required to achieve them.

            Given the following business goals:
            {goals_str}

            

            Analyze the requirements for each goal  and provide a structured list of essential skills needed to address them effectively.

            For each goal , clearly indicate which one it pertains to.

            - Ensure the list of skills for each goal/problem is precise, diverse, and highly relevant.
            - Provide the skills in a comma-separated format on a line starting with "Skills:" immediately following the Goal  statement.
            - Do not include explanations, extra text, or other formatting besides the Goal statement and the "Skills:" line.

            **Output Format Example:**
            Goal: Increase customer retention
            Skills: Customer Service, Communication, Problem-Solving

            Problem: High employee turnover
            Skills: Employee Engagement, Leadership, Compensation Strategy
            input_variablestemplate
Goal:Problem:Skills:c                 S      g | ]}|  qS r   r_   r`   r   r   r   r:          zTNA_Goals.<locals>.<listcomp>rc   r   r   invokecontentrI   rg   
startswithrh   )goalsllmskill_extraction_promptrr   skill_extraction_chaininputresponseextracted_skillscurrent_itemlineskills_listr   r   r   	TNA_Goals{   s:   




 r   c                 C   rm   )Nrn   r   ro   problems_strav  
            You are an industry expert with over 10 years of experience in analyzing business problems and identifying the most critical skills required to achieve them.

         

            Given the following business problems:
            {problems_str}

            Analyze the requirements for each  problem and provide a structured list of essential skills needed to address them effectively.

            For each goal and problem, clearly indicate which one it pertains to.

            - Ensure the list of skills for each problem is precise, diverse, and highly relevant.
            - Provide the skills in a comma-separated format on a line starting with "Skills:" immediately following the Problem statement.
            - Do not include explanations, extra text, or other formatting besides the Problem statement and the "Skills:" line.

            **Output Format Example:**
            Goal: Increase customer retention
            Skills: Customer Service, Communication, Problem-Solving

            Problem: High employee turnover
            Skills: Employee Engagement, Leadership, Compensation Strategy
            rs   rv   rw   rx   ry   c                 S   rz   r   r_   r`   r   r   r   r:      r{   z TNA_Problems.<locals>.<listcomp>rc   r|   )problemsr   r   r   r   r   r   r   r   r   r   r   r   r   TNA_Problems   s:   




 r   c           	      C   P   t |}i }|  D ]\}}t |}|| }||@ }t|t|d||< q
|S N)existing_skillsmissing_skillssetitemsrJ   	required_skills_dictr<   organization_skills_setanalysis_resultsitemrequired_skillsrequired_skills_setr   r   r   r   r   find_skill_gaps_goals      r   c           	      C   r   r   r   r   r   r   r   find_skill_gaps_problems
  r   r   c           
      C   d   | r|st dtddgdd}tddgdd}tdd	d
}| }|}||B }||d}||}	|	S )N0Goal/problem and missing skills must be providedgoal_or_problemmissing_skills_strS  
        As an expert learning and development specialist, your task is to recommend the most suitable online courses 
        that directly address the following:

        Business Goal/Problem: {{goal_or_problem}}

        Specific Skills Gaps Identified:
        {{missing_skills_str}}

        Recommendation Guidelines:
        1. Identify the most critical online courses that precisely match the skill gaps
        2. Only recommend courses with at least 95% relevance to the goal and missing skills
        3. Provide a comprehensive rationale for each course recommendation
        4. Consider courses from major online learning platforms (Coursera, Udemy, edX, etc.)

        Evaluation Criteria:
        - Direct alignment with the specific skills needed
        - Depth of content coverage
        - Practical applicability to the business goal
        - Potential to close the identified skill gaps

        **Recommended Output Format:**
        [Platform] Course Name - Relevance % - Detailed Relevance Explanation
        Example: 
        [Coursera] Advanced Data Analysis for Marketing Professionals - 98% - Comprehensive course covering advanced 
        statistical analysis, data visualization, and marketing-specific data interpretation techniques directly addressing 
        the identified skill gaps in data analysis capabilities
        rs   goala  
You are a professional learning and development advisor.

Given the user's business goal , and their identified missing skills, output the recommendation report in **STRICT JSON FORMAT**.

### JSON Output Format:

{{
Goal:{{
  "goalTitle": "string",
  "missing_skills": ["list", "of", "skills"],
  "course_recommendations_online": [
    {{
      "platform": "Platform name",
      "course_name": "Course title",
      "level": "Beginner / Intermediate / Advanced",
      "why_recommended": "Reason why the course is useful",
      "relevance_score": integer (0-100),
      "link": "Course URL or 'Available on [Platform]'"
    }}
  ]
  
  }}
}}

**Rules:**
- Only return valid JSON, no markdown, no headings.
- Use double quotes `"` around all keys and string values.
- Ensure the JSON is syntactically correct (ready for `json.loads()`).
- If a field is missing, use an empty string "" or empty array [].
- Only give those courses which relevance_score more than 75

---

### Inputs:

Goal / Problem:
{goal}

Missing Skills:
{missing_skills_str}
rn   r   ro   r   r   r)   r   r   r}   )
r   r   course_recommendation_promptcourse_recommendation_prompt2r   goal_strr   online_course_extraction_chain
input_datar#   r   r   r   recommend_online_courses_goal  s,    .
r   c           
      C   r   )N+Problem and missing skills must be providedr   r   r   rs   problemap  
You are a professional learning and development advisor.

Given the user's business problem , and their identified missing skills, output the recommendation report in **STRICT JSON FORMAT**.

### JSON Output Format:
Goal:
{{
  "problemTtile": "string",
  "missing_skills": ["list", "of", "skills"],
  "course_recommendations_online": [
    {{
      "platform": "Platform name",
      "course_name": "Course title",
      "level": "Beginner / Intermediate / Advanced",
      "why_recommended": "Reason why the course is useful",
      "relevance_score": integer (0-100),
      "link": "Course URL or 'Available on [Platform]'"
    }}
  ],
  "suggested_order": [
    "Course 1 name",
    "Course 2 name",
    "Course 3 name"
  ]
}}

**Rules:**
- Only return valid JSON, no markdown, no headings.
- Use double quotes `"` around all keys and string values.
- Ensure the JSON is syntactically correct (ready for `json.loads()`).
- If a field is missing, use an empty string "" or empty array [].
- Only give those courses which relevance_score more than 75

---

### Inputs:

Goal / Problem:
{problem}

Missing Skills:
{missing_skills_str}
rn   r   ro   r   r   r   )
r   r   r   r   r   problem_strr   r   r   r#   r   r   r   !recommend_online_courses_problems  s,    0
r   c           
      C   sn   | r|st dtg ddd}tddd}| }|}td t|  t| ||B }|||d}||}	|	S )	Nz(Goal and missing skills must be providedr   r   course_data_jsonaQ  
You are a professional learning and development advisor.

You are given:
- A business goal
- A list of missing skills
- A database of available courses (with name and description)

### Business Goal:
{goal}

### Missing Skills:
{missing_skills_str}

### Available Courses:
{course_data_json}

Your task is to:
1. Evaluate each course for how well it helps achieve the goal and address the missing skills.
2. Select the most relevant courses (maximum 5).
3. For each course, return ONLY the following fields:
   - "course_name": string
   - "reason_to_recommend": string
   - "relevance_score": integer (0-100)

Don't give any extra text . Just return JSON Output.
Here is the JSON class to validate the output that you give. Make sure the check always passes.

class SimpleOfflineCourseRecommendation(BaseModel):
    
    ### JSON Output Format:

{{
Goal:{{
  "goaltitle": "string",
  "missing_skills": ["list", "of", "skills"],
  "course_recommendations_offline": [
    {{
      
      "course_name": "Course title",
      
      "why_recommended": "Reason why the course is useful",
      "relevance_score": integer (0-100),
      "link": "Course URL or 'Available on [Platform]'"
    }}
  ],
  "suggested_order": [
    "Course 1 name",
    "Course 2 name",
    "Course 3 name"
  ]
  }}
}}

**Rules:**
- Only return valid JSON, no markdown, no headings.
- Use double quotes `"` around all keys and string values.
- Ensure the JSON is syntactically correct (ready for `json.loads()`).
- If a field is missing, use an empty string "" or empty array [].
- Only give those courses which relevance_score more than 75


rs   rn   r   ro   zgoal r)   r   r   printr}   )
r   r   courses_available'course_recommendation_prompt_simplifiedr   r   r   r   r   r#   r   r   r   recommend_offline_courses_goal  s,   F
r   c           
      C   s^   | r|st dtg ddd}tddd}| }|}td ||B }|||d}||}	|	S )	Nr   r   r   r   a  
You are a professional learning and development advisor.

You are given:
- A business problem
- A list of missing skills
- A database of available courses (with name and description)

### Business Goal:
{problem}

### Missing Skills:
{missing_skills_str}

### Available Courses:
{course_data_json}

Your task is to:
1. Evaluate each course for how well it helps achieve the goal and address the missing skills.
2. Select the most relevant courses (maximum 5).
3. For each course, return ONLY the following fields:
   - "course_name": string
   - "reason_to_recommend": string
   - "relevance_score": integer (0-100)

Don't give any extra text . Just return JSON Output.
Here is the pydantic class to validate the output that you give. Make sure the check always passes.

class SimpleOfflineCourseRecommendation(BaseModel):
    
    class SimpleOfflineCourseRecommendation(BaseModel):
    
    ### JSON Output Format:
Goal:
{{
  "problemTtile": "string",
  "missing_skills": ["list", "of", "skills"],
  "course_recommendations_offline": [
    {{
      
      "course_name": "Course title",
      
      "why_recommended": "Reason why the course is useful",
      "relevance_score": integer (0-100),
      "link": "Course URL or 'Available on [Platform]'"
    }}
  ],
  "suggested_order": [
    "Course 1 name",
    "Course 2 name",
    "Course 3 name"
  ]
}}

**Rules:**
- Only return valid JSON, no markdown, no headings.
- Use double quotes `"` around all keys and string values.
- Ensure the JSON is syntactically correct (ready for `json.loads()`).
- If a field is missing, use an empty string "" or empty array [].
- Only give those courses which relevance_score more than 75


rs   rn   r   ro   zgoal and missing skill setr   )
r   r   r   r   r   r   r   r   r   r#   r   r   r   "recommend_offline_courses_problemsX  s(   F
r   c                 C   s  | r|st dtddgdd}tg ddd}tdd	d
}| }|}||B }||d}	||B }
|||d}|
|}||	}|j}|j}|dd }|dd }t|}td t| td t|}td t| |	dg }|	dd}|	dd}|	dg }|p|}t
|trdd |dD }nt
|trtdd |D rdd |D }n|}d||||di}td ttj|dd  |S )!Nr   r   r   aE  
You are a professional learning and development advisor.

Given the user's business problem , and their identified missing skills, output the recommendation report in **STRICT JSON FORMAT**.

### JSON Output Format:
Problem:
{{
  "problemTtile": "string",
  "course_recommendations_online": [
    {{
      "platform": "Platform name",
      "course_name": "Course title",
      "level": "Beginner / Intermediate / Advanced",
      "why_recommended": "Reason why the course is useful",
      "relevance_score": integer (0-100),
      "link": "Course URL or 'Available on [Platform]'"
    }}
  ],
  "suggested_order": [
    "Course 1 name",
    "Course 2 name",
    "Course 3 name"
  ]
}}

**Rules:**
- Only return valid JSON, no markdown, no headings.
- Use double quotes `"` around all keys and string values.
- Ensure the JSON is syntactically correct (ready for `json.loads()`).
- If a field is missing, use an empty string "" or empty array [].
- Only give those courses which relevance_score more than 75

---

### Inputs:

Goal / Problem:
{problem}

Missing Skills:
{missing_skills_str}
rs   r   a  
You are a professional learning and development advisor.

You are given:
- A business problem
- A list of missing skills
- A database of available courses (with name and description)

### Business Goal:
{problem}

### Missing Skills:
{missing_skills_str}

### Available Courses:
{course_data_json}

Your task is to:
1. Evaluate each course for how well it helps achieve the goal and address the missing skills.
2. Select the most relevant courses (maximum 5).
3. For each course, return ONLY the following fields:
   - "course_name": string
   - "course_id" : string
   - "reason_to_recommend": string
   - "relevance_score": integer (0-100)

Don't give any extra text . Just return JSON Output.
Here is the pydantic class to validate the output that you give. Make sure the check always passes.

class SimpleOfflineCourseRecommendation(BaseModel):
    
    class SimpleOfflineCourseRecommendation(BaseModel):
    
    ### JSON Output Format:
Problem:
{{
  "problemTtile": "string",
  "missing_skills": ["list", "of", "skills"],
  "course_recommendations_offline": [
    {{
      
      "course_name": "Course title",
      "course_id" : Course ID from course_data_json,
      "reason_to_recommend": "Reason why the course is useful",
      "relevance_score": integer (0-100),
      
    }}
  ],
  "suggested_order": [
    "Course 1 name",
    "Course 2 name",
    "Course 3 name"
  ]
}}

**Rules:**
- Only return valid JSON, no markdown, no headings.
- Use double quotes `"` around all keys and string values.
- Ensure the JSON is syntactically correct (ready for `json.loads()`).
- If a field is missing, use an empty string "" or empty array [].
- Only give those courses which relevance_score more than 75


rn   r   ro   r   ```json```zc=============================================================================Offlieneeee Prob Startza=============================================================================Offlieneeee Prob EndzP--------------------------------------------------------------------------------course_recommendations_offlineproblemtitler   problemTitlecourse_recommendations_onlinec                 S   rz   r   r_   r`   r   r   r   r:   u  r{   z=recommend_online_offline_courses_problems.<locals>.<listcomp>rc   c                 s       | ]}t |tV  qd S Nrf   rJ   r3   r   r   r   r   	<genexpr>v      z<recommend_online_offline_courses_problems.<locals>.<genexpr>c                 S      g | ]	}|D ]}|qqS r   r   r3   sublistra   r   r   r   r:   x  re   Problem)r   r   r   r   zB+=================================================================   rC   r)   r   r   r}   r~   rI   r&   r'   r   getrf   r   rg   rJ   allrQ   )r   r   r   r   r   r   r   r   r   input_data_onlineoffline_course_extraction_chaininput_data_offlinerecommendations_offlinerecommendations_onlinerecommendations_offline_data1recommendations_online_data1recommendations_offline_data2recommendations_online_data2recommendations_offline_datarecommendations_online_datar   problem_title_offlineproblem_title_onliner   final_problem_titlemissing_skills_listfinal_outputr   r   r   )recommend_online_offline_courses_problems  st   /E





r   c                 C   s  | r|st dtddgdd}tg ddd}tdd	d
}| }|}||B }||d}	||B }
|||d}|
|}||	}|j}|j}|dd }|dd }t|}td t| td t|}|	dg }|	dd}|	di }|	dd}|	dg }|p|}t
|trdd |dD }nt
|trtdd |D rdd |D }n|}d||||di}ttj|dd |S )Nr   r   r   a  
You are a professional learning and development advisor.

Given the user's business goal , and their identified missing skills, output the recommendation report in **STRICT JSON FORMAT**.

### JSON Output Format:

{{
Goal:{{
  "goalTitle": "string",
  "course_recommendations_online": [
    {{
      "platform": "Platform name",
      "course_name": "Course title",
      "level": "Beginner / Intermediate / Advanced",
      "why_recommended": "Reason why the course is useful",
      "relevance_score": integer (0-100),
      "link": "Course URL or 'Available on [Platform]'"
    }}
  ]
  
  }}
}}

**Rules:**
- Only return valid JSON, no markdown, no headings.
- Use double quotes `"` around all keys and string values.
- Ensure the JSON is syntactically correct (ready for `json.loads()`).
- If a field is missing, use an empty string "" or empty array [].
- Only give those courses which relevance_score more than 75

---

### Inputs:

Goal / Problem:
{goal}

Missing Skills:
{missing_skills_str}
rs   r   ak  
You are a professional learning and development advisor.

You are given:
- A business goal
- A list of missing skills
- A database of available courses (with name and description)

### Business Goal:
{goal}

### Missing Skills:
{missing_skills_str}

### Available Courses:
{course_data_json}

Your task is to:
1. Evaluate each course for how well it helps achieve the goal and address the missing skills.
2. Select the most relevant courses (maximum 5).
3. For each course, return ONLY the following fields:
   - "course_name": string
   - "course_id" : string
   - "reason_to_recommend": string
   - "relevance_score": integer (0-100)

Don't give any extra text . Just return JSON Output.
Here is the JSON class to validate the output that you give. Make sure the check always passes.

class SimpleOfflineCourseRecommendation(BaseModel):
    
    ### JSON Output Format:

{{
Goal:{{
  "goaltitle": "string",
  "course_recommendations_offline": [
    {{
      
      "course_name": "Course title",
      "course_id" : Course ID from course_data_json,
      "why_recommended": "Reason why the course is useful",
      "relevance_score": integer (0-100),
      "link": "Course URL or 'Available on [Platform]'"
    }}
  ],
  "suggested_order": [
    "Course 1 name",
    "Course 2 name",
    "Course 3 name"
  ]
  }}
}}

**Rules:**
- Only return valid JSON, no markdown, no headings.
- Use double quotes `"` around all keys and string values.
- Ensure the JSON is syntactically correct (ready for `json.loads()`).
- If a field is missing, use an empty string "" or empty array [].
- Only give those courses which relevance_score more than 75


rn   r   ro   r   r   r   zd=============================================================================Offlieneeee Goal Start za=============================================================================Offlieneeee Goal Endr   	goaltitler   Goal	goalTitler   c                 S   rz   r   r_   r`   r   r   r   r:   F  r{   z9recommend_online_offline_courses_goal.<locals>.<listcomp>rc   c                 s   r   r   r   r   r   r   r   r   G  r   z8recommend_online_offline_courses_goal.<locals>.<genexpr>c                 S   r   r   r   r   r   r   r   r:   I  re   r   r   r   r   r   rC   r   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   goal_title_offlinegoal_data_onlinegoal_title_onliner   final_goal_titler   r   r   r   r   %recommend_online_offline_courses_goal  sp   -C





r   c                 C   s  | r|st dtddgdd}tg ddd}tdd	d
}| }|}||B }||d}	||B }
|||d}|
|}||	}|j}|j}td t| |dd }|dd }td t| t|}t|}|	dg }|	dd}|	di }|	dd}|	dg }|p|}t
|trdd |dD }nt
|trtdd |D rdd |D }n|}d||||di}ttj|dd |S )Nr   r   r   a  
You are a professional learning and development advisor.

Given the user's business goals , and their identified missing problems, output the recommendation report in **STRICT JSON FORMAT**.

### JSON Output Format:

{{
Problem:{{
  "problemTitle": "string",
  "course_recommendations_online": [
    {{
      "platform": "Platform name",
      "course_name": "Course title",
      "level": "Beginner / Intermediate / Advanced",
      "why_recommended": "Reason why the course is useful",
      "relevance_score": integer (0-100),
      "link": "Course URL or 'Available on [Platform]'"
    }}
  ]
  
  }}
}}

**Rules:**
- Only return valid JSON, no markdown, no headings.
- Use double quotes `"` around all keys and string values.
- Ensure the JSON is syntactically correct (ready for `json.loads()`).
- If a field is missing, use an empty string "" or empty array [].
- Only give those courses which relevance_score more than 75

---

### Inputs:

Problem:
{problem}

Missing Skills:
{missing_skills_str}
rs   r   a5  
You are a professional learning and development advisor.

You are given:
- A business problem
- A list of missing skills
- A database of available courses (with name and description)

### Business Problem:
{problem}

### Missing Skills:
{missing_skills_str}

### Available Courses:
{course_data_json}

Your task is to:
1. Evaluate each course for how well it helps achieve the problem and address the missing skills.
2. Select the most relevant courses (maximum 5).
3. For each course, return ONLY the following fields:
   - "course_name": string
   - "reason_to_recommend": string
   - "relevance_score": integer (0-100)

Don't give any extra text . Just return JSON Output.
Here is the JSON class to validate the output that you give. Make sure the check always passes.

class SimpleOfflineCourseRecommendation(BaseModel):
    
    ### JSON Output Format:

{{
problem:{{
  "problemtitle": "string",
  "course_recommendations_offline": [
    {{
      
      "course_name": "Course title",
      
      "why_recommended": "Reason why the course is useful",
      "relevance_score": integer (0-100),
      "link": "Course URL or 'Available on [Platform]'"
    }}
  ],
  "suggested_order": [
    "Course 1 name",
    "Course 2 name",
    "Course 3 name"
  ]
  }}
}}

**Rules:**
- Only return valid JSON, no markdown, no headings.
- Use double quotes `"` around all keys and string values.
- Ensure the JSON is syntactically correct (ready for `json.loads()`).
- If a field is missing, use an empty string "" or empty array [].
- Only give those courses which relevance_score more than 75


rn   r   ro   r   r   r   r   r   r   r   r   r   r   c                 S   rz   r   r_   r`   r   r   r   r:     r{   z>recommend_online_offline_courses_problems1.<locals>.<listcomp>rc   c                 s   r   r   r   r   r   r   r   r     r   z=recommend_online_offline_courses_problems1.<locals>.<genexpr>c                 S   r   r   r   r   r   r   r   r:     re   r   r   r   rC   )r)   r   r   r}   r~   r   rI   r&   r'   r   rf   r   rg   rJ   r   rQ   )r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   *recommend_online_offline_courses_problems1\  sr   -B





r   __main__8gsk_igZbGeSv0MAqutmjrX9HWGdyb3FYc1U6fPEfvHFdLNFytjmyPGUHzOIncrease sales in the new Southeast Asia market by 20% in the next fiscal year.z)Lack of effective internal communication.zUserSkillDataIB.xlsxcompetency_namezCourseDataIB.xlsxr0   short_descriptionlms_course_idjson_outputr    Fr   )ensure_asciirD   r=   rr<   SDASDASDASDADz'Required Skills for Goals and Problems:r   zgoal:   zproblem:	   ")r   r   c                 C   s   g | ]}|d  qS )r   r   )r3   analysisr   r   r   r:     r{   r:   StartStart2)Qr&   retypingr   r   pandasrE   langchain_groqr   langchain_ollamar   langchain_core.promptsr   langchain.chainsr   langchain.output_parsersr   langchain_core.pydantic_v1r	   r
   r   r   r   r   r   r"   r   r.   r]   rl   r   r   r   r   r   r   r   r   r   r   r   r   groq_api_keybusiness_goalsbusiness_problemsrR   rS   rT   courses_columnr7   r8   r   r   rf   r'   course_datarQ   r   rO   floadr[   r   r<   courses_datar   required_skills_problemskill_gap_analysis_problemtyper   r   keyskeyrH   r   rI   goal_problem_dictvaluesall_missing_skills_problemabcxyzr   r   r   r   <module>   s    
0==hjge Z G 
H






