Spaces:
Running
on
CPU Upgrade
Running
on
CPU Upgrade
IliaLarchenko
commited on
Commit
•
5f54ec7
1
Parent(s):
68e9ce7
Improved all prompts
Browse files- app.py +1 -2
- llm.py +17 -8
- options.py +1 -1
- prompts.py +33 -15
app.py
CHANGED
@@ -11,7 +11,6 @@ default_audio_params = {
|
|
11 |
"editable": False,
|
12 |
"container": False,
|
13 |
"show_share_button": False,
|
14 |
-
"min_length": 5,
|
15 |
}
|
16 |
|
17 |
|
@@ -118,7 +117,7 @@ with gr.Blocks() as demo:
|
|
118 |
inputs=[chat],
|
119 |
outputs=[chat],
|
120 |
).then(
|
121 |
-
fn=end_interview, inputs=[chat_history, model_select], outputs=feedback
|
122 |
).then(fn=hide_solution, inputs=None, outputs=[solution_acc, end_btn, problem_acc, audio_input])
|
123 |
|
124 |
audio_input.stop_recording(fn=transcribe_audio, inputs=[audio_input], outputs=[message]).then(
|
|
|
11 |
"editable": False,
|
12 |
"container": False,
|
13 |
"show_share_button": False,
|
|
|
14 |
}
|
15 |
|
16 |
|
|
|
117 |
inputs=[chat],
|
118 |
outputs=[chat],
|
119 |
).then(
|
120 |
+
fn=end_interview, inputs=[description, chat_history, model_select], outputs=feedback
|
121 |
).then(fn=hide_solution, inputs=None, outputs=[solution_acc, end_btn, problem_acc, audio_input])
|
122 |
|
123 |
audio_input.stop_recording(fn=transcribe_audio, inputs=[audio_input], outputs=[message]).then(
|
llm.py
CHANGED
@@ -4,7 +4,7 @@ from dotenv import load_dotenv
|
|
4 |
from openai import OpenAI
|
5 |
|
6 |
from audio import numpy_audio_to_bytes
|
7 |
-
from prompts import coding_interviewer_prompt, grading_feedback_prompt
|
8 |
|
9 |
load_dotenv()
|
10 |
# TODO: don't use my key
|
@@ -20,33 +20,42 @@ def init_bot(problem=""):
|
|
20 |
|
21 |
|
22 |
def get_problem(requirements, difficulty, topic, model, client=client):
|
23 |
-
|
24 |
-
|
|
|
|
|
|
|
|
|
25 |
response = client.chat.completions.create(
|
26 |
model=model,
|
27 |
messages=[
|
28 |
-
{"role": "system", "content":
|
29 |
{"role": "user", "content": full_prompt},
|
30 |
],
|
31 |
-
temperature=1.
|
32 |
)
|
33 |
question = response.choices[0].message.content.strip()
|
34 |
chat_history = init_bot(question)
|
35 |
return question, chat_history
|
36 |
|
37 |
|
38 |
-
def end_interview(chat_history, model, client=client):
|
|
|
|
|
|
|
39 |
transcript = []
|
40 |
for message in chat_history[1:]:
|
41 |
role = message["role"]
|
42 |
content = f"{role.capitalize()}: {message['content']}"
|
43 |
transcript.append(content)
|
|
|
44 |
response = client.chat.completions.create(
|
45 |
model=model,
|
46 |
messages=[
|
47 |
{"role": "system", "content": grading_feedback_prompt},
|
48 |
-
{"role": "user", "content": "
|
49 |
-
{"role": "user", "content": "
|
|
|
50 |
],
|
51 |
temperature=0.5,
|
52 |
)
|
|
|
4 |
from openai import OpenAI
|
5 |
|
6 |
from audio import numpy_audio_to_bytes
|
7 |
+
from prompts import coding_interviewer_prompt, grading_feedback_prompt, problem_generation_prompt
|
8 |
|
9 |
load_dotenv()
|
10 |
# TODO: don't use my key
|
|
|
20 |
|
21 |
|
22 |
def get_problem(requirements, difficulty, topic, model, client=client):
|
23 |
+
full_prompt = (
|
24 |
+
f"Create a {difficulty} {topic} coding problem. "
|
25 |
+
f"Additional requirements: {requirements}. "
|
26 |
+
"The problem should be clearly stated, well-formatted, and solvable within 30 minutes. "
|
27 |
+
"Ensure the problem varies each time to provide a wide range of challenges."
|
28 |
+
)
|
29 |
response = client.chat.completions.create(
|
30 |
model=model,
|
31 |
messages=[
|
32 |
+
{"role": "system", "content": problem_generation_prompt},
|
33 |
{"role": "user", "content": full_prompt},
|
34 |
],
|
35 |
+
temperature=1.0, # Adjusted for a balance between creativity and coherency
|
36 |
)
|
37 |
question = response.choices[0].message.content.strip()
|
38 |
chat_history = init_bot(question)
|
39 |
return question, chat_history
|
40 |
|
41 |
|
42 |
+
def end_interview(problem_description, chat_history, model, client=client):
|
43 |
+
if not chat_history or len(chat_history) <= 2:
|
44 |
+
return "No interview content available to review."
|
45 |
+
|
46 |
transcript = []
|
47 |
for message in chat_history[1:]:
|
48 |
role = message["role"]
|
49 |
content = f"{role.capitalize()}: {message['content']}"
|
50 |
transcript.append(content)
|
51 |
+
|
52 |
response = client.chat.completions.create(
|
53 |
model=model,
|
54 |
messages=[
|
55 |
{"role": "system", "content": grading_feedback_prompt},
|
56 |
+
{"role": "user", "content": f"The original problem to solve: {problem_description}"},
|
57 |
+
{"role": "user", "content": "\n\n".join(transcript)},
|
58 |
+
{"role": "user", "content": "Grade the interview based on the transcript provided and give feedback."},
|
59 |
],
|
60 |
temperature=0.5,
|
61 |
)
|
options.py
CHANGED
@@ -28,7 +28,7 @@ models = ["gpt-3.5-turbo"]
|
|
28 |
fixed_messages = {
|
29 |
"intro": "Welcome to the coding interview! I am your AI interview assistant. For the start select the difficulty and topic of the problem you would like to solve. Then click on the 'Generate a problem' button. Good luck!",
|
30 |
"start": (
|
31 |
-
"Please take a moment to read the problem statement. Then you can share you initial thoughts and ask any questions you may have.
|
32 |
"Please use the record button to communicate with me. Try to think out loud and record all you comments and questions as if it is the real interview."
|
33 |
),
|
34 |
"end": "The interview has concluded. Thank you for your participation! In a moment I will provide a detailed feedback on your performance.",
|
|
|
28 |
fixed_messages = {
|
29 |
"intro": "Welcome to the coding interview! I am your AI interview assistant. For the start select the difficulty and topic of the problem you would like to solve. Then click on the 'Generate a problem' button. Good luck!",
|
30 |
"start": (
|
31 |
+
"Please take a moment to read the problem statement. Then you can share you initial thoughts and ask any questions you may have. "
|
32 |
"Please use the record button to communicate with me. Try to think out loud and record all you comments and questions as if it is the real interview."
|
33 |
),
|
34 |
"end": "The interview has concluded. Thank you for your participation! In a moment I will provide a detailed feedback on your performance.",
|
prompts.py
CHANGED
@@ -1,24 +1,42 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
# Coding round interviewer instructions
|
2 |
coding_interviewer_prompt = (
|
3 |
-
"As an AI acting as a coding interviewer for a major tech company, you are to maintain a
|
4 |
-
"
|
5 |
-
"
|
6 |
-
"Encourage
|
7 |
-
"
|
8 |
-
"
|
9 |
-
"
|
10 |
-
"
|
11 |
-
"
|
|
|
|
|
|
|
12 |
)
|
13 |
|
|
|
14 |
# Prompt for grading feedback
|
15 |
grading_feedback_prompt = (
|
16 |
"You are the AI grader for a coding interview at a major tech firm. "
|
17 |
-
"The following is the interview transcript with the candidate. "
|
18 |
-
"
|
19 |
-
"
|
20 |
-
"
|
21 |
-
"
|
22 |
-
"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
23 |
"Format all feedback in clear, structured markdown for readability."
|
24 |
)
|
|
|
1 |
+
problem_generation_prompt = (
|
2 |
+
"You are AI acting as a coding round interviewer for a big-tech company. "
|
3 |
+
"Generate a problem that tests the candidate's ability to solve real-world coding challenges efficiently. "
|
4 |
+
"Ensure the problem tests for problem-solving skills, technical proficiency, code quality, and handling of edge cases. "
|
5 |
+
)
|
6 |
+
|
7 |
# Coding round interviewer instructions
|
8 |
coding_interviewer_prompt = (
|
9 |
+
"As an AI acting as a coding interviewer for a major tech company, you are to maintain a professional and analytical demeanor. "
|
10 |
+
"You must consistently ask about the time and space complexity of the candidate's solutions after each significant problem-solving step. "
|
11 |
+
"Prompt the candidate to explain how they compute these complexities, and guide them through the process if necessary, without providing the answers directly. "
|
12 |
+
"Encourage thorough exploration of solutions without revealing answers directly. Provide hints subtly only after observing the candidate struggle significantly or upon explicit request. "
|
13 |
+
"Probe the candidate with questions related to problem-solving approaches, algorithm choices, handling of edge cases, and error identification to assess technical proficiency comprehensively. "
|
14 |
+
"If the candidate deviates from the problem, gently guide them back to focus on the task at hand. "
|
15 |
+
"After multiple unsuccessful attempts by the candidate to identify or fix an error, provide more direct hints or rephrase the problem slightly to aid understanding. "
|
16 |
+
"Encourage the candidate to think about real-world applications and scalability of their solutions, asking how changes to the problem parameters might affect their approach. "
|
17 |
+
"Responses should be structured in JSON format with two fields: "
|
18 |
+
"1. 'reply_to_candidate': contains visible feedback and guidance for the candidate, structured to facilitate learning and insight without giving away answers. "
|
19 |
+
"2. 'hidden_note': internal notes for the grading AI, including observations on the candidate’s performance across various criteria such as problem-solving skills, debugging effectiveness, and adaptability. These notes may include specific code snippets the candidate struggled with, key mistakes made, and any notable strengths or weaknesses observed. "
|
20 |
+
"The 'hidden_note' should also reflect a self-critical perspective if the interviewer's expectations do not align with a valid candidate solution, acknowledging and adjusting for any potential bias or error. "
|
21 |
)
|
22 |
|
23 |
+
|
24 |
# Prompt for grading feedback
|
25 |
grading_feedback_prompt = (
|
26 |
"You are the AI grader for a coding interview at a major tech firm. "
|
27 |
+
"The following is the interview transcript with the candidate's responses. "
|
28 |
+
"Ignore minor transcription errors unless they impact comprehension. "
|
29 |
+
"If there are no real solution provide just say it. "
|
30 |
+
"Evaluate the candidate’s performance based on the following criteria: "
|
31 |
+
"\n- **Problem-Solving Skills**: Approach to solving problems, creativity, and handling of complex issues."
|
32 |
+
"\n- **Technical Proficiency**: Accuracy of the solution, usage of appropriate algorithms and data structures, consideration of edge cases, and error handling."
|
33 |
+
"\n- **Code Quality**: Readability, maintainability, scalability, and overall organization."
|
34 |
+
"\n- **Communication Skills**: Ability to explain their thought process clearly, interaction during the interview, and responsiveness to feedback."
|
35 |
+
"\n- **Debugging Skills**: Efficiency in identifying and resolving errors."
|
36 |
+
"\n- **Adaptability**: Ability to incorporate feedback and adjust solutions as needed."
|
37 |
+
"\n- **Handling Ambiguity**: Approach to dealing with uncertain or incomplete requirements."
|
38 |
+
"\n- **Real-World Application**: Practicality and real-world applicability of the proposed solutions."
|
39 |
+
"\nProvide comprehensive feedback, detailing overall performance, specific errors, areas for improvement, communication lapses, overlooked edge cases, and any other relevant observations. "
|
40 |
+
"Use code examples to illustrate points where necessary. Your feedback should be critical, aiming to fail candidates who do not meet high standards while providing detailed improvement areas. "
|
41 |
"Format all feedback in clear, structured markdown for readability."
|
42 |
)
|