
    ia                     b    d dl mZ d dlmZ d dlmZ d dlZd dlmZ d dl	Z	d dl
Z
 G d de      Zy)    )render)APIView)ResponseNstatusc                   "    e Zd ZdedefdZd Zy)
PromptViewtextreturnc                     t        j                  dd|t         j                        j                         }t	        j
                  |      S )Nz```json|``` )flags)resub
IGNORECASEstripjsonloads)selfr
   cleaneds      &/var/www/auto_recruiter/arllm/views.pyextract_json_from_llmz PromptView.extract_json_from_llm   s2    &&TGMMOzz'""    c                 F   |j                   }|j                  dd      }d| d}t        d|       t        j                  d|ddd	
      }|r:| j                  |d         }t        |       t        |t        j                        S t        dt        j                        S )Npromptr   a  Role:
        Act as an Expert Technical Recruiter and Data Parsing AI.
        Input Data:
        I will provide you with the raw text from an EMAIL BODY or PDF or Word, which containing an  unstructured Job Description (JD).
        Your Task:
        Analyze: Read the text and identify key job details. Ignore email metadata (signatures, "Sent from my iPhone", greetings, and thread headers).
        Semantic Extraction & Tuning:
        Interpret Meaning: If the email says, "looking for a rockstar in Python," interpret this as "Expert proficiency in Python" under skills.
        Standardize: Expand only universal recruitment abbreviations (e.g., "wfh" -> "Remote"). Strictly preserve Client Acronyms, Project Codes, and Proper Nouns exactly as written (e.g., keep "LTA", "JPMC", "DBS" as is; do not expand them).
        Categorize: Semantically distinguish between what is "Required" (Must have) vs. "Preferred" (Nice to have/Bonus).
        Refine: Clean up the grammar and tone of the extracted text to be professional and suitable for a formal JD.
        Audit Transformation: Track every specific change made, including which input headers were mapped to which output keys.
        Format: Output the data strictly into the specific JSON format defined below.
        Rules for Extraction:
        If a field is not mentioned in the email, return "Not Specified".
        jd_date: Extract the date from the email text if present, otherwise use "Current".
        job_title : Retain the given title in the JD
        ai_title : Tuned and Generated Title from the JD
        job_type: type of Job in the JD example Contract or Employee or etc..
        job_id: reference for the JD or JD identifier
        duration : Duration of the Job requirement in months, if not specified use 24+ months
        about_company: If not explicitly stated, try to infer the company name/domain from the context, or leave as "Not Specified".
        no_of_open_positions: If not explicitly stated, give default value as 1
        primary_skills: highly important skills required for the JD
        secondary_skills: technical skills exclude the primary skills
        domain_requirements: must specified as domain skills in the JD
        Specific Instruction for "changes" field:
        You must generate a semicolon-separated string listing THREE types of changes:
        MAPPING: Which input section was mapped to which JSON key (e.g., "Mapped 'Key Responsibilities' to 'responsibilities'").
        CORRECTION: Content fixes (e.g., "Corrected '58 years' to '5-8 Years'").
        INFERENCE: Data derived from context (e.g., "Inferred 'LTA' is the Domain/Client").
        Output Format:
        Return ONLY a single valid JSON object. Do not include any conversational text.
        ```json
            {
            "ai_title" : "String",
            "job_title" : "String",
            "job_type" : "String",
            "job_id" : "String",
            "about_company"  : "String",
            "no_of_open_positions" : "String",
            "job_summary"  : "String",
            "responsibilities" : "String",
            "domain_requirements" : "String",
            "certification_requirements" : "String",
            "security_clearance_requirements" : "String",
            "years_of_experience" : "String",
            "duration" : "String",
            "onsite_job" : "String",
            "job_location" : "String",
            "salary_range" : "String",
            "required_qualifications" : "String",
            "preferred_qualifications" : "String",
            "working_hours" : "String",
            "benefits" : "String",
            "requirement_priority" : "String",
            "search_pattern" : {
                "job_title": "String",
                "location": "String",
                "education": ["String"],
                "primary_skills": ["String"],
                "secondary_skills": ["String"],
                "soft_skills": ["String"],
                "tools_and_frameworks": ["String"],
                "salary_range": "String",
                "keywords": ["String"],
                "domain_requirements": ["String"]
            },
            "changes": "String",
            }
            ```
        Input Email Body:
            {z
}
        zdata: zdeepseek-r1:7b   i   )
num_threadnum_ctx)modelr   optionsresponser   zError in Prompt response)
datagetprintollamagenerater   r   r   HTTP_201_CREATEDHTTP_400_BAD_REQUEST)	r   requestargskwargsr"   prompt_data
prompt_strprompt_responseresponse_datas	            r   postzPromptView.post   s    ||hhx,HP m 	QI
T 	x$ //!

  66z7RTM-  M&2I2IJJ 26;V;VWWr   N)__name__
__module____qualname__strdictr   r0    r   r   r	   r	      s    ## #$ #
`Xr   r	   )django.shortcutsr   rest_framework.viewsr   rest_framework.responser   r%   rest_frameworkr   r   r   r	   r6   r   r   <module>r;      s,    # ) ,  ! 	 fX fXr   