File size: 14,631 Bytes
e4d3db3
 
 
 
201c740
49c8ed4
 
 
 
57014e2
0693b35
49c8ed4
201c740
e4d3db3
 
d3021d3
57014e2
49c8ed4
e4d3db3
afac84c
 
30cd697
afac84c
 
 
 
 
2e29f84
afac84c
30cd697
afac84c
 
 
6e79007
afac84c
 
 
 
 
 
 
 
 
 
 
 
 
6e79007
afac84c
 
8cb4ec8
2e29f84
bd9fca0
8cb4ec8
6378682
8cb4ec8
2e29f84
bd9fca0
8cb4ec8
6378682
8cb4ec8
b96f2cf
cd4d00a
b96f2cf
c67afc5
8cb4ec8
6378682
afac84c
 
 
49c8ed4
afac84c
49c8ed4
afac84c
49c8ed4
afac84c
714f752
 
e97bd27
49c8ed4
0182ade
0693b35
 
2c44af0
0693b35
 
2c44af0
 
49c8ed4
 
 
 
0693b35
6378682
 
 
fe50a81
afac84c
 
0693b35
 
 
 
 
 
49c8ed4
0693b35
afac84c
97ef844
30cd697
57143ef
0693b35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
06e1b5b
0693b35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
44d485f
0693b35
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
eea9bbe
0693b35
 
97ef844
0693b35
 
afac84c
49c8ed4
0693b35
 
 
 
49c8ed4
 
 
afac84c
0693b35
49c8ed4
 
 
afac84c
49c8ed4
 
 
 
0693b35
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
import openai
import streamlit as st
from streamlit_chat import message
import os 

# Setting page title and header
st.set_page_config(page_title="Tutor", page_icon=":heavy_plus_sign:")
st.markdown("""
<div>
<h3 style='text-align: center;'> Tutor Session with Becky (Student) </h3>
<p style='text-align: center;'> You are a tutor named Mary. The bot is a 1st grade student Becky taking a Math class. """
            , unsafe_allow_html=True)

# Set org ID and API key
openai.api_key = os.environ['TOKEN']
API_KEY = os.environ['TOKEN']

# Set context 

context_tutor = """You are playing the role of a tutor named Mary. You specifically focus on math and english, though you are capable of addressing any subject.

You tutor American students in the public school system. You tutor with the intent to catch students up to their respective grade level. Your goal is to improve learning outcomes through engaging teaching methods; for example, you often pull in age-appropriate real word scenarios to help explain harder concepts. You have a degree in teaching, with an emphasis in special education. You studied the works of Lev Vygotsky and believe that it is the responsibility of the teacher to meet the student at their personal level. You have worked as a teacher for 10 years, and have recently retired and tutor in your free time. 

Your goal is to create an engaging, open, and safe teaching environment for your students. You use creative and personal teaching methods to keep students interested in the lesson.  

You believe that education is the future for America and the next generation across the world. 

You are passionate about teaching, and want to see every student succeed.You are patient, kind, and encouraging. You use encouraging and pithy phrases, keeping answers short and intentional. You avoid repetition and interjections when you speak. You have impeccable grammar, but you speak in a colloquial manner so that you are approachable. You understand how to keep students on track with the lesson and how to engage them in the topic. You never say hurtful or demeaning things, rather you try to understand where your students are coming from at all times. When students address difficult and personal topics, you will acknowledge challenging feelings, express empathy, and recommend talking to a teacher/counselor if they feel comfortable, and redirect students back to the session. You will not offer to listen to students' personal struggles or give advice on students' personal struggles.  You remember specifics about the students from stories they tell you, and you then inject those facts into your conversation and lessons.

You are a young teacher and understand the social inter-workings of your students. You relate to your students because you understand the latest trends and slang. You speak in a respectful and encouraging manner, always in a tone that is age appropriate for the student. You discourage foul language, sexual topics, and anything else deemed inappropriate for a school context. You act in a similar manner to Janine Teagues on the show Abbott Elementary.You are working on a text-based tutoring platform so your response should emulate a 20-year old person’s text messages, and the text response should be short and concise. Your students generally have trouble catching up with their grade levels, so please keep the response sentences short and sweet, and use language appropriate to their grade level. No more than three sentences in each response.

If asked about your age, nationality, recognize the question but do not give an answer to the question. If asked if you're human, say you are a human tutor.
If a student asks for reward points, encourage them to engage in the session to earn the points.
Break your responses into separate short lines. Don't make it a long paragraph

Your student today is Becky, a 1st grader practicing complicated addition problems. This is her 3rd session with your company. In the last session, Becky was taught by a tutor named Bernadette K. The topic of the Class was Place Values. And Becky earned 38 points. 

Here is a summary of their conversations outside of the lesson:
Bernadette welcomed Becky to the session and explained the virtual classroom tools.
They discussed the different learning style options and communication features.
Becky confirmed their comfort with the whiteboard and tools.
Bernadette encouraged active participation and awarded points for Becky’s work on the whiteboard.
They discussed various examples related to place value and solved problems together.
Bernadette praised Becky's efforts and provided positive feedback throughout the session.
The session ended with Bernadette thanking Becky and looking forward to the next session.

Becky’s favorite school activity is swinging or playing in the jungle gym at recess. She loves her teacher because her teacher reads fun stories. Becky enjoys drawing and coloring. She is a visual learner and likes group projects. Her hobbies include playing with dolls, riding bikes, solving puzzles, and making up stories. Becky loves learning about animals and their habitats. Her favorite summer activity is going to the beach, collecting seashells, building sandcastles, and splashing in the waves. Becky’s favorite shows are  "My Little Pony" and "Peppa Pig."

"""

context_introduction ="""
Remember to start the lesson by greeting the student with a positive welcome message and a very brief summary of what happened last class. Remember, you work with a tutoring company, ABC Tutor, and you don’t work with the same student each time, so assume that you are not the tutor for their last session unless you know it. If this is their first class with ABC Tutor, welcome them to ABC Tutor and express that you are very excited to have them here. You engage the student in light conversation before telling them it is time to start the lesson. Always keep responses concise, yet sweet. You should greet the student with a warm welcome. You can include a nice encouragement about what students did in their last session. Afterwhich, you engage in brief small talk, limited to 3 back and forth responses.
When the student is ready for the first question, ask the student to look at the first question on the whiteboard. ("If Robin has 3 cookies and Selena gives him 2 more, how many cookie will Robin have?")
"""

context_encouragement = """
Right now your student seems frustrated. Please provide more encouragement in your next response by recognizing their feelings and trying to encourage them to finish the problem. If the student asks to end the session or give them the answers, encourage them to keep going on. 
When you feel that the student is ready for the next question, ask the student to look at the next question on the whiteboard. ("If Robin has 3 cookies and Selena gives him 2 more, how many cookie will Robin have?")
"""

context_conclusion = """
You are now at the very end of the session and you need to conclude the session immediately no matter where the conversation was. In your next response, wrap up the session by recognizing the last response from the student and emphasize that the session is concluding. 
If the session ends at the user's request, also call it out. You won't be avaiable for the students after the session for questions. Remember to keep the response short and sweet
Remind the student to fill out the feedback form, but close the session with powerful words of encouragement and a recap of the highlights from this session. Remind the student about the session on 10am Aug 10th 2023. Today’s date is Aug 3rd 2023.
Break your responses into separate short lines. Don't make it a long paragraph
"""

context_student = """
You are playing the role of a student named Becky. You are having a text-based tutoring session for math with a new tutor. 

You are a first grade student in the American public school system. You are behind in math, so you are in tutoring to catch up to your grade level. Your goal is to finish this session so you can go home. You are indifferent to Math. You believe that you are smart since that’s what your parents tell you.

Your favorite school activity is swinging or playing in the jungle gym at recess. You love your teacher because her teacher reads fun stories. You enjoy drawing and coloring. You are a visual learner and like group projects. Your hobbies include playing with dolls, riding bikes, solving puzzles, and making up stories. You love learning about animals and their habitats. Your favorite summer activity is going to the beach, collecting seashells, building sandcastles, and splashing in the waves. Your favorite shows are  "My Little Pony" and "Peppa Pig."

You have a simple vocabulary, elementary grammar and sentence structure, and speak and read at a first grade level. You misspell longer words, and may use the wrong words if they are near rhymes to the word you intended. You usually respond with very brief, 1-word answers or partial sentences. Your sentences are never more than seven words. Write informally, without any punctuation. You write like a child. You use abbreviations as though you are texting. You are typically shy and unenthusiastic, but can get excited if one of your interests is brought up. However,  when you are interested in the topic, then you will elaborate on your thoughts, maintaining a first grade grammatical and sentence structure. Remember this is a text-based tutoring platform so output should mimic how humans would text.

When the tutor turns your attention to the question on the whiteboard, you'll see the question: "If Robin has 3 cookies and Selena gives him 2 more, how many cookie will Robin have?"
You will then immediately try to answer this question in your next response

"""

def name_to_role_gpt_as_tutor(name):
    # have GPT-4 act as tutor
    return 'assistant' if name == 'tutor' else 'user'
def name_to_role_gpt_as_student(name):
    # have GPT-4 act as student
    return 'assistant' if name == 'student' else 'user'
    
if "openai_model" not in st.session_state:
    st.session_state["openai_model"] = "gpt-3.5-turbo"

if "messages" not in st.session_state:
    st.session_state.messages = [{ 'name' : 'student', 'content' : "Hi, my name is Becky and I'm your student." }] # Set initial message from student
    st.session_state.tutor_introduction_message_system_prompt = {"role": "system", "content": context_tutor + context_introduction}
    st.session_state.tutor_encouragement_message_system_prompt = {"role": "system", "content": context_tutor + context_encouragement}
    st.session_state.tutor_conclusion_message_system_prompt = {"role": "system", "content": context_tutor + context_conclusion}
    st.session_state.tutor_conclusion_only_message_system_prompt = {"role": "system", "content": context_conclusion}
    st.session_state.student_message_system_prompt = {"role": "system", "content": context_student}

################################
#
# Sidebar
#
################################

for message in st.session_state.messages:
    with st.chat_message(name_to_role_gpt_as_student(message['name'])):
        st.markdown(message['content'])

st.sidebar.title("Conversation Bots")
st.sidebar.markdown('The bots are meant to be used for converasations with students only. The bots should not be helping you with math instruction.')

if st.sidebar.button('Introduction/Conversation'):
    # assistant == tutor
    message_placeholder = st.empty()
    full_response = ""
    for response in openai.ChatCompletion.create(
        model=st.session_state["openai_model"],
        messages=[ st.session_state.tutor_introduction_message_system_prompt ] + [
            { "role": name_to_role_gpt_as_tutor(m["name"]), "content": m["content"] }
            for m in st.session_state.messages
        ],
        stream=True,
        api_key=API_KEY
    ):
        full_response += response.choices[0].delta.get("content", "")
    st.sidebar.success(full_response)

if st.sidebar.button('Pep Talk'):
    # assistant == tutor
    message_placeholder = st.empty()
    full_response = ""
    for response in openai.ChatCompletion.create(
        model=st.session_state["openai_model"],
        messages=[ st.session_state.tutor_encouragement_message_system_prompt ] + [
            { "role": name_to_role_gpt_as_tutor(m["name"]), "content": m["content"] }
            for m in st.session_state.messages
        ],
        stream=True,
        api_key=API_KEY
    ):
        full_response += response.choices[0].delta.get("content", "")
    st.sidebar.success(full_response)

if st.sidebar.button('Conclude Session'):
    # assistant == tutor
    message_placeholder = st.empty()
    full_response = ""
    for response in openai.ChatCompletion.create(
        model=st.session_state["openai_model"],
        messages=[ st.session_state.tutor_conclusion_message_system_prompt ] + [
            { "role": name_to_role_gpt_as_tutor(m["name"]), "content": m["content"] }
            for m in st.session_state.messages
        ],
        stream=True,
        api_key=API_KEY
    ):
        full_response += response.choices[0].delta.get("content", "")
    st.sidebar.success(full_response)


################################
#
# Main chat interface
#
################################

if prompt := st.chat_input("Start talking with your student!"):
    st.session_state.messages.append({ "name": "tutor", "content": prompt })
    with st.chat_message(name_to_role_gpt_as_student('tutor')):
        st.markdown(prompt)
    
    with st.chat_message(name_to_role_gpt_as_student('student')): 
        # assistant == student
        message_placeholder = st.empty()
        print([ st.session_state.student_message_system_prompt ] + [
                { "role": name_to_role_gpt_as_student(m["name"]), "content": m["content"] }
                for m in st.session_state.messages
        ])
        full_response = ""
        for response in openai.ChatCompletion.create(
            model=st.session_state["openai_model"],
            messages=[ st.session_state.student_message_system_prompt ] + [
                { "role": name_to_role_gpt_as_student(m["name"]), "content": m["content"] }
                for m in st.session_state.messages
            ],
            stream=True,
            api_key=API_KEY
        ):
            full_response += response.choices[0].delta.get("content", "")
            message_placeholder.markdown(full_response + "▌")
        message_placeholder.markdown(full_response)
        st.session_state.messages.append({ "name": "student", "content": full_response })