Spaces:
Sleeping
Sleeping
Commit ·
a432ed7
1
Parent(s): 94cd6c9
Json Parser changed
Browse files- Process/change.py +28 -23
Process/change.py
CHANGED
|
@@ -8,6 +8,7 @@ from .response import get_response
|
|
| 8 |
# Set up logging
|
| 9 |
logger = logging.getLogger(__name__)
|
| 10 |
|
|
|
|
| 11 |
@csrf_exempt
|
| 12 |
def process_change(request):
|
| 13 |
logger.info("Change request received")
|
|
@@ -17,18 +18,18 @@ def process_change(request):
|
|
| 17 |
data = json.loads(request.body)
|
| 18 |
logger.debug("Request body parsed successfully")
|
| 19 |
|
| 20 |
-
user_id = data.get(
|
| 21 |
prompt = data.get("prompt")
|
| 22 |
-
content = data.get(
|
| 23 |
section = data.get("section")
|
| 24 |
-
job_description = data.get(
|
| 25 |
-
|
| 26 |
logger.debug(f"Request for user_id: {user_id}, section: {section}")
|
| 27 |
-
|
| 28 |
if not all([user_id, prompt, content]):
|
| 29 |
logger.warning("Missing required fields in request")
|
| 30 |
-
return JsonResponse({
|
| 31 |
-
|
| 32 |
# Customize processing approach based on section
|
| 33 |
logger.info(f"Customizing instructions for section: {section}")
|
| 34 |
section_specific_instruction = ""
|
|
@@ -36,10 +37,10 @@ def process_change(request):
|
|
| 36 |
section_specific_instruction = "Format achievements using the X-Y-Z method (e.g., 'Accomplished X as measured by Y, by doing Z'). Provide at least one compelling example that demonstrates measurable impact."
|
| 37 |
else:
|
| 38 |
section_specific_instruction = "Incorporate relevant keywords from the job description while avoiding generic buzzwords. Focus on specificity and concrete details that align with ATS screening requirements."
|
| 39 |
-
|
| 40 |
combined_prompt = f"Content: {content}\nJob Description: {job_description}\nTask: {prompt}"
|
| 41 |
|
| 42 |
-
system_instruction = """As an ATS resume optimizer, your primary task is to revise content to align with job requirements while maintaining absolute truthfulness. All accomplishments must be rewritten using the X-Y-Z method: 'Achieved X, as measured by Y, through Z.' Avoid using placeholders like 'Achieved X, as measured by Y, through Z,' and instead provide specific, quantifiable, and truthful details for every accomplishment. Limit each statement to a maximum of 35 words for clarity, precision, and ATS compatibility. Use language that highlights measurable results, impact, and relevance to the role. Include industry-specific keywords and technical terms where appropriate to enhance searchability.
|
| 43 |
|
| 44 |
Examples of the required format:
|
| 45 |
- 'Developed a Python script that improved audio transcription accuracy by 30% and reduced post-processing time by 35%.'
|
|
@@ -59,28 +60,32 @@ def process_change(request):
|
|
| 59 |
|
| 60 |
The final content must be highly ATS-optimized, prioritize measurable results wherever possible, and avoid vague or incomplete statements. Ensure all outputs are actionable, impactful, and tailored to the specific job description provided."""
|
| 61 |
|
| 62 |
-
|
| 63 |
-
|
| 64 |
# Combine system_instruction with section_specific_instruction
|
| 65 |
-
combined_system_instruction =
|
| 66 |
-
|
|
|
|
|
|
|
| 67 |
logger.info("Sending request to get_response function")
|
| 68 |
-
|
|
|
|
| 69 |
logger.info("Content modification completed successfully")
|
| 70 |
-
|
| 71 |
-
return JsonResponse(
|
| 72 |
-
|
| 73 |
-
|
| 74 |
-
|
| 75 |
-
|
|
|
|
|
|
|
|
|
|
| 76 |
except json.JSONDecodeError as e:
|
| 77 |
logger.error(f"Invalid JSON format: {e}")
|
| 78 |
-
return JsonResponse({
|
| 79 |
except Exception as e:
|
| 80 |
error_msg = f"Error in process_change: {e}"
|
| 81 |
logger.error(error_msg)
|
| 82 |
logger.debug(traceback.format_exc())
|
| 83 |
-
return JsonResponse({
|
| 84 |
else:
|
| 85 |
logger.warning(f"Unsupported method: {request.method}")
|
| 86 |
-
return JsonResponse({
|
|
|
|
| 8 |
# Set up logging
|
| 9 |
logger = logging.getLogger(__name__)
|
| 10 |
|
| 11 |
+
|
| 12 |
@csrf_exempt
|
| 13 |
def process_change(request):
|
| 14 |
logger.info("Change request received")
|
|
|
|
| 18 |
data = json.loads(request.body)
|
| 19 |
logger.debug("Request body parsed successfully")
|
| 20 |
|
| 21 |
+
user_id = data.get("user_id")
|
| 22 |
prompt = data.get("prompt")
|
| 23 |
+
content = data.get("content")
|
| 24 |
section = data.get("section")
|
| 25 |
+
job_description = data.get("job_description")
|
| 26 |
+
|
| 27 |
logger.debug(f"Request for user_id: {user_id}, section: {section}")
|
| 28 |
+
|
| 29 |
if not all([user_id, prompt, content]):
|
| 30 |
logger.warning("Missing required fields in request")
|
| 31 |
+
return JsonResponse({"error": "Missing required fields"}, status=400)
|
| 32 |
+
|
| 33 |
# Customize processing approach based on section
|
| 34 |
logger.info(f"Customizing instructions for section: {section}")
|
| 35 |
section_specific_instruction = ""
|
|
|
|
| 37 |
section_specific_instruction = "Format achievements using the X-Y-Z method (e.g., 'Accomplished X as measured by Y, by doing Z'). Provide at least one compelling example that demonstrates measurable impact."
|
| 38 |
else:
|
| 39 |
section_specific_instruction = "Incorporate relevant keywords from the job description while avoiding generic buzzwords. Focus on specificity and concrete details that align with ATS screening requirements."
|
| 40 |
+
|
| 41 |
combined_prompt = f"Content: {content}\nJob Description: {job_description}\nTask: {prompt}"
|
| 42 |
|
| 43 |
+
system_instruction = """As an ATS resume optimizer, your primary task is to revise content to align with job requirements while maintaining absolute truthfulness. All accomplishments must be rewritten using the X-Y-Z method: 'Achieved X, as measured by Y, through Z.' Avoid using placeholders like 'Achieved X, as measured by Y, through Z,' and instead provide specific, quantifiable, and truthful details for every accomplishment. Limit each statement to a maximum of 35 words for clarity and 20 words minimum, precision, and ATS compatibility. Use language that highlights measurable results, impact, and relevance to the role. Include industry-specific keywords and technical terms where appropriate to enhance searchability.
|
| 44 |
|
| 45 |
Examples of the required format:
|
| 46 |
- 'Developed a Python script that improved audio transcription accuracy by 30% and reduced post-processing time by 35%.'
|
|
|
|
| 60 |
|
| 61 |
The final content must be highly ATS-optimized, prioritize measurable results wherever possible, and avoid vague or incomplete statements. Ensure all outputs are actionable, impactful, and tailored to the specific job description provided."""
|
| 62 |
|
|
|
|
|
|
|
| 63 |
# Combine system_instruction with section_specific_instruction
|
| 64 |
+
combined_system_instruction = (
|
| 65 |
+
f"{system_instruction} {section_specific_instruction}"
|
| 66 |
+
)
|
| 67 |
+
|
| 68 |
logger.info("Sending request to get_response function")
|
| 69 |
+
response_str = get_response(combined_prompt, combined_system_instruction)
|
| 70 |
+
modified_content = json.loads(response_str)
|
| 71 |
logger.info("Content modification completed successfully")
|
| 72 |
+
|
| 73 |
+
return JsonResponse(
|
| 74 |
+
{
|
| 75 |
+
"user_id": user_id,
|
| 76 |
+
"modified_content": modified_content["modified_content"],
|
| 77 |
+
},
|
| 78 |
+
status=200,
|
| 79 |
+
)
|
| 80 |
+
|
| 81 |
except json.JSONDecodeError as e:
|
| 82 |
logger.error(f"Invalid JSON format: {e}")
|
| 83 |
+
return JsonResponse({"error": "Invalid JSON format"}, status=400)
|
| 84 |
except Exception as e:
|
| 85 |
error_msg = f"Error in process_change: {e}"
|
| 86 |
logger.error(error_msg)
|
| 87 |
logger.debug(traceback.format_exc())
|
| 88 |
+
return JsonResponse({"error": error_msg}, status=500)
|
| 89 |
else:
|
| 90 |
logger.warning(f"Unsupported method: {request.method}")
|
| 91 |
+
return JsonResponse({"error": "Only POST requests are allowed"}, status=405)
|