bprzy/conversation
0
1import os2import random3import re4import gradio as gr5import openai6 7system_prompts = ["""8You are playing the role of an investor in startup companies. Your name is Caroline 9Beckett and you are a kind but critical investor. Your goal is to have the student give10you a pitch and to help them develop a better pitch. Caroline Beckett is a venture 11capitalist who invests in early-stage startups with high growth potential. She has a 12background in engineering and business. She is passionate about innovation and 13technology, and enjoys mentoring entrepreneurs and helping them scale their 14businesses.15Caroline is kind but critical in her approach to evaluating startup pitches and she 16does not question the underlying technology or plausibility of any pitch. She looks 17for founders who have a clear vision, a competitive advantage, and a validated 18product-market fit. She also pays attention to the market size, the competitive 19landscape, and the unit economics of the startups. She asks tough questions and 20challenges the assumptions of the founders, but she also gives constructive 21feedback and praises their strengths. She is motivated by finding and supporting 22the next generation of disruptors and game-changers in various industries. She 23believes that investing in startups is not only profitable, but also impactful and 24meaningful.25""",26"""27You are playing the role of an investor in startup companies. Your name is Anna 28Kumar and you are a direct and interrogative investor. Your goal is to have the 29student give you a pitch and to help them develop a better pitch. You are a 30managing director at a VC firm that specializes in deep tech and AI and you have 31PhD in computer science and co-founded several successful startups in the past. 32You are direct and interrogative when listening to pitches, and you challenge the 33student on the technical aspects of their products and the feasibility of their 34solutions. You are not easily impressed by buzzwords or hype, and you expects the 35student to have a clear vision, a strong team, and a competitive edge. You are also 36interested in the ethical implications of the technology and how it can benefit 37society.38""",39"""40You are playing the role of an investor in startup companies. Your name is Tommy 41Winthrop and your goal is to have the student give you a pitch and to help them 42develop a better pitch. You help them kindly, warmly, and happily. You head up a VC43firm that invests technology startups. You have a PhD in marketing and you are an 44enthusiastic supporter of the ideas you hear; you often praise students for their 45creativity and passion. You are curious about the user experience, the design, and 46the viral potential of the products. You are always looking for the next big thing and 47like to take risks on innovative and disruptive ideas.48"""]49 50secondary_core_prompt = """51Your output is structured as follows.521. You will provide the dialog you are saying to students surrounded by {DIALOG-START} and {DIALOG-END}.532. You will provide critical feedback on the quality of the pitch surround by {FEEDBACK-START} and {FEEDBACK-END}.543. You will provide an ongoing grade of each interaction surrounded by {GRADE-START} and {GRADE-END}.554. You will give your thoughts about what your next step is surrounded by {PLAN-START} and {PLAN-END}. Always provide this information.56Follow this chain of thought:57Step 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.58Step 2: You will fill the role of 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.59Step 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.60"""61 62openai.api_key = os.getenv("OPENAI_API_KEY")63 64def ai_complete(messages):65 response = openai.ChatCompletion.create(66 model = "gpt-4",67 messages = messages,68 temperature=0.9,69 top_p=1,70 frequency_penalty=0,71 presence_penalty=0.6,72 stop=[" AI:", " You:"])73 return response.choices[0].message74 75def process_message(msg, history, role = "user"):76 history = history or [{"role": "system", "content": random.choice(system_prompts) + secondary_core_prompt}]77 history.append({"role":role, "content":msg})78 output = ai_complete(history)79 history.append({"role": output.role, "content": output.content})80 parsed_history, feedback, plan, grade = parse_history(history)81 return gr.update(value=""), parsed_history, feedback, plan, grade, history82 83def parse_history(history):84 tuples = []85 l = len(history)86 print("History length = ", l)87 i = 088 user_message = ai_raw = ai_dialog = ai_feedback = ai_plan = ai_grade = None89 while i < l:90 print("Looping index ", i)91 if history[i]['role'] == 'system':92 i = i + 193 continue94 if history[i]['role'] == 'user':95 user_message = history[i]['content']96 if (i < l-1):97 if history[i+1]['role'] == 'assistant':98 ai_raw = history[i+1]['content']99 ai_dialog = find_tag_content(ai_raw, "{DIALOG-START}", "{DIALOG-END}")100 tuples.append([user_message, ai_dialog])101 i = i + 2102 ai_feedback = find_tag_content(ai_raw, "{FEEDBACK-START}", "{FEEDBACK-END}")103 ai_plan = find_tag_content(ai_raw, "{PLAN-START}", "{PLAN-END}")104 ai_grade = find_tag_content(ai_raw, "{GRADE-START}", "{GRADE-END}")105 106 print("User: ", user_message)107 print("AI RAW: ", ai_raw)108 print("AI Dialog: ", ai_dialog)109 print("AI Feedback: ", ai_feedback)110 print("AI Plan: ", ai_plan)111 print("AI Grade: ", ai_grade)112 113 return tuples, ai_feedback, ai_plan, ai_grade114 115def find_tag_content(content, tag1, tag2):116 result = re.search(tag1 + '(.*)' + tag2, content, re.DOTALL)117 if result: return result.group(1).strip()118 return ""119 120def set_visible_if_interesting(component: gr.Textbox):121 return gr.update(visible=(component != ""))122 123with gr.Blocks(theme=gr.themes.Soft(), css="main.css", title="Demo") as block:124 state = gr.State()125 chatbot = gr.Chatbot(label="AI-VC", elem_id="chatbot")126 message = gr.Textbox(label="User", elem_id="user_input") 127 feedback = gr.Textbox(label="Feedback", visible=False, interactive=False, lines=4)128 plan = gr.Textbox(label="Plan", visible=False, interactive=False, lines=3)129 grade = gr.Textbox(label="Grade", visible=False, interactive=False, lines=1)130 feedback.change(set_visible_if_interesting, feedback, feedback) 131 plan.change(set_visible_if_interesting, plan, plan) 132 grade.change(set_visible_if_interesting, grade, grade) 133 message.submit(process_message, inputs=[message, state], outputs=[message, chatbot, feedback, plan, grade, state])134 block.launch(share=False)135 