rairo commited on
Commit
a38e707
·
verified ·
1 Parent(s): 6df647b

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +29 -17
main.py CHANGED
@@ -160,36 +160,48 @@ def _get_context_specific_instructions(use_case):
160
  def analyze_transcript_with_gemini(uid, project_id, transcript, duration_seconds):
161
  logger.info(f"Starting transcript analysis for project {project_id}.")
162
  try:
 
 
 
 
 
 
163
  project_ref = db_ref.child(f'projects/{uid}/{project_id}')
164
  project_data = project_ref.get()
165
  if not project_data: raise ValueError("Project not found for analysis.")
166
  use_case = project_data.get('detectedUseCase', 'General')
167
  context_text = project_data.get('key_points', project_data.get('originalBriefingText', ''))
168
 
169
- # --- NEW, FAIRER PROMPT ---
170
  prompt = f"""
171
- You are an expert performance coach and communication analyst. Your task is to analyze the following transcript of a mock '{use_case}' with fairness and a focus on constructive feedback.
172
- The user's session was based on a document with these key points: "{context_text}"
 
 
 
 
 
173
 
174
- Your analysis must be structured as a valid JSON object. Do not include any text before or after the JSON object.
175
 
176
- **Step 1: Assess Conversation Depth and Effort**
177
- First, evaluate the substance of the conversation. Crucially, you must differentiate between a user who makes a **good-faith effort but struggles** (e.g., gives a short, nervous, or incomplete but relevant answer) and a user who provides **no substantive response at all** (e.g., only says "hello" or hangs up). A good-faith effort, even if imperfect, should be scored higher than no effort.
178
 
179
- **Step 2: Detailed Performance Evaluation with Scoring Rubric**
180
- Evaluate the user's performance on the four core criteria. Use the following scoring rubric to guide your scores:
181
 
182
- * **0-40 (Needs Significant Work):** Use this range for sessions that are extremely short with no real answers, or for responses that are completely off-topic or incoherent.
183
- * **41-70 (Developing):** This is for users who are making a good-faith effort but are still developing their skills. Their answers might be relevant but lack depth, confidence, or clarity. This is the range for a "struggling" user.
184
- * **71-100 (Proficient to Excellent):** Use this range for users who provide clear, confident, and well-supported answers to one or more questions.
 
185
 
186
- **Core Criteria Definitions:**
187
- 1. **Communication Skills:** Score based on clarity and confidence.
188
- 2. **Content Mastery:** Score based on relevance and support for claims. An answer must be on-topic to score above 40.
189
- 3. **Engagement & Delivery:** Score based on tone and pacing. Can only be reasonably scored in a back-and-forth exchange.
190
- 4. **Resilience Under Pressure:** Score based on handling follow-up questions. If no follow-up was possible, this score should reflect that, typically in the lower-mid range.
191
 
192
- **Final Instruction:** Your primary goal is to be a constructive coach. If the scores are low because the session was too short, the qualitative feedback fields MUST explain this clearly and encourage the user to try a longer session to get a more accurate analysis.
193
 
194
  The JSON structure MUST be:
195
  {{
 
160
  def analyze_transcript_with_gemini(uid, project_id, transcript, duration_seconds):
161
  logger.info(f"Starting transcript analysis for project {project_id}.")
162
  try:
163
+ # --- NEW: Fetch user's name for explicit identification ---
164
+ user_ref = db_ref.child(f'users/{uid}')
165
+ user_data = user_ref.get()
166
+ user_name = user_data.get('displayName', 'the user') if user_data else 'the user'
167
+ # --- END NEW ---
168
+
169
  project_ref = db_ref.child(f'projects/{uid}/{project_id}')
170
  project_data = project_ref.get()
171
  if not project_data: raise ValueError("Project not found for analysis.")
172
  use_case = project_data.get('detectedUseCase', 'General')
173
  context_text = project_data.get('key_points', project_data.get('originalBriefingText', ''))
174
 
175
+ # --- NEW, SURGICALLY PRECISE PROMPT ---
176
  prompt = f"""
177
+ You are an expert performance coach and communication analyst. Your task is to analyze the following transcript of a mock '{use_case}' with fairness and precision.
178
+
179
+ **CRITICAL CONTEXT:**
180
+ - You are analyzing a session for a user named **'{user_name}'**.
181
+ - In the transcript, the speaker labeled 'User' is **'{user_name}'**.
182
+ - Any other names mentioned by the user (e.g., Eric, Daniel, Rachel) are part of the role-play scenario and should NOT be confused with the user you are evaluating.
183
+ - The user's session was based on a document with these key points: "{context_text}"
184
 
185
+ Your analysis must be structured as a valid JSON object.
186
 
187
+ **Step 1: Assess Conversation Substance**
188
+ First, evaluate if the transcript contains a "substantive answer." A substantive answer is defined as a user's response to a direct question from the AI. An introductory statement or greeting from the user does NOT count as a substantive answer.
189
 
190
+ **Step 2: Detailed Performance Evaluation with a Strict Scoring Rubric**
191
+ Evaluate the user's performance on the four core criteria. You MUST follow this rubric:
192
 
193
+ * **Crucial Scoring Rule:** To award a score above 40 in **any** category, the user must have provided at least one complete, on-topic, "substantive answer" as defined in Step 1.
194
+ * **0-40 (Needs Significant Work):** Use this range if the session does not contain a substantive answer. Even if the user's introduction is excellent, if they do not answer a question, their scores must remain in this range.
195
+ * **41-70 (Developing):** Use this for users who provide at least one substantive answer but struggle with clarity, depth, or confidence.
196
+ * **71-100 (Proficient to Excellent):** Use this for users who provide clear, confident, and well-supported answers.
197
 
198
+ **Core Criteria:**
199
+ 1. **Communication Skills:** Clarity and confidence.
200
+ 2. **Content Mastery:** Relevance and support for claims. Cannot be high without a substantive answer.
201
+ 3. **Engagement & Delivery:** Tone and pacing.
202
+ 4. **Resilience Under Pressure:** Handling follow-up questions. Cannot be scored high if no questions were answered.
203
 
204
+ **Final Instruction:** Your qualitative feedback should reflect the score. If scores are low because the session was too short, you can praise the introduction in the "Strengths" section (e.g., "Provides a clear, confident opening statement.") but you MUST state in the "Areas for Improvement" section that a full analysis is impossible without answering questions.
205
 
206
  The JSON structure MUST be:
207
  {{