justenp commited on
Commit
e9880f2
·
1 Parent(s): d0097c9

update system prompt and add inputs

Browse files
Files changed (1) hide show
  1. app.py +250 -55
app.py CHANGED
@@ -5,38 +5,113 @@ import os
5
 
6
  interviewer_system_prompt = """
7
  # Task
8
- - You are an unnamed multilingual interviewer, interviewing for the House Cleaner position.
9
-
10
- # Tone
11
- - Be friendly and engaging but professional.
12
- - Keep your responses relevant to the task and the candidate's response.
13
-
14
- # Rules
15
- - Do not introduce yourself with a name.
16
- - Do not include instructions in your response. (ie. "We will do this interview and be friendly and engaging but professional.")
17
- - Default language is English. Always respond in English unless the candidate has explicitly selected a different language or is clearly communicating in another language.
18
- - Always answer in the same language as the question once a language has been established.
19
- - If the candidate is not fluent in the language, ask them to repeat their answer.
20
- - If the candidate does not answer the question, ask them to repeat their answer.
21
-
22
- # Incorrect examples
23
- - Hello! I am [Interviewers Name], and I will be conducting your interview for the House Cleaner position today. We will keep the tone friendly and engaging, but professional.
24
-
25
- # Introduction
26
- - Start the interview with:
27
- - "Hello! I will be conducting your interview for the House Cleaner position today. Let's get started."
28
- - Introduce yourself as the interviewer.
29
- - Explain the task and the tone of the interview.
30
-
31
- # Questions
32
- 1. Ask the candidate about their experience with cleaning.
33
- 2. Ask the candidate about their experience with working in a team.
34
- 3. Ask the candidate about their preferred methods of cleaning.
35
-
36
- # Closing
37
- - Thank the candidate for their time.
38
- - Ask if they have any questions.
39
- - End the interview with a goodbye.
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40
  """
41
 
42
  candidate_system_prompt = """You are a job candidate applying for a House Cleaner position.
@@ -51,6 +126,55 @@ Guidelines:
51
  - If you don't have direct experience, show willingness to learn
52
  """
53
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
54
  """
55
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
56
  """
@@ -92,11 +216,46 @@ with gr.Blocks() as demo:
92
  clear_btn = gr.ClearButton([msg, chatbot], value="Clear Chat")
93
 
94
  with gr.Column(scale=1):
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
95
  system_prompt = gr.Textbox(
96
  lines=10,
97
  autoscroll=True,
98
- value=interviewer_system_prompt,
99
- label="System Prompt",
 
 
 
 
 
100
  interactive=True
101
  )
102
  max_tokens = gr.Slider(
@@ -121,22 +280,58 @@ with gr.Blocks() as demo:
121
  label="Top-p (nucleus sampling)"
122
  )
123
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
124
  # Language selection mapping
125
- language_greetings = {
126
- "English": "Hello! I will be conducting your interview for the House Cleaner position today. Let's get started. Could you please tell me about your experience with cleaning?",
127
- "Español (México)": "¡Hola! El día de hoy voy a realizar tu entrevista para el puesto de Limpiador/a de Casa. Empecemos. ¿Podrías contarme sobre tu experiencia en limpieza?",
128
- "Français": "Bonjour! Je vais mener votre entretien pour le poste de femme/homme de ménage aujourd'hui. Commençons. Pourriez-vous me parler de votre expérience en nettoyage?",
129
- "Kreyòl Ayisyen": "Bonjou! Jodi a, m ap fè entèvyou ou pou pozisyon Netwayè Kay la. Ann kòmanse. Eske ou ka pale m de eksperyans ou nan netwayaj?",
130
- }
131
-
132
- def start_interview_in_language(language, history, system_msg):
133
- """Start the interview with a greeting in the selected language. Clears any existing chat."""
 
 
 
 
 
 
 
 
134
  # Always clear and restart when a language button is clicked
135
- greeting = language_greetings.get(language, language_greetings["English"])
136
 
137
- # Reset system message to original and add language preference
138
- original_system_msg = interviewer_system_prompt
139
- updated_system_msg = original_system_msg + f"\n\n- The candidate has selected {language} as their preferred language. Always respond in {language}."
140
 
141
  return [{"role": "assistant", "content": greeting}], updated_system_msg
142
 
@@ -217,26 +412,26 @@ with gr.Blocks() as demo:
217
 
218
  # Wire up language selection buttons
219
  lang_english.click(
220
- lambda h, s: start_interview_in_language("English", h, s),
221
- [chatbot, system_prompt],
222
  [chatbot, system_prompt]
223
  )
224
 
225
  lang_spanish.click(
226
- lambda h, s: start_interview_in_language("Español (México)", h, s),
227
- [chatbot, system_prompt],
228
  [chatbot, system_prompt]
229
  )
230
 
231
  lang_french.click(
232
- lambda h, s: start_interview_in_language("Français", h, s),
233
- [chatbot, system_prompt],
234
  [chatbot, system_prompt]
235
  )
236
 
237
  lang_creole.click(
238
- lambda h, s: start_interview_in_language("Kreyòl Ayisyen", h, s),
239
- [chatbot, system_prompt],
240
  [chatbot, system_prompt]
241
  )
242
 
 
5
 
6
  interviewer_system_prompt = """
7
  # Task
8
+ - You are to act as a multilingual interviewer / hiring manager for {{ COMPANY_NAME }}, hiring for the {{ SCREENER_NAME }} position.
9
+
10
+ # Conversation Tone
11
+
12
+ - You are very friendly, empathetic, enthusiastic, and interested in the users answers and experience.
13
+ - Keep it conversational and friendly.
14
+ - Maintain correct language and translation based on user's selection for all responses and statements.
15
+
16
+ # Conversation Rules
17
+
18
+ - Listen Carefully: Pay close attention to the interviewee's responses. If the answer is incomplete or doesn't directly address the question, politely ask for further details.
19
+ - Maintain Context: Keep the conversation's context in mind when formulating follow-up questions or responses. This ensures relevance and coherence throughout the interview.
20
+ - Be Adaptive: Adjust the conversation based on the interviewee's input. If an interesting point arises that's worth exploring, feel free to ask more about it while still aiming to cover all planned questions.
21
+ - Validate Responses: Ensure each response adheres to the specific rules and validation criteria set for the questions. If not, gently guide the interviewee back to the topic or ask for clarification.
22
+ - Respect Comfort Levels: If the interviewee seems uncomfortable with a question, acknowledge their feelings and offer to move on or adjust the question.
23
+ - Provide Clarity: If asked for clarification or a rephrased question, respond in a clear and understanding manner to facilitate a smooth conversation.
24
+ - Conclude Properly: At the end of the interview, thank the interviewee for their time and provide information on the next steps, if applicable.
25
+ - Avoid repetitiveness: Do not repeat questions that had been previously asked.
26
+ - Translation: If a language other than english is indicated, use that language for the rest of the conversation, and translate pre-written questions into that language.
27
+
28
+ # Company Information
29
+
30
+ - If the candidate asks you, the interviewer, questions about the company or role, respond with: Thank you for your interest in learning more about our company. To ensure you receive the most accurate and detailed information, a member of our team will address your questions later in the process. For now, let's focus on your qualifications and experiences related to this position.
31
+ - Do not respond with this unless the candidate asks you a question about the company, company details, or role details.
32
+
33
+ # EEOC Compliance
34
+ - Strictly adhere to the United States Equal Employment Opportunity Commission interview guidelines.
35
+
36
+ ## Conversation EEOC Rules
37
+
38
+ - Do not ask about or discuss personal characteristics protected by law, including but not limited to: race, color, religion, sex (including gender identity, sexual orientation, and pregnancy), national origin, age, disability, genetic information, mental health, or veteran status.
39
+ - If an applicant discloses any protected characteristic, provide a neutral acknowledgment and move to next question or response.
40
+ - Immediately redirect the conversation to job-related topics and qualifications.
41
+ - Do not express any sentiments that could be interpreted as bias or judgment based on any disclosures.
42
+ - Ensure all questions and discussions relate directly to the applicant's ability to perform the essential functions of the job.
43
+ - If an applicant mentions personal information such as marital status, number of children, or other family circumstances, do not engage with or ask follow-up questions about this information. Instead, acknowledge briefly and redirect to job-related topics.
44
+ - Never ask how personal circumstances, including family situation, might affect job performance.
45
+
46
+ ## Example scenarios
47
+
48
+ Candidate: "I struggle with mental health..."
49
+ Correct example response: Thank you for sharing. Let's focus on your professional experiences that relate to this position. Could you tell me about a time when you successfully managed a challenging situation in your previous role?.
50
+
51
+ Candidate: "I have 6 children..."
52
+ Correct example response: Thank you for sharing. Let's focus on your professional experiences that relate to this position. Could you tell me about a time when you successfully managed multiple priorities in a fast-paced work environment?.
53
+
54
+ # Translations
55
+
56
+ - Translate the entire conversation into the user's selected language.
57
+ - Maintain the original tone and context.
58
+ - Preserve idioms when appropriate, or adapt them for the target language.
59
+ - Keep the format, punctuation, and sentence structure similar to the original when possible.
60
+ - For specialized terms or jargon, provide the most accurate translation.
61
+ - If a word or phrase has no direct translation, transliterate it and provide a brief explanation in parentheses.
62
+ - Render the Interlude Statement and the Closing Statement in the target language.
63
+ - Translate the Company Information deflection response as well.
64
+
65
+ ---
66
+
67
+ # Conversation Flow
68
+
69
+ - The interlude statement should only be given once at the beginning of the conversation.
70
+ - IMPORTANT: The Interlude Statement must be delivered in the same language as the rest of the conversation. If the user requested a language other than English, translate the Interlude Statement before delivering it.
71
+ - Do not restart the conversation for any reason.
72
+ - Maintain memory and knowledge of current point in the conversation to avoid restarting or looping back to the first question.
73
+ - If the conversation context is lost for any reason, gracefully resume from the last unanswered question instead of restarting.
74
+ - If you accidentally repeat or rephrase a question already asked, acknowledge it and move on smoothly to the next unique question.
75
+
76
+ ## Sample Conversation Flow
77
+
78
+ 1. Interlude statement (only given once & translated if user has selected language other than English).
79
+ 2. Questions & conversation.
80
+ 3. Closing Statement / Conclusion.
81
+
82
+ ## Interlude Statement:
83
+
84
+ CRITICAL: Check the user's message for their language selection before delivering this statement.
85
+
86
+ Before delivering the Interlude Statement:
87
+ 1. Check if the user specified a language other than English in their initial message
88
+ 2. If they specified another language, translate the entire Interlude Statement into that language
89
+ 3. If they did NOT specify another language, deliver the English version as written below
90
+
91
+ ### Interlude Statement - English:
92
+ Perfect. Now we have {{ TOTAL_Q_COUNT }} more questions to determine how good of a fit you are for the role. We weigh these questions heavily while hiring, so please consider your answer carefully.
93
+
94
+ ### Interlude Statement - Haitian Creole Translation:
95
+ Parfè. Kounye a nou gen {{ TOTAL_Q_COUNT }} lòt kesyon pou n detèmine kijan ou anfòm ak wòl la. Nou pran kesyon sa yo trè serye nan pwosesis anbochaj la, kidonk tanpri reflechi byen anvan ou reponn. Ann pase sou premye kesyon an nan seri a.
96
+
97
+ ### Interlude Statement - French Translation:
98
+ Parfait. Nous avons maintenant encore {{ TOTAL_Q_COUNT }} questions pour déterminer à quel point vous correspondez au poste. Nous accordons beaucoup d'importance à ces questions dans le processus de recrutement, alors prenez le temps de bien réfléchir avant de répondre. Passons à la première question de la série.
99
+
100
+ ## Inputs & Synthesization
101
+
102
+ {{#each QUESTIONS}}
103
+ "{{{ QUESTION_TEXT }}"
104
+ {{/each}}
105
+
106
+ ## Closing Statement
107
+
108
+ {{ ENDING_STATEMENT }}
109
+
110
+ # Conversation Completion & End
111
+
112
+ - The Closing Statement acts as the final message of the conversation.
113
+ - If a question is asked after the Closing Statement, politely decline further conversation with "Thank you for your time. Our team will reach out with further questions or instructions.".
114
+ - Do not repeat any questions or allow the conversation to continue.
115
  """
116
 
117
  candidate_system_prompt = """You are a job candidate applying for a House Cleaner position.
 
126
  - If you don't have direct experience, show willingness to learn
127
  """
128
 
129
+ def synthesize_prompt(company_name: str, screener_name: str, questions: str, ending_statement: str) -> str:
130
+ """
131
+ Synthesizes the interviewer system prompt by replacing template variables
132
+ with actual values from the input fields.
133
+
134
+ Args:
135
+ company_name: The name of the company
136
+ screener_name: The position/screener name
137
+ questions: Newline-separated list of questions
138
+ ending_statement: The closing statement for the interview
139
+
140
+ Returns:
141
+ The synthesized system prompt with all variables replaced
142
+ """
143
+ # Parse questions - split by newlines and filter empty lines
144
+ question_list = [q.strip() for q in questions.split('\n') if q.strip()]
145
+ total_q_count = len(question_list)
146
+
147
+ # Format questions for the prompt
148
+ questions_formatted = ""
149
+ for i, question in enumerate(question_list, 1):
150
+ questions_formatted += f'Question {i}: "{question}"\n'
151
+
152
+ # Start with the template
153
+ prompt = interviewer_system_prompt
154
+
155
+ # Replace template variables
156
+ prompt = prompt.replace("{{ COMPANY_NAME }}", company_name)
157
+ prompt = prompt.replace("{{ SCREENER_NAME }}", screener_name)
158
+ prompt = prompt.replace("{{ TOTAL_Q_COUNT }}", str(total_q_count))
159
+ prompt = prompt.replace("{{ ENDING_STATEMENT }}", ending_statement)
160
+
161
+ # Replace the {{#each QUESTIONS}} block with actual questions
162
+ # Find the block between {{#each QUESTIONS}} and {{/each}}
163
+ if "{{#each QUESTIONS}}" in prompt:
164
+ start_marker = "{{#each QUESTIONS}}"
165
+ end_marker = "{{/each}}"
166
+
167
+ start_idx = prompt.find(start_marker)
168
+ end_idx = prompt.find(end_marker)
169
+
170
+ if start_idx != -1 and end_idx != -1:
171
+ # Replace the entire block with formatted questions
172
+ before_block = prompt[:start_idx]
173
+ after_block = prompt[end_idx + len(end_marker):]
174
+ prompt = before_block + questions_formatted + after_block
175
+
176
+ return prompt
177
+
178
  """
179
  For information on how to customize the ChatInterface, peruse the gradio docs: https://www.gradio.app/docs/chatinterface
180
  """
 
216
  clear_btn = gr.ClearButton([msg, chatbot], value="Clear Chat")
217
 
218
  with gr.Column(scale=1):
219
+ gr.Markdown("### Configuration")
220
+
221
+ company_name = gr.Textbox(
222
+ label="Company Name",
223
+ value="ABC Company",
224
+ placeholder="Enter company name",
225
+ lines=1
226
+ )
227
+
228
+ screener_name = gr.Textbox(
229
+ label="Position/Screener Name",
230
+ value="House Cleaner",
231
+ placeholder="Enter position name",
232
+ lines=1
233
+ )
234
+
235
+ questions_input = gr.Textbox(
236
+ label="Questions (one per line)",
237
+ value="Tell me about your cleaning experience.\nHow do you handle working in a team?\nWhat are your preferred cleaning methods?",
238
+ placeholder="Enter interview questions, one per line",
239
+ lines=5
240
+ )
241
+
242
+ ending_statement = gr.Textbox(
243
+ label="Ending Statement",
244
+ value="Thank you for taking the time to complete this interview. We will review your responses and get back to you within 3-5 business days.",
245
+ placeholder="Enter the closing statement",
246
+ lines=3
247
+ )
248
+
249
  system_prompt = gr.Textbox(
250
  lines=10,
251
  autoscroll=True,
252
+ value=synthesize_prompt(
253
+ "ABC Company",
254
+ "House Cleaner",
255
+ "Tell me about your cleaning experience.\nHow do you handle working in a team?\nWhat are your preferred cleaning methods?",
256
+ "Thank you for taking the time to complete this interview. We will review your responses and get back to you within 3-5 business days."
257
+ ),
258
+ label="Synthesized System Prompt",
259
  interactive=True
260
  )
261
  max_tokens = gr.Slider(
 
280
  label="Top-p (nucleus sampling)"
281
  )
282
 
283
+ # Function to update system prompt when inputs change
284
+ def update_prompt(company, position, questions, ending):
285
+ return synthesize_prompt(company, position, questions, ending)
286
+
287
+ # Wire up auto-update for system prompt
288
+ company_name.change(
289
+ update_prompt,
290
+ [company_name, screener_name, questions_input, ending_statement],
291
+ system_prompt
292
+ )
293
+
294
+ screener_name.change(
295
+ update_prompt,
296
+ [company_name, screener_name, questions_input, ending_statement],
297
+ system_prompt
298
+ )
299
+
300
+ questions_input.change(
301
+ update_prompt,
302
+ [company_name, screener_name, questions_input, ending_statement],
303
+ system_prompt
304
+ )
305
+
306
+ ending_statement.change(
307
+ update_prompt,
308
+ [company_name, screener_name, questions_input, ending_statement],
309
+ system_prompt
310
+ )
311
+
312
  # Language selection mapping
313
+ def get_language_greeting(language, questions_text):
314
+ """Get the Interlude Statement in the selected language with the question count"""
315
+ # Count the questions
316
+ question_list = [q.strip() for q in questions_text.split('\n') if q.strip()]
317
+ total_q_count = len(question_list)
318
+
319
+ # Interlude Statement translations from the system prompt
320
+ greetings = {
321
+ "English": f"Perfect. Now we have {total_q_count} more questions to determine how good of a fit you are for the role. We weigh these questions heavily while hiring, so please consider your answer carefully.",
322
+ "Español (México)": f"Perfecto. Ahora tenemos {total_q_count} preguntas más para determinar qué tan adecuado eres para el puesto. Damos mucha importancia a estas preguntas en el proceso de contratación, así que considera tu respuesta cuidadosamente.",
323
+ "Français": f"Parfait. Nous avons maintenant encore {total_q_count} questions pour déterminer à quel point vous correspondez au poste. Nous accordons beaucoup d'importance à ces questions dans le processus de recrutement, alors prenez le temps de bien réfléchir avant de répondre. Passons à la première question de la série.",
324
+ "Kreyòl Ayisyen": f"Parfè. Kounye a nou gen {total_q_count} lòt kesyon pou n detèmine kijan ou anfòm ak wòl la. Nou pran kesyon sa yo trè serye nan pwosesis anbochaj la, kidonk tanpri reflechi byen anvan ou reponn. Ann pase sou premye kesyon an nan seri a.",
325
+ }
326
+ return greetings.get(language, greetings["English"])
327
+
328
+ def start_interview_in_language(language, history, system_msg, questions_text):
329
+ """Start the interview with the Interlude Statement in the selected language. Clears any existing chat."""
330
  # Always clear and restart when a language button is clicked
331
+ greeting = get_language_greeting(language, questions_text)
332
 
333
+ # Add language preference to system message
334
+ updated_system_msg = system_msg + f"\n\n- The candidate has selected {language} as their preferred language. Always respond in {language}."
 
335
 
336
  return [{"role": "assistant", "content": greeting}], updated_system_msg
337
 
 
412
 
413
  # Wire up language selection buttons
414
  lang_english.click(
415
+ lambda h, s, q: start_interview_in_language("English", h, s, q),
416
+ [chatbot, system_prompt, questions_input],
417
  [chatbot, system_prompt]
418
  )
419
 
420
  lang_spanish.click(
421
+ lambda h, s, q: start_interview_in_language("Español (México)", h, s, q),
422
+ [chatbot, system_prompt, questions_input],
423
  [chatbot, system_prompt]
424
  )
425
 
426
  lang_french.click(
427
+ lambda h, s, q: start_interview_in_language("Français", h, s, q),
428
+ [chatbot, system_prompt, questions_input],
429
  [chatbot, system_prompt]
430
  )
431
 
432
  lang_creole.click(
433
+ lambda h, s, q: start_interview_in_language("Kreyòl Ayisyen", h, s, q),
434
+ [chatbot, system_prompt, questions_input],
435
  [chatbot, system_prompt]
436
  )
437