Spaces:
Running
Running
Arjun Singh commited on
Commit ·
c0a9026
1
Parent(s): 2754acf
Added self-correcting behavior to the AI Recruiting Agent to improve accuracy in hiring recommendations.
Browse files
app.py
CHANGED
|
@@ -172,6 +172,37 @@ def verify_analysis(analysis_text: str, source_documents: List[str]) -> Dict:
|
|
| 172 |
"verification_result": result
|
| 173 |
}
|
| 174 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 175 |
|
| 176 |
|
| 177 |
def analyze_candidates(job_description: str) -> str:
|
|
@@ -360,36 +391,36 @@ def analyze_candidates(job_description: str) -> str:
|
|
| 360 |
"job_description": job_description
|
| 361 |
})
|
| 362 |
|
| 363 |
-
#
|
| 364 |
-
#
|
| 365 |
-
|
| 366 |
-
|
| 367 |
-
|
| 368 |
-
|
| 369 |
-
|
| 370 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 371 |
|
| 372 |
-
# Add verification warnings if factuality score <
|
| 373 |
verification_notes = ""
|
| 374 |
-
|
| 375 |
-
|
| 376 |
-
if culture_verification["factuality_score"] <= 1 or skills_verification["factuality_score"] <= 1:
|
| 377 |
verification_notes = "\n\n🔍 FACT CHECK RESULTS:"
|
| 378 |
-
|
| 379 |
-
|
| 380 |
-
if culture_verification.get("unverified_claims"):
|
| 381 |
verification_notes += f"\n\nCULTURE ANALYSIS - Unverified claims:"
|
| 382 |
for claim in culture_verification["unverified_claims"][:3]:
|
| 383 |
verification_notes += f"\n✗ {claim}"
|
| 384 |
-
|
| 385 |
-
if skills_verification
|
| 386 |
verification_notes += f"\n\nSKILLS ANALYSIS - Unverified claims:"
|
| 387 |
for claim in skills_verification["unverified_claims"][:3]:
|
| 388 |
verification_notes += f"\n✗ {claim}"
|
| 389 |
-
else:
|
| 390 |
-
print("DEBUG - No verification notes added")
|
| 391 |
-
|
| 392 |
-
print(f"DEBUG - Final verification_notes: '{verification_notes}'")
|
| 393 |
|
| 394 |
# Append the analysis for this candidate to the consolidated analyses
|
| 395 |
consolidated_analyses.append(f"""
|
|
@@ -402,7 +433,7 @@ def analyze_candidates(job_description: str) -> str:
|
|
| 402 |
{skills_fit}
|
| 403 |
|
| 404 |
HIRING RECOMMENDATION:
|
| 405 |
-
{final_recommendation}{verification_notes}
|
| 406 |
|
| 407 |
----------------------------------------
|
| 408 |
""")
|
|
|
|
| 172 |
"verification_result": result
|
| 173 |
}
|
| 174 |
|
| 175 |
+
def self_correct_recommendation(original_recommendation: str, verification_issues: List[str], source_docs: List[str]) -> str:
|
| 176 |
+
"""Have LLM revise its recommendation based on verification feedback"""
|
| 177 |
+
correction_prompt = PromptTemplate(
|
| 178 |
+
input_variables=["original_rec", "issues", "source_docs"],
|
| 179 |
+
template="""
|
| 180 |
+
Your original hiring recommendation contained some unverified claims. Please revise it.
|
| 181 |
+
|
| 182 |
+
Original Recommendation:
|
| 183 |
+
{original_rec}
|
| 184 |
+
|
| 185 |
+
Verification Issues Found:
|
| 186 |
+
{issues}
|
| 187 |
+
|
| 188 |
+
Source Documents:
|
| 189 |
+
{source_docs}
|
| 190 |
+
|
| 191 |
+
Provide a REVISED recommendation that:
|
| 192 |
+
1. Removes or corrects unverified claims
|
| 193 |
+
2. Bases conclusions only on documented evidence
|
| 194 |
+
3. Maintains the same format and decision structure
|
| 195 |
+
|
| 196 |
+
REVISED HIRING RECOMMENDATION:
|
| 197 |
+
"""
|
| 198 |
+
)
|
| 199 |
+
|
| 200 |
+
chain = LLMChain(llm=llm, prompt=correction_prompt)
|
| 201 |
+
return chain.run({
|
| 202 |
+
"original_rec": original_recommendation,
|
| 203 |
+
"issues": "\n".join(verification_issues),
|
| 204 |
+
"source_docs": "\n---\n".join(source_docs)
|
| 205 |
+
})
|
| 206 |
|
| 207 |
|
| 208 |
def analyze_candidates(job_description: str) -> str:
|
|
|
|
| 391 |
"job_description": job_description
|
| 392 |
})
|
| 393 |
|
| 394 |
+
# Self-correction integration - INSERT HERE (after line 364)
|
| 395 |
+
# Collect all unverified claims for potential self-correction
|
| 396 |
+
all_issues = culture_verification["unverified_claims"] + skills_verification["unverified_claims"]
|
| 397 |
+
|
| 398 |
+
# Self-correct if verification scores are low AND there are actual issues
|
| 399 |
+
if (culture_verification["factuality_score"] < 0.95 or skills_verification["factuality_score"] < 0.95) and all_issues:
|
| 400 |
+
corrected_recommendation = self_correct_recommendation(
|
| 401 |
+
final_recommendation,
|
| 402 |
+
all_issues,
|
| 403 |
+
[resume_text, job_description, cultural_requirements]
|
| 404 |
+
)
|
| 405 |
+
final_recommendation = corrected_recommendation
|
| 406 |
+
revision_note = "\n\n🔄 RECOMMENDATION REVISED: Corrected based on verification feedback"
|
| 407 |
+
else:
|
| 408 |
+
revision_note = ""
|
| 409 |
|
| 410 |
+
# Add verification warnings if factuality score < 0.95
|
| 411 |
verification_notes = ""
|
| 412 |
+
if culture_verification["factuality_score"] < 0.95 or skills_verification["factuality_score"] < 0.95:
|
|
|
|
|
|
|
| 413 |
verification_notes = "\n\n🔍 FACT CHECK RESULTS:"
|
| 414 |
+
|
| 415 |
+
if culture_verification["unverified_claims"]:
|
|
|
|
| 416 |
verification_notes += f"\n\nCULTURE ANALYSIS - Unverified claims:"
|
| 417 |
for claim in culture_verification["unverified_claims"][:3]:
|
| 418 |
verification_notes += f"\n✗ {claim}"
|
| 419 |
+
|
| 420 |
+
if skills_verification["unverified_claims"]:
|
| 421 |
verification_notes += f"\n\nSKILLS ANALYSIS - Unverified claims:"
|
| 422 |
for claim in skills_verification["unverified_claims"][:3]:
|
| 423 |
verification_notes += f"\n✗ {claim}"
|
|
|
|
|
|
|
|
|
|
|
|
|
| 424 |
|
| 425 |
# Append the analysis for this candidate to the consolidated analyses
|
| 426 |
consolidated_analyses.append(f"""
|
|
|
|
| 433 |
{skills_fit}
|
| 434 |
|
| 435 |
HIRING RECOMMENDATION:
|
| 436 |
+
{final_recommendation}{revision_note}{verification_notes}
|
| 437 |
|
| 438 |
----------------------------------------
|
| 439 |
""")
|