bprzy commited on
Commit
bba6203
·
1 Parent(s): 945c107

Updates AI-VC

Browse files
Files changed (3) hide show
  1. .vscode/settings.json +3 -0
  2. app.py +99 -39
  3. main.css +9 -0
.vscode/settings.json ADDED
@@ -0,0 +1,3 @@
 
 
 
 
1
+ {
2
+ "python.analysis.typeCheckingMode": "off"
3
+ }
app.py CHANGED
@@ -1,50 +1,110 @@
1
  import os
2
- import openai
 
3
  import gradio as gr
 
4
 
5
- openai.api_key = os.getenv("OPENAI_API_KEY")
6
-
7
- start_sequence = "\nCoach:"
8
- restart_sequence = "\nMe:"
 
 
 
 
 
 
 
 
 
 
9
 
10
- prompt = "The following is a conversation with an instructor. The instructor is an expert in opportunity cost. You will act as the instructor, I will be the student."
11
 
12
- def completion_create(prompt):
13
-
14
- response = openai.Completion.create(
15
- model = "text-davinci-003",
16
- prompt=prompt,
17
  temperature=0.9,
18
- max_tokens=150,
19
  top_p=1,
20
  frequency_penalty=0,
21
  presence_penalty=0.6,
22
- stop=[" Coach:", " Me:"])
23
- print("Raw response: ")
24
- print(response)
25
- return response.choices[0].text
26
-
27
- def chat_clone(input, history):
28
- history = history or []
29
- s = list(sum(history, ()))
30
- print(s)
31
- s.append(input)
32
- inp = ' '.join(s)
33
- output = completion_create(inp)
34
- if (len(output) < 5): print("ERROR, short output")
35
- print(output)
36
- history.append((input, output))
37
- return history, history
38
-
39
- block = gr.Blocks(css="main.css", title="Coaching Demo")
40
-
41
- with block:
42
- gr.Markdown("""<h1><center>Coaching Demo</center></h1>""")
43
- chatbot = gr.Chatbot()
44
- input = gr.Textbox(placeholder=None,value="")
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
45
  state = gr.State()
46
- input.submit(chat_clone, inputs=[input, state], outputs=[chatbot, state])
47
- submit = gr.Button("Ask")
48
- submit.click(chat_clone, inputs=[input, state], outputs=[chatbot, state])
49
 
50
- block.launch(share=False,debug=True)
 
 
 
 
 
 
 
 
 
 
 
1
  import os
2
+ import random
3
+ import re
4
  import gradio as gr
5
+ import openai
6
 
7
+ system_prompt = """
8
+ You are playing the role of an investor in startup companies. Your name is Caroline Beckett and you are a kind but critical investor. Your goal is to have the student give you a pitch and to help them develop a better pitch. Caroline Beckett is a venture capitalist who invests in early-stage startups with high growth potential. She has a background in engineering and business. She is passionate about innovation and technology, and enjoys mentoring entrepreneurs and helping them scale their businesses.
9
+ Caroline is kind but critical in her approach to evaluating startup pitches. She looks for founders who have a clear vision, a competitive advantage, and a validated product-market fit. She also pays attention to the market size, the competitive landscape, and the unit economics of the startups. She asks tough questions and challenges the assumptions of the founders, but she also gives constructive feedback and praises their strengths. She is motivated by finding and supporting the next generation of disruptors and game-changers in various industries. She believes that investing in startups is not only profitable, but also impactful and meaningful.
10
+ First, introduce yourself as Caroline Beckett, an investor interested in the student's idea. Tell students that you'd like to hear their pitch but do not specify what they should include in that pitch. Your job is to help students understand and practice how to create an elevator pitch. This means that if students are missing elements you can ask them questions that help them fill in those elements.
11
+ Your output is structured as follows.
12
+ 1. You will provide the dialog you are saying to students surrounded by {DIALOG-START} and {DIALOG-END}.
13
+ 2. You will provide critical feedback on the quality of the pitch surround by {FEEDBACK-START} and {FEEDBACK-END}.
14
+ 3. You will provide an ongoing grade of each interaction surrounded by {GRADE-START} and {GRADE-END}.
15
+ 4. You will give your thoughts about what your next step is surrounded by {PLAN-START} and {PLAN-END}. Always provide this information.
16
+ Follow this chain of thought:
17
+ Step 1: An elevator pitch should have the following components: a target audience, a need, a product name, a product category, a key benefit, a competitive advantage.
18
+ Step 2: You will fill the role of Caroline Beckett, the investor who interrogates the student with the secret goal of teaching the student how to create a really effective elevator pitch. You will not divulge this goal to the student but stay within the role throughout the entire interaction. After 5 interactions you will record your "grade" for the student but not show the student this grade. You will also record detailed feedback about what they could do better and what they did well. You will designate students into three buckets: struggling, pretty good, excellent. After 5 interactions you will thank the student and end the conversation.
19
+ Step 3: Your rules as you roleplay a VC investor: You should guide students in an open-ended way. Do not provide answers or solutions to problems but help students generate their own answers by asking leading questions. Ask students to explain their thinking. If the student is struggling or get the answer wrong try asking them to do part of the task or remind the student of their goal and give them a hint about how to improve their pitch. If students improve their pitch in the scenario then praise them and act more and more convinced of their ideas; show excitement and hint that you may be willing to talk further and invest. If the student struggles, then tell them they'll need to refine their pitch and give them some ideas to think about.
20
+ """
21
 
22
+ openai.api_key = os.getenv("OPENAI_API_KEY")
23
 
24
+ def ai_complete(messages):
25
+ response = openai.ChatCompletion.create(
26
+ #model = "gpt-3.5-turbo",
27
+ model = "gpt-4",
28
+ messages = messages,
29
  temperature=0.9,
 
30
  top_p=1,
31
  frequency_penalty=0,
32
  presence_penalty=0.6,
33
+ stop=[" AI:", " You:"])
34
+ return response.choices[0].message
35
+
36
+ def process_message(msg, history, role = "user"):
37
+ history = history or [{"role": "system", "content": system_prompt}]
38
+
39
+ history.append({"role":role, "content":msg})
40
+
41
+ output = ai_complete(history)
42
+ history.append({"role": output.role, "content": output.content})
43
+
44
+ parsed_history, feedback, plan, grade = parse_history(history)
45
+
46
+ return gr.update(value=""), parsed_history, feedback, plan, grade, history
47
+
48
+ def parse_history(history):
49
+ tuples = []
50
+ l = len(history)
51
+ print("History length = ", l)
52
+ i = 0
53
+ user_message = ai_raw = ai_dialog = ai_feedback = ai_plan = ai_grade = None
54
+ while i < l:
55
+ print("Looping index ", i)
56
+ if history[i]['role'] == 'system':
57
+ i = i + 1
58
+ continue
59
+ if history[i]['role'] == 'user':
60
+ user_message = history[i]['content']
61
+ if (i < l-1):
62
+ if history[i+1]['role'] == 'assistant':
63
+ ai_raw = history[i+1]['content']
64
+ ai_dialog = find_tag_content(ai_raw, "{DIALOG-START}", "{DIALOG-END}")
65
+ tuples.append([user_message, ai_dialog])
66
+ i = i + 2
67
+ ai_feedback = find_tag_content(ai_raw, "{FEEDBACK-START}", "{FEEDBACK-END}")
68
+ ai_plan = find_tag_content(ai_raw, "{PLAN-START}", "{PLAN-END}")
69
+ ai_grade = find_tag_content(ai_raw, "{GRADE-START}", "{GRADE-END}")
70
+
71
+ print("User: ", user_message)
72
+ print("AI RAW: ", ai_raw)
73
+ print("AI Dialog: ", ai_dialog)
74
+ print("AI Feedback: ", ai_feedback)
75
+ print("AI Plan: ", ai_plan)
76
+ print("AI Grade: ", ai_grade)
77
+
78
+ return tuples, ai_feedback, ai_plan, ai_grade
79
+
80
+ def find_tag_content(content, tag1, tag2):
81
+ tag1 = tag1.replace('[', '\[')
82
+ tag1 = tag1.replace(']', '\]')
83
+ tag2 = tag2.replace('[', '\[')
84
+ tag2 = tag2.replace(']', '\]')
85
+ result = re.search(tag1 + '(.*)' + tag2, content)
86
+ if result: return result.group(1).strip()
87
+ return ""
88
+
89
+ def set_visible_if_interesting(component: gr.Textbox):
90
+ return gr.update(visible=(component != ""))
91
+
92
+ with gr.Blocks(theme=gr.themes.Soft(), css="main.css", title="Demo") as block:
93
+
94
+ #gr.Markdown("""<h1><center>Demo</center></h1>""")
95
+
96
  state = gr.State()
97
+ chatbot = gr.Chatbot(label="AI-VC", elem_id="chatbot")
98
+ message = gr.Textbox(label="User", elem_id="user_input")
 
99
 
100
+ feedback = gr.Textbox(label="Feedback", visible=False, interactive=False, lines=4)
101
+ plan = gr.Textbox(label="Plan", visible=False, interactive=False, lines=3)
102
+ grade = gr.Textbox(label="Grade", visible=False, interactive=False, lines=1)
103
+
104
+ feedback.change(set_visible_if_interesting, feedback, feedback)
105
+ plan.change(set_visible_if_interesting, plan, plan)
106
+ grade.change(set_visible_if_interesting, grade, grade)
107
+
108
+ message.submit(process_message, inputs=[message, state], outputs=[message, chatbot, feedback, plan, grade, state])
109
+
110
+ block.launch(share=True)
main.css ADDED
@@ -0,0 +1,9 @@
 
 
 
 
 
 
 
 
 
 
1
+ footer {
2
+ visibility: hidden
3
+ }
4
+ #chatbot {
5
+ font-size: 1em;
6
+ }
7
+ #user_input {
8
+ font-size: 1em;
9
+ }