Spaces:
Sleeping
Sleeping
vertex ai minor bugs 1
Browse files- .DS_Store +0 -0
- src/interview_logic.py +20 -38
.DS_Store
CHANGED
|
Binary files a/.DS_Store and b/.DS_Store differ
|
|
|
src/interview_logic.py
CHANGED
|
@@ -10,50 +10,32 @@ EXCEL_QUESTIONS = [
|
|
| 10 |
"What is Conditional Formatting in Excel? Can you provide an example?",
|
| 11 |
]
|
| 12 |
|
| 13 |
-
# --- CORRECTED FUNCTION ---
|
| 14 |
def start_interview(state: dict) -> dict:
|
| 15 |
"""
|
| 16 |
-
|
| 17 |
-
preserving the user's first message. The graph will then transition to 'ask_question'
|
| 18 |
-
to ask the first question.
|
| 19 |
"""
|
| 20 |
intro_message = "Welcome to the automated Excel skills assessment! I will ask you a series of questions to gauge your knowledge. Let's start with the first one."
|
| 21 |
-
|
| 22 |
-
# Get the existing history from the state
|
| 23 |
history = state.get("interview_history", [])
|
| 24 |
-
|
| 25 |
-
# Append the welcome message
|
| 26 |
history.append(("ai", intro_message))
|
| 27 |
-
|
| 28 |
-
# Return the updated state. We do NOT ask a question here.
|
| 29 |
return {
|
| 30 |
**state,
|
| 31 |
"interview_status": 1,
|
| 32 |
-
"interview_history": history,
|
| 33 |
"questions": EXCEL_QUESTIONS,
|
| 34 |
-
"question_index": 0,
|
| 35 |
"evaluations": [],
|
| 36 |
-
"warnings": [],
|
| 37 |
-
"final_feedback": "",
|
| 38 |
}
|
| 39 |
|
| 40 |
-
|
| 41 |
def ask_question(state: dict) -> dict:
|
| 42 |
-
"""
|
| 43 |
-
This function is now responsible for asking ALL questions, including the first one.
|
| 44 |
-
It remains unchanged but its role is now clearer.
|
| 45 |
-
"""
|
| 46 |
question_index = state["question_index"]
|
| 47 |
current_question = state["questions"][question_index]
|
| 48 |
-
|
| 49 |
history = state.get("interview_history", [])
|
| 50 |
history.append(("ai", current_question))
|
| 51 |
-
|
| 52 |
-
return { **state, "interview_history": history }
|
| 53 |
-
|
| 54 |
|
| 55 |
def process_user_response(state: dict) -> dict:
|
| 56 |
-
"""
|
| 57 |
history = state.get("interview_history", [])
|
| 58 |
user_response = history[-1][1]
|
| 59 |
|
|
@@ -73,13 +55,12 @@ def process_user_response(state: dict) -> dict:
|
|
| 73 |
|
| 74 |
evaluation = get_llm_response(evaluation_prompt)
|
| 75 |
|
| 76 |
-
#
|
| 77 |
history.append(("ai", f"**Evaluation:**\n{evaluation}"))
|
| 78 |
|
| 79 |
evaluations = state.get("evaluations", [])
|
| 80 |
evaluations.append(evaluation)
|
| 81 |
|
| 82 |
-
# Increment the question index for the next turn
|
| 83 |
return {
|
| 84 |
**state,
|
| 85 |
"interview_history": history,
|
|
@@ -88,7 +69,7 @@ def process_user_response(state: dict) -> dict:
|
|
| 88 |
}
|
| 89 |
|
| 90 |
def generate_final_report(state: dict) -> dict:
|
| 91 |
-
"""
|
| 92 |
interview_transcript = "\n".join([f"{speaker.capitalize()}: {text}" for speaker, text in state['interview_history']])
|
| 93 |
evaluations_summary = "\n\n".join(f"Evaluation for Q{i+1}:\n{e}" for i, e in enumerate(state['evaluations']))
|
| 94 |
|
|
@@ -99,31 +80,32 @@ def generate_final_report(state: dict) -> dict:
|
|
| 99 |
)
|
| 100 |
|
| 101 |
final_feedback = get_llm_response(report_prompt)
|
| 102 |
-
|
| 103 |
history = state.get("interview_history", [])
|
|
|
|
| 104 |
history.append(("ai", f"**Final Performance Summary:**\n{final_feedback}"))
|
| 105 |
|
| 106 |
return {**state, "final_feedback": final_feedback, "interview_history": history, "interview_status": 2}
|
| 107 |
|
| 108 |
-
|
| 109 |
-
# --- CORRECTED ROUTING ---
|
| 110 |
-
# The routing logic itself is fine, but its behavior is now correct because
|
| 111 |
-
# the nodes it routes to have been fixed.
|
| 112 |
|
| 113 |
def route_after_evaluation(state: dict):
|
|
|
|
| 114 |
if state.get("interview_status") == 2:
|
| 115 |
return "terminate"
|
| 116 |
-
# The evaluation node now just adds feedback, so we check the index to see if we should ask another question or end.
|
| 117 |
elif state["question_index"] >= len(state["questions"]):
|
| 118 |
return "generate_final_report"
|
| 119 |
else:
|
| 120 |
return "ask_question"
|
| 121 |
|
| 122 |
def route_start_of_interview(state: dict):
|
| 123 |
-
|
| 124 |
-
|
| 125 |
-
|
| 126 |
-
|
|
|
|
|
|
|
|
|
|
| 127 |
return "start_interview"
|
|
|
|
| 128 |
else:
|
| 129 |
-
return "process_user_response"
|
|
|
|
| 10 |
"What is Conditional Formatting in Excel? Can you provide an example?",
|
| 11 |
]
|
| 12 |
|
|
|
|
| 13 |
def start_interview(state: dict) -> dict:
|
| 14 |
"""
|
| 15 |
+
Appends a welcome message to the history, preserving the user's first message.
|
|
|
|
|
|
|
| 16 |
"""
|
| 17 |
intro_message = "Welcome to the automated Excel skills assessment! I will ask you a series of questions to gauge your knowledge. Let's start with the first one."
|
|
|
|
|
|
|
| 18 |
history = state.get("interview_history", [])
|
|
|
|
|
|
|
| 19 |
history.append(("ai", intro_message))
|
|
|
|
|
|
|
| 20 |
return {
|
| 21 |
**state,
|
| 22 |
"interview_status": 1,
|
| 23 |
+
"interview_history": history,
|
| 24 |
"questions": EXCEL_QUESTIONS,
|
| 25 |
+
"question_index": 0,
|
| 26 |
"evaluations": [],
|
|
|
|
|
|
|
| 27 |
}
|
| 28 |
|
|
|
|
| 29 |
def ask_question(state: dict) -> dict:
|
| 30 |
+
"""Asks the current question based on the question_index."""
|
|
|
|
|
|
|
|
|
|
| 31 |
question_index = state["question_index"]
|
| 32 |
current_question = state["questions"][question_index]
|
|
|
|
| 33 |
history = state.get("interview_history", [])
|
| 34 |
history.append(("ai", current_question))
|
| 35 |
+
return {**state, "interview_history": history}
|
|
|
|
|
|
|
| 36 |
|
| 37 |
def process_user_response(state: dict) -> dict:
|
| 38 |
+
"""Evaluates the user's response and appends the evaluation to history."""
|
| 39 |
history = state.get("interview_history", [])
|
| 40 |
user_response = history[-1][1]
|
| 41 |
|
|
|
|
| 55 |
|
| 56 |
evaluation = get_llm_response(evaluation_prompt)
|
| 57 |
|
| 58 |
+
# Add a clear marker for the user
|
| 59 |
history.append(("ai", f"**Evaluation:**\n{evaluation}"))
|
| 60 |
|
| 61 |
evaluations = state.get("evaluations", [])
|
| 62 |
evaluations.append(evaluation)
|
| 63 |
|
|
|
|
| 64 |
return {
|
| 65 |
**state,
|
| 66 |
"interview_history": history,
|
|
|
|
| 69 |
}
|
| 70 |
|
| 71 |
def generate_final_report(state: dict) -> dict:
|
| 72 |
+
"""Generates and appends the final performance summary."""
|
| 73 |
interview_transcript = "\n".join([f"{speaker.capitalize()}: {text}" for speaker, text in state['interview_history']])
|
| 74 |
evaluations_summary = "\n\n".join(f"Evaluation for Q{i+1}:\n{e}" for i, e in enumerate(state['evaluations']))
|
| 75 |
|
|
|
|
| 80 |
)
|
| 81 |
|
| 82 |
final_feedback = get_llm_response(report_prompt)
|
|
|
|
| 83 |
history = state.get("interview_history", [])
|
| 84 |
+
# Add a clear marker for the user
|
| 85 |
history.append(("ai", f"**Final Performance Summary:**\n{final_feedback}"))
|
| 86 |
|
| 87 |
return {**state, "final_feedback": final_feedback, "interview_history": history, "interview_status": 2}
|
| 88 |
|
| 89 |
+
# --- CORRECTED ROUTING LOGIC ---
|
|
|
|
|
|
|
|
|
|
| 90 |
|
| 91 |
def route_after_evaluation(state: dict):
|
| 92 |
+
"""Routes to the next step after a user's response has been processed."""
|
| 93 |
if state.get("interview_status") == 2:
|
| 94 |
return "terminate"
|
|
|
|
| 95 |
elif state["question_index"] >= len(state["questions"]):
|
| 96 |
return "generate_final_report"
|
| 97 |
else:
|
| 98 |
return "ask_question"
|
| 99 |
|
| 100 |
def route_start_of_interview(state: dict):
|
| 101 |
+
"""
|
| 102 |
+
CORRECTED: This is the critical fix.
|
| 103 |
+
Checks if it's the very first user message to start the interview.
|
| 104 |
+
Otherwise, it processes the message as an answer.
|
| 105 |
+
"""
|
| 106 |
+
# If the history has exactly one turn, it must be the user's initial message.
|
| 107 |
+
if len(state["interview_history"]) == 1:
|
| 108 |
return "start_interview"
|
| 109 |
+
# Otherwise, the user is responding to a question.
|
| 110 |
else:
|
| 111 |
+
return "process_user_response"
|