IliaLarchenko commited on
Commit
c8e8be4
1 Parent(s): 1a9277d

Added problem generation

Browse files
Files changed (3) hide show
  1. app.py +6 -1
  2. llm.py +63 -0
  3. requirements.txt +1 -0
app.py CHANGED
@@ -1,5 +1,7 @@
1
  import gradio as gr
2
 
 
 
3
  with gr.Blocks() as demo:
4
  gr.Markdown("Your coding interview practice AI assistant!")
5
  with gr.Tab("Coding"):
@@ -20,7 +22,7 @@ with gr.Blocks() as demo:
20
  with gr.Row() as content:
21
  with gr.Column(scale=2):
22
  code = gr.Code(label="Solution", language="python", lines=20)
23
- message = gr.Textbox(label="text", lines=1)
24
  answer_btn = gr.Button("Send message")
25
  with gr.Column(scale=1):
26
  chat = gr.Chatbot(label="Chat history")
@@ -28,4 +30,7 @@ with gr.Blocks() as demo:
28
  with gr.Accordion("Feedback", open=True) as feedback_acc:
29
  feedback = gr.Markdown()
30
 
 
 
 
31
  demo.launch()
 
1
  import gradio as gr
2
 
3
+ from llm import get_problem
4
+
5
  with gr.Blocks() as demo:
6
  gr.Markdown("Your coding interview practice AI assistant!")
7
  with gr.Tab("Coding"):
 
22
  with gr.Row() as content:
23
  with gr.Column(scale=2):
24
  code = gr.Code(label="Solution", language="python", lines=20)
25
+ message = gr.Textbox(label="Message", lines=1)
26
  answer_btn = gr.Button("Send message")
27
  with gr.Column(scale=1):
28
  chat = gr.Chatbot(label="Chat history")
 
30
  with gr.Accordion("Feedback", open=True) as feedback_acc:
31
  feedback = gr.Markdown()
32
 
33
+ start_btn.click(fn=get_problem, inputs=requirements, outputs=[description, chat_history], scroll_to_output=True)
34
+
35
+
36
  demo.launch()
llm.py ADDED
@@ -0,0 +1,63 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import json
2
+ import os
3
+
4
+ from openai import OpenAI
5
+
6
+ try:
7
+ with open(".env") as file:
8
+ for line in file:
9
+ key, value = line.strip().split("=", 1)
10
+ os.environ[key] = value
11
+ except FileNotFoundError:
12
+ pass
13
+
14
+ client = OpenAI()
15
+
16
+
17
+ def init_bot(problem=""):
18
+ prompt_system = (
19
+ "You are ChatGPT acting as a coding round interviewer for a big-tech company. "
20
+ "You are very strict. You don't give any hints until candidate is stuck or asks for it. "
21
+ "If a candidate made a mistake let them find and debug it themselves. "
22
+ "If a solution can be improved let candidate figure it out, you can ask directional questions but delay giving hints. "
23
+ "For each version of solution ask candidate about time and space complexity. "
24
+ "Strive to get the most optimal solution possible. "
25
+ "Always return the answer in json format with 2 fields: reply_to_candidate and hidden_note. "
26
+ "reply_to_candidate: the answer that will be shown to the candidate. "
27
+ "hidden_note: the concise hidden note that is not visible to the candidate but will be useful for final grading and feedback, "
28
+ "it can contain short code snippets, errors found, things to pay attention to. "
29
+ "'reply_to_candidate' can not be empty, 'hidden_note' can be empty if there is no new important information to note. "
30
+ "When the interview is finished and you don't have any more questions provide a very detailed feedback. "
31
+ "Don't wait for the candidate to ask for feedback, provide it as soon as you don't have any more question or if you see that the candidate can't solve the problem at all. "
32
+ "Provide detailed feedback using all the notes, mentioning not only the final solution but all issues and mistakes made during the interview. "
33
+ )
34
+
35
+ chat_history = [
36
+ {"role": "system", "content": prompt_system},
37
+ {"role": "system", "content": f"The candidate is solving the following problem: {problem}"},
38
+ ]
39
+
40
+ return chat_history
41
+
42
+
43
+ def get_problem(requirements="", client=client):
44
+ prompt_system = "You are ChatGPT acting as a coding round interviewer for a big-tech company. "
45
+ prompt_start = "Generate a coding problem that is expected to be solvable within 30 minutes. " "Follow the additional instructions: "
46
+ prompt_end = (
47
+ "Please provide the problem statement, example inputs and outputs, and any special constraints."
48
+ "Return the results in nicely formatted markdown."
49
+ )
50
+ full_prompt = f"{prompt_start} {requirements} {prompt_end}"
51
+
52
+ response = client.chat.completions.create(
53
+ model="gpt-3.5-turbo",
54
+ messages=[
55
+ {"role": "system", "content": prompt_system},
56
+ {"role": "user", "content": full_prompt},
57
+ ],
58
+ )
59
+
60
+ question = response.choices[0].message.content.strip()
61
+ chat_history = init_bot(question)
62
+
63
+ return question, chat_history
requirements.txt CHANGED
@@ -1 +1,2 @@
1
  gradio==4.26.0
 
 
1
  gradio==4.26.0
2
+ openai==1.19.0