Parimal Kalpande commited on
Commit
410face
·
1 Parent(s): eee2bf3
Files changed (1) hide show
  1. modules/llm_handler.py +25 -14
modules/llm_handler.py CHANGED
@@ -1,16 +1,25 @@
1
  # modules/llm_handler.py
2
- import ollama
3
  import config
4
  import regex as re
 
5
  from modules.web_search import search_for_example_answers
6
 
 
 
 
 
 
7
  def generate_question(interview_type, document_text):
8
  prompt = f"As an expert {interview_type} interviewer, ask one relevant, open-ended question based on this document:\n\n---\n{document_text}\n---"
9
  try:
10
- response = ollama.chat(model=config.OLLAMA_MODEL, messages=[{'role': 'user', 'content': prompt}])
11
- return response['message']['content'].strip()
 
 
 
12
  except Exception as e:
13
- return f"Error generating question: {e}"
14
 
15
  def evaluate_answer(question, answer):
16
  prompt = f"""
@@ -22,11 +31,14 @@ def evaluate_answer(question, answer):
22
  Relevance & Directness: [SCORE]/10
23
  Structure & Clarity: [SCORE]/10
24
 
25
- After the scores, you MUST provide a brief written evaluation and suggest improvements.
26
  """
27
  try:
28
- response = ollama.chat(model=config.OLLAMA_MODEL, messages=[{'role': 'user', 'content': prompt}], stream=False)
29
- return response['message']['content']
 
 
 
30
  except Exception as e:
31
  return f"An error occurred during evaluation: {e}"
32
 
@@ -49,15 +61,14 @@ def parse_scores_from_evaluation(evaluation_text: str) -> dict:
49
 
50
  def generate_holistic_feedback(full_interview_log):
51
  prompt = f"""
52
- You are a senior interview coach reviewing a candidate's full interview performance.
53
- Based on the entire Q&A log, provide a high-level "Overall Performance Summary" and an "Actionable Improvement Plan".
54
  **FULL INTERVIEW LOG:** --- {full_interview_log} ---
55
- **INSTRUCTIONS:**
56
- 1. **Overall Performance Summary:** Summarize performance, identifying patterns of strengths and weaknesses.
57
- 2. **Actionable Improvement Plan:** Provide a bulleted list of the top 3 most critical actions to take.
58
  """
59
  try:
60
- response = ollama.chat(model=config.OLLAMA_MODEL, messages=[{'role': 'user', 'content': prompt}], stream=False)
61
- return response['message']['content']
 
 
 
62
  except Exception as e:
63
  return "Could not generate holistic feedback due to an error."
 
1
  # modules/llm_handler.py
2
+ import os
3
  import config
4
  import regex as re
5
+ from groq import Groq
6
  from modules.web_search import search_for_example_answers
7
 
8
+ # Initialize the Groq client
9
+ # It will automatically use the API key from your Hugging Face secrets
10
+ client = Groq(api_key=os.environ.get("GROQ_API_KEY"))
11
+ MODEL = "llama3-8b-8192" # Use Groq's Llama 3 8B model
12
+
13
  def generate_question(interview_type, document_text):
14
  prompt = f"As an expert {interview_type} interviewer, ask one relevant, open-ended question based on this document:\n\n---\n{document_text}\n---"
15
  try:
16
+ chat_completion = client.chat.completions.create(
17
+ messages=[{"role": "user", "content": prompt}],
18
+ model=MODEL,
19
+ )
20
+ return chat_completion.choices[0].message.content
21
  except Exception as e:
22
+ return f"Error generating question from API: {e}"
23
 
24
  def evaluate_answer(question, answer):
25
  prompt = f"""
 
31
  Relevance & Directness: [SCORE]/10
32
  Structure & Clarity: [SCORE]/10
33
 
34
+ After the scores, you MUST provide a brief written evaluation.
35
  """
36
  try:
37
+ chat_completion = client.chat.completions.create(
38
+ messages=[{"role": "user", "content": prompt}],
39
+ model=MODEL,
40
+ )
41
+ return chat_completion.choices[0].message.content
42
  except Exception as e:
43
  return f"An error occurred during evaluation: {e}"
44
 
 
61
 
62
  def generate_holistic_feedback(full_interview_log):
63
  prompt = f"""
64
+ You are a senior interview coach. Based on the entire Q&A log, provide a high-level "Overall Performance Summary" and an "Actionable Improvement Plan".
 
65
  **FULL INTERVIEW LOG:** --- {full_interview_log} ---
 
 
 
66
  """
67
  try:
68
+ chat_completion = client.chat.completions.create(
69
+ messages=[{"role": "user", "content": prompt}],
70
+ model=MODEL,
71
+ )
72
+ return chat_completion.choices[0].message.content
73
  except Exception as e:
74
  return "Could not generate holistic feedback due to an error."