Spaces:
Runtime error
Runtime error
File size: 4,481 Bytes
5348e91 410face 209e20b 410face 5348e91 410face 7c82687 410face 5348e91 209e20b 5348e91 410face 7c82687 410face 5348e91 410face 5348e91 7c82687 5348e91 7c82687 209e20b 7c82687 209e20b 410face 7c82687 410face 209e20b 7c82687 209e20b 7c82687 209e20b 7c82687 209e20b 7c82687 209e20b 7c82687 5348e91 410face 7c82687 410face 5348e91 209e20b |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 |
# modules/llm_handler.py
import os
import config
import regex as re
from groq import Groq
from modules.web_search import search_for_example_answers
# Initialize the Groq client
client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
MODEL = "llama3-70b-8192" # Use the more powerful 70B model for detailed analysis
def generate_question(interview_type, document_text):
prompt = f"As an expert {interview_type} interviewer, ask one relevant, open-ended question based on this document:\n\n---\n{document_text}\n---"
try:
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": prompt}], model=MODEL
)
return chat_completion.choices[0].message.content
except Exception as e:
return f"Error generating question from API: {e}"
def evaluate_answer(question, answer):
# This new prompt demands a much higher level of detail
prompt = f"""
You are a meticulous and insightful interview coach. Your task is to provide a highly detailed evaluation of a candidate's answer.
**INTERVIEW QUESTION:**
"{question}"
---
**CANDIDATE'S ANSWER:**
"{answer}"
---
**YOUR TASK:**
Provide a detailed, multi-part evaluation. You MUST include scores and written analysis for each section.
**1. Score Breakdown (Format: `Category: [SCORE]/10`)**
You must provide a score for each of the following:
- Factual Accuracy: [SCORE]/10
- Relevance & Directness: [SCORE]/10
- Structure & Clarity (STAR Method): [SCORE]/10
**2. Detailed Written Evaluation**
- **Strengths:** What did the candidate do well? (e.g., "Good use of a specific example...")
- **Areas for Improvement:** What were the key weaknesses? (e.g., "The result of the action was unclear...")
**3. Concrete Suggestion**
- **Example Rephrasing:** Provide a short example of how they could have phrased a key part of their answer more effectively.
"""
try:
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": prompt}], model=MODEL
)
return chat_completion.choices[0].message.content
except Exception as e:
return f"An error occurred during evaluation: {e}"
def parse_scores_from_evaluation(evaluation_text: str) -> dict:
scores = {
'Factual Accuracy': 0,
'Relevance & Directness': 0,
'Structure & Clarity (STAR Method)': 0
}
# Updated regex to match the new category name
pattern = r"(Factual Accuracy|Relevance & Directness|Structure & Clarity \(STAR Method\)):\s*\[?(\d{1,2})\]?\/10"
matches = re.findall(pattern, evaluation_text, re.IGNORECASE)
for match in matches:
category_name, score_value = match[0].strip(), int(match[1])
# Normalize the key for consistency
if "Structure" in category_name:
scores['Structure & Clarity (STAR Method)'] = score_value
elif category_name in scores:
scores[category_name] = score_value
print(f"📊 Parsed scores: {scores}")
return scores
def generate_holistic_feedback(full_interview_log):
# This prompt is also enhanced for more detail
prompt = f"""
You are a senior career strategist reviewing a candidate's full interview performance.
Based on the entire Q&A log, provide a detailed "Overall Performance Summary" and an "Actionable Improvement Plan".
**FULL INTERVIEW LOG:**
---
{full_interview_log}
---
**YOUR TASK:**
1. **Overall Performance Summary:** Write a detailed paragraph summarizing the candidate's performance. Analyze their communication style, confidence, and consistency. Identify the most significant recurring strengths and weaknesses across all answers.
2. **Actionable Improvement Plan:** Provide a bulleted list of the top 3 most critical and specific actions the candidate must take. For each action, explain *why* it's important and provide a *concrete example*. (e.g., "- Action: Quantify your achievements. Why: It demonstrates impact. Example: Instead of 'improved the system,' say 'reduced server response time by 15%.'").
"""
try:
chat_completion = client.chat.completions.create(
messages=[{"role": "user", "content": prompt}], model=MODEL
)
return chat_completion.choices[0].message.content
except Exception as e:
return "Could not generate holistic feedback due to an error." |