Wanswan commited on
Commit
2bc4b3c
·
verified ·
1 Parent(s): 4bb1e77

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +16 -14
app.py CHANGED
@@ -93,7 +93,6 @@ async def respond(user_input, history, step, language, questions, followup_mode)
93
  await asyncio.sleep(0.03)
94
  return history, "", step, language, questions, False
95
 
96
- # Handle follow-up answer
97
  if followup_mode:
98
  comment_prompt = [
99
  {"role": "system", "content": f"Write a short, empathetic comment in {language} responding to the user's last answer."},
@@ -109,7 +108,6 @@ async def respond(user_input, history, step, language, questions, followup_mode)
109
 
110
  rand = random.random()
111
  if rand < 0.1:
112
- # Trigger second follow-up
113
  followup_prompt = [
114
  {"role": "system", "content": f"Ask one open-ended follow-up question in {language} based on the user's last answer."},
115
  history[-2],
@@ -122,12 +120,11 @@ async def respond(user_input, history, step, language, questions, followup_mode)
122
  )
123
  followup_question = followup_response.choices[0].message.content.strip()
124
 
125
- # Comment bubble
126
  history.append({"role": "assistant", "content": ""})
127
  for c in comment:
128
  history[-1]["content"] += c
129
  await asyncio.sleep(0.03)
130
- # Follow-up question bubble
131
  history.append({"role": "assistant", "content": ""})
132
  for c in followup_question:
133
  history[-1]["content"] += c
@@ -135,16 +132,19 @@ async def respond(user_input, history, step, language, questions, followup_mode)
135
 
136
  return history, "", step, language, questions, True
137
  else:
138
- # No more follow-ups, move to next main question
 
 
 
 
139
  next_question = f"{step+1}. {questions[step]}"
140
- content = comment + "\n\n" + next_question
141
  history.append({"role": "assistant", "content": ""})
142
- for c in content:
143
  history[-1]["content"] += c
144
  await asyncio.sleep(0.03)
 
145
  return history, "", step + 1, language, questions, False
146
 
147
- # Handle main question answer
148
  comment_prompt = [
149
  {"role": "system", "content": f"Write a short, personalized comment in {language} responding to the user's answer. Add a light emoji."},
150
  history[-2],
@@ -159,7 +159,6 @@ async def respond(user_input, history, step, language, questions, followup_mode)
159
 
160
  rand = random.random()
161
  if rand < 0.4:
162
- # Trigger first follow-up
163
  followup_prompt = [
164
  {"role": "system", "content": f"Ask one open-ended follow-up question in {language} based on the user's answer."},
165
  history[-2],
@@ -172,12 +171,11 @@ async def respond(user_input, history, step, language, questions, followup_mode)
172
  )
173
  followup_question = followup_response.choices[0].message.content.strip()
174
 
175
- # Comment bubble
176
  history.append({"role": "assistant", "content": ""})
177
  for c in comment:
178
  history[-1]["content"] += c
179
  await asyncio.sleep(0.03)
180
- # Follow-up question bubble
181
  history.append({"role": "assistant", "content": ""})
182
  for c in followup_question:
183
  history[-1]["content"] += c
@@ -185,13 +183,17 @@ async def respond(user_input, history, step, language, questions, followup_mode)
185
 
186
  return history, "", step, language, questions, True
187
  else:
188
- # No follow-up, move to next question
 
 
 
 
189
  next_question = f"{step+1}. {questions[step]}"
190
- content = comment + "\n\n" + next_question
191
  history.append({"role": "assistant", "content": ""})
192
- for c in content:
193
  history[-1]["content"] += c
194
  await asyncio.sleep(0.03)
 
195
  return history, "", step + 1, language, questions, False
196
 
197
  def init():
 
93
  await asyncio.sleep(0.03)
94
  return history, "", step, language, questions, False
95
 
 
96
  if followup_mode:
97
  comment_prompt = [
98
  {"role": "system", "content": f"Write a short, empathetic comment in {language} responding to the user's last answer."},
 
108
 
109
  rand = random.random()
110
  if rand < 0.1:
 
111
  followup_prompt = [
112
  {"role": "system", "content": f"Ask one open-ended follow-up question in {language} based on the user's last answer."},
113
  history[-2],
 
120
  )
121
  followup_question = followup_response.choices[0].message.content.strip()
122
 
 
123
  history.append({"role": "assistant", "content": ""})
124
  for c in comment:
125
  history[-1]["content"] += c
126
  await asyncio.sleep(0.03)
127
+
128
  history.append({"role": "assistant", "content": ""})
129
  for c in followup_question:
130
  history[-1]["content"] += c
 
132
 
133
  return history, "", step, language, questions, True
134
  else:
135
+ history.append({"role": "assistant", "content": ""})
136
+ for c in comment:
137
+ history[-1]["content"] += c
138
+ await asyncio.sleep(0.03)
139
+
140
  next_question = f"{step+1}. {questions[step]}"
 
141
  history.append({"role": "assistant", "content": ""})
142
+ for c in next_question:
143
  history[-1]["content"] += c
144
  await asyncio.sleep(0.03)
145
+
146
  return history, "", step + 1, language, questions, False
147
 
 
148
  comment_prompt = [
149
  {"role": "system", "content": f"Write a short, personalized comment in {language} responding to the user's answer. Add a light emoji."},
150
  history[-2],
 
159
 
160
  rand = random.random()
161
  if rand < 0.4:
 
162
  followup_prompt = [
163
  {"role": "system", "content": f"Ask one open-ended follow-up question in {language} based on the user's answer."},
164
  history[-2],
 
171
  )
172
  followup_question = followup_response.choices[0].message.content.strip()
173
 
 
174
  history.append({"role": "assistant", "content": ""})
175
  for c in comment:
176
  history[-1]["content"] += c
177
  await asyncio.sleep(0.03)
178
+
179
  history.append({"role": "assistant", "content": ""})
180
  for c in followup_question:
181
  history[-1]["content"] += c
 
183
 
184
  return history, "", step, language, questions, True
185
  else:
186
+ history.append({"role": "assistant", "content": ""})
187
+ for c in comment:
188
+ history[-1]["content"] += c
189
+ await asyncio.sleep(0.03)
190
+
191
  next_question = f"{step+1}. {questions[step]}"
 
192
  history.append({"role": "assistant", "content": ""})
193
+ for c in next_question:
194
  history[-1]["content"] += c
195
  await asyncio.sleep(0.03)
196
+
197
  return history, "", step + 1, language, questions, False
198
 
199
  def init():