
    hIW              	       x   S SK r S SKrS SKrS SKrS SKrS SKrS SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKrS SKJr  S SK
Jr  S SKJrJr  S S	KJr  S S
KJrJrJrJr  S SKJr  S SKJr  S SK J!r!J"r"  S SK#J$r$J%r%J&r&  S SK'J(r(  S SK)J*r*  S SK+r+Sr,Sr-S r.S*S jr/S SKrS SKrS r0S r1S r2\3S:X  a  Sr,Sr4Sr5Sr6/ SQ/ SQ/ SQ/ SQ/ S Q/ S!QS"S#// S$QS%.r7/ SQ/ SQ/ SQ/ SQ/ S Q/ S!Q/ S$QS&.r8\Rr                  " \85      r:\;" S'5        \;" \:5        \;" S(5        \1" \5\6\:S)9u  r<r=\;" \=5        \;" \<5        \;" \>" \<5      5        gg)+    N)OllamaEmbeddings)FAISS)ChatPromptTemplate)AsyncWebCrawler)ChatGroq)PromptTemplate)StrOutputParserPydanticOutputParser)RunnablePassthrough)PyPDFLoader
TextLoaderDocx2txtLoaderUnstructuredPowerPointLoader)	PdfReader)SemanticChunker)	BaseModelField)ListOptionalDict)urlparse)
ChatOllama8gsk_CEh3itIpUAkEkEKsUDqVWGdyb3FYoTjqmXNTBHOSxJFK3obGTzXZznomic-embed-textc                    [        S[        SS9n/ nU HW  nUR                  SS5      nUR                  SS5      nU(       a  UR                  U SU 35        MF  UR                  U5        MY     SR	                  U5      n[        S	S
/SS9nUR                  U R                  SS5      R                  SS5      UR                  SS5      R                  SS5      S9n	 UR                  U	5      n
U
R                  n[        SU5        [        U5      nUc  gU
R                  S   S   nX4$ ! [         a  n[        SU 35         S nAgS nAff = f)Nr   llama-3.3-70b-versatiletemperaturegroq_api_key
model_namename description: 
	skills_dbjob_profilesa
  
        You are an expert in skill-to-job-profile mapping. Your task is to validate,refine  and map skills to job profiles to ensure accuracy, completeness, and clarity.

        ### Input:
         

        ### Available Skills:
        {skills_db}

        ### Job Profiles (with descriptions where available):
        {job_profiles}

        ### Output Format:
        {{  
        "Job Profile 1": ["Skill 1", "Skill 2", "Skill 3"],  
        "Job Profile 2": ["Skill 4", "Skill 5"],  
        "Job Profile 3": ["Skill 6", "Skill 7", "Skill 8"]  
        }}  

        ### Enhanced Mapping Guidelines:
        1. **Leverage Job Descriptions:**  
        - Use the provided job descriptions to better understand the role requirements.  
        - Map skills that align with the specific responsibilities and expertise mentioned in descriptions.  
        
        2. **Ensure Relevance:**  
        - Verify that each skill is appropriately mapped to the correct job profile(s) based on both the role name and description.  
        - Remove any incorrectly assigned skills.  
        
        3. **Check for Completeness:**  
        - Identify and add missing skills relevant to each job profile based on the description context.  
        - For profiles without descriptions, use industry-standard expectations for that role.  
        
        4. **Refine Overlapping Skills:**  
        - If a skill belongs to multiple job profiles, ensure it is correctly included in each where relevant.  
        - Consider the description context to determine skill relevance.  
        
        5. **Improve Consistency & Clarity:**  
        - Standardize skill naming to avoid duplicates with different names.  
        - Use precise and industry-recognized terminology.  
        
        6. **Handle Profiles with/without Descriptions:**  
        - For profiles with descriptions: prioritize skills that match the described responsibilities.  
        - For profiles without descriptions: use standard industry expectations for that role title.

        7. **Include Soft Skills Where Relevant:**
        - Evaluate the job description for behavioral, interpersonal, or communication requirements.
        - Map relevant soft skills such as Communication, Problem Solving, Teamwork, Leadership, or Adaptability when implied or directly stated
        - Do not exclude soft skills if they play a crucial role in client-facing or collaborative roles.
        
        7. **Response Format:**  
        - **ONLY return the JSON object without any explanations, comments, or additional text.**  
        - **DO NOT wrap the JSON in code blocks (```json ... ```).**  
        - Use the exact job profile names as provided in the input.
        input_variablestemplate{{{}}})r%   r&   Raw API response:Nr   token_usagetotal_tokens*An error occurred during chat invocation: )r   GROQ_API_KEYgetappendjoinr   formatreplaceinvokecontentprintextract_json_from_responseresponse_metadata	Exception)r%   job_profiles_datachatformatted_job_profilesprofiler    r"   job_profiles_textsystem_promptformatted_promptoutputoutskill_to_JobProfile_mappingtoken_consumedes                  N/var/www/eduai.edurigo.com/generate_skill_and_map/production/jobProfile_map.pymap_skills_to_jobProfilerL      sp    IbcD  ${{62&kk-4"))TF"[M*BC"))$/ % 		"89 #$n558Mv %++##C.66sDA&..sD9AA#tL , 
-.nn!3'&@&E#&.  11-@P '66	  :1#>?s   7D* D* *
E4EEc                     [        SSS9n[        SS/SS9nUR                  XS9n UR                  U5      nUR                  S	   nUR
                  n	X4$ ! [         a  n
[        S
U
 35         S n
A
gS n
A
ff = f)Nhttp://127.0.0.1:11434	llama3:8bbase_urlmodelr%   
JobProfileay  
        You are an expert in skill-to-Job Profile mapping. Your task is to analyze a given set of skills and map them to the most appropriate JobProfile.

        ### Input Skills:
        {skills_db}

        ### Designations:
        {JobProfile}

        ### Output Format:
        {{
        "JobProfile 1": ["Skill 1", "Skill 2", "Skill 3"],
        "JobProfile 2": ["Skill 4", "Skill 5"],
        "JobProfile 3": ["Skill 6", "Skill 7", "Skill 8"]
        }}

        ### Notes:
        - Ensure that each skill is mapped only to the most relevant JobProfile(s).
        - If a skill fits multiple JobProfile, include it in both.
        - Use clear and concise mappings.
        - Respond only with the JSON object in the specified format, without any additional text.
        - If you found no skills for some JobProfile check does JobProfile at last one more time

        ### Instructions:
        - **Respond only with the JSON object in the specified format.**
        - **Do not include any additional text, explanations, or code fences (e.g., ```json).**
        - **Ensure that the JSON is properly formatted and valid.**
        r'   )r%   rS   output_tokensr2   r/   )r   r   r7   r9   usage_metadatar:   r>   r;   )r%   rS   r   r   r@   rD   rE   rF   r1   skill_to_jobProfile_mappingrJ   s              rK   ,map_skills_to_jobProfile_without_descriptionrW      s    
 /D #$l3MB %++i+W-.,,_=&,nn#
 '44	  :1#>?s   ,A 
A8 A33A8c                      U R                  S5      nU R                  S5      nUS:w  a#  US:w  a  XUS-    n[        R                  " U5      $ [	        S5        g ! [
         a  n[	        SU 35         S nAg S nAff = f)Nr*   r,      z#Could not find JSON object in text.z"Error extracting or parsing JSON: )findrfindjsonloadsr;   r>   )textstartendjson_strrJ   s        rK   r<   r<      sz    		#jjoB;3"9#'*H::h''78 21#67s   A
A A 
A;#A66A;c                    [        S[        SS9n[        R                  " USS9n/ nU HW  nUR	                  SS5      nUR	                  SS5      nU(       a  UR                  U S	U 35        MF  UR                  U5        MY     S
R                  U5      n	[        / SQSS9n
U
R                  U R                  SS5      R                  SS5      U	R                  SS5      R                  SS5      US9n UR                  U5      nUR                  n[        SU5        [        U5      nUc  gUR                  S   S   nX4$ ! [         a  n[        SU 35         S nAgS nAff = f)Nr   r   r   Fensure_asciir    r!   r"   r#   r$   )r%   r&   mapped_skillsaw	  
        You are an expert in skill-to-job-profile mapping. Your task is to validate and refine a given mapping of skills to job profiles to ensure accuracy, completeness, and clarity.

        ### Input:
        - **Existing Mapped Skills** (JSON format):  
        {mapped_skills}  

        ### Available Skills:
        {skills_db}

        ### Job Profiles (with descriptions where available):
        {job_profiles}

        ### Output Format:
        {{  
        "Job Profile 1": ["Skill 1", "Skill 2", "Skill 3"],  
        "Job Profile 2": ["Skill 4", "Skill 5"],  
        "Job Profile 3": ["Skill 6", "Skill 7", "Skill 8"]  
        }}  

        ### Enhanced Mapping Guidelines:
        1. **Leverage Job Descriptions:**  
        - Use the provided job descriptions to better understand the role requirements.  
        - Map skills that align with the specific responsibilities and expertise mentioned in descriptions.  
        
        2. **Ensure Relevance:**  
        - Verify that each skill is appropriately mapped to the correct job profile(s) based on both the role name and description.  
        - Remove any incorrectly assigned skills.  
        
        3. **Check for Completeness:**  
        - Identify and add missing skills relevant to each job profile based on the description context.  
        - For profiles without descriptions, use industry-standard expectations for that role.  
        
        4. **Refine Overlapping Skills:**  
        - If a skill belongs to multiple job profiles, ensure it is correctly included in each where relevant.  
        - Consider the description context to determine skill relevance.  
        
        5. **Improve Consistency & Clarity:**  
        - Standardize skill naming to avoid duplicates with different names.  
        - Use precise and industry-recognized terminology.  
        
        6. **Handle Profiles with/without Descriptions:**  
        - For profiles with descriptions: prioritize skills that match the described responsibilities.  
        - For profiles without descriptions: use standard industry expectations for that role title.
        
        7. **Response Format:**  
        - **ONLY return the JSON object without any explanations, comments, or additional text.**  
        - **DO NOT wrap the JSON in code blocks (```json ... ```).**  
        - Use the exact job profile names as provided in the input.
        r'   r*   r+   r,   r-   r.   r/   r0   r1   r2   )r   r3   r]   dumpsr4   r5   r6   r   r7   r8   r9   r:   r;   r<   r=   r>   )r%   r?   rf   r@   formatted_mapped_skillsrA   rB   r    r"   rC   rD   rE   rF   rG   rH   rI   rJ   s                    rK   "map_skills_to_jobProfile_non_emptyri      s    IbcD #jjUK  ${{62&kk-4"))TF"[M*BC"))$/ % 		"89 #F14Mn %++##C.66sDA&..sD9AA#tL- , -.nn!3'&@&E#&.  11-@P '66	  :1#>?s   37E  +E   
E"
EE"c                    [        SSS9n[        R                  " USS9n[        / SQSS9nUR	                  U R                  S	S
5      R                  SS5      UR                  S	S
5      R                  SS5      US9n UR                  U5      nUR                  n[        SU5        [        U5      n	U	c  gUR                  S   n
X4$ ! [         a  n[        SU 35         S nAgS nAff = f)NrN   rO   rP   Frd   r%   rS   rf   a  
        You are an expert in skill-to-JobProfile mapping. Your task is to validate and refine a given mapping of skills to JobProfile to ensure accuracy, completeness, and clarity.
    
        ### Input:
        - **Existing Mapped Skills** (JSON format):  
        {mapped_skills}  

        ### Input Skills:
        {skills_db}

        ### JobProfile:
        {JobProfile}

        ### Output Format:
        {{  
        "JobProfile 1": ["Skill 1", "Skill 2", "Skill 3"],  
        "JobProfile 2": ["Skill 4", "Skill 5"],  
        "JobProfile 3": ["Skill 6", "Skill 7", "Skill 8"]  
        }}  

        ### Validation & Enhancement Guidelines:
        1. **Ensure Relevance:**  
        - Verify that each skill is appropriately mapped to the correct JobProfile(s).  
        - Remove any incorrectly assigned skills.  
        2. **Check for Completeness:**  
        - Identify and add missing skills relevant to each JobProfile.  
        - Ensure no important skills are overlooked.  
        3. **Refine Overlapping Skills:**  
        - If a skill belongs to multiple JobProfile, ensure it is correctly included in each.  
        - Avoid redundant mappings unless justified.  
        4. **Improve Consistency & Clarity:**  
        - Standardize skill naming to avoid duplicates with different names.  
        - Use precise and industry-recognized terminology.  
        5. **Handle Unmapped JobProfile:**  
        - If a JobProfile lacks sufficient mapped skills, reevaluate and attempt to match relevant ones.  
        6. **Respond in Valid JSON Format:**  
        - **ONLY return the JSON object without any explanations, comments, or additional text.**  
        - **DO NOT wrap the JSON in code blocks (```json ... ```).**  
        r'   r*   r+   r,   r-   r.   r/   rT   r2   )r   r]   rg   r   r7   r8   r9   r:   r;   r<   rU   r>   )r%   rS   rf   r@   rh   rD   rE   rF   rG   rH   rI   rJ   s               rK   6map_skills_to_jobProfile_non_empty_without_descriptionrl   G  s    /D #jjUK #D&)MX %++##C.66sDA%%c4088dC- , 
-.nn!3'&@&E#&...? '66	  :1#>?s   >7C 6C 
C*C%%C*__main__Infrastructurea}  
      Budgeting,
      Cost Estimation,
    
      Civil Engineering,
      Structural Analysis,
   
      AutoCAD,
      Revit,
    
      Communication,
      Leadership,
      Teamwork,
      Urban Design,
      Water Supply and Distribution
      , SQL, C++ , Management, Housekeeping Management,Front Desk Management,Complaint Handling,Recruitment,Training & Development
    zZ

        HR, Developer, Manager, Planner,CEO, Infrastructure Deverloper
        
        )zTime ManagementzDecision MakingIndustry TrendsSector ExpertiseBusiness AcumenStakeholder CommunicationRisk ManagementzAgile Methodologies
LeadershipTeamworkAdaptability)Data EncryptionIncident ResponseCloud ArchitectureCloud MigrationCloud MonitoringNetwork SecurityProgramming LanguagesPy)	NegotiationEmpathyrt   rs   rq   rp   ro   rr   
Creativity)	r   rp   r   rt   rr   rs   rq   ro   r   )r~   r}   Software TestingVersion Control)r|   r~   r}   rw   rx   Communicationrr   )r   r   r}   rz   r{   r~   ry   )ManagerEngineerCEO
CO-Founder	DeveloperSenior DeveloperzHR HeadProduct Engineer)r   r   r   r   r   r   r   OPOLKLrk   )zmixtral-8x7b-32768r   )?ostimerandomrer]   requestslangchain_community.embeddingsr    langchain_community.vectorstoresr   langchain_core.promptsr   crawl4air   asynciolangchain_groqr   r   langchain_core.output_parsersr	   r
   langchain_core.runnablesr   $langchain_community.document_loadersr   r   r   r   PyPDF2r   $langchain_experimental.text_splitterr   pydanticr   r   typingr   r   r   urllib.parser   langchain_ollamar   shutilr3   OLLAMA_MODELrL   rW   r<   ri   rl   __name__industryskillsetrS   mappedrf   rg   	json_datar;   
skill_treerI   type     rK   <module>r      su   	   	   ; 2 5 $  # 1 O 8 v v  @ % ' ' ! ' I!h7Z95|  	"f7RL7f zMLHH$J	

 	#HFV	

HMX 

=)I	%L	)	%L
 "Dxdn  @I  "JJ~ 
.	*	$z
A r   