Skip to content

Commit

Permalink
fix but with human moderator setting and remove survey for moderator …
Browse files Browse the repository at this point in the history
…side
  • Loading branch information
wise-east committed Jun 21, 2023
1 parent 27a8b8d commit 2aa466d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 11 deletions.
8 changes: 8 additions & 0 deletions boteval/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,6 +268,7 @@ def launch_topic(topic_id):
thread = service.get_thread_for_topic(user=FL.current_user, topic=topic, create_if_missing=True)
if thread is None:
err_msg = 'Another user is loading this chat topic. Please retry after 10 seconds!'
log.error(err_msg)
return err_msg, 400

return flask.redirect(url_for('app.get_thread', thread_id=thread.id))
Expand Down Expand Up @@ -304,6 +305,8 @@ def get_thread(thread_id, request_worker_id=None, focus_mode=False):

if req_worker_is_human_mod:
instructions_for_user = service.human_mod_instructions
# add one more turn for human mod:
remaining_turns = remaining_turns + 1
log.info('Human moderator instructions should be used for user:', request_worker_id)

if thread.max_human_users_per_thread == 1:
Expand Down Expand Up @@ -508,6 +511,11 @@ def mturk_landing(topic_id): # this is where mturk worker should land first
}
chat_thread = service.get_thread_for_topic(user=FL.current_user, topic=topic, create_if_missing=True,
ext_id=assignment_id, ext_src=ext_src, data=data)

if chat_thread is None:
err_msg = 'Another user is loading this chat topic. Please retry after 10 seconds!'
log.error(err_msg)
return err_msg, 400

log.info(f'chat_thread: {chat_thread}')
log.info(f'worker_id: {worker_id}')
Expand Down
16 changes: 11 additions & 5 deletions boteval/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def bot_init_reply(self, thread):
db.session.commit()

episode_done = False
thread.thread_state = 2

return reply, episode_done

Expand Down Expand Up @@ -450,17 +449,17 @@ def get_thread_for_topic(self, user, topic: ChatTopic, create_if_missing=True,
"""

# log.info('data is: ', data)
log.info('topic.human_moderator is: ', topic.human_moderator)
log.info(f'topic.human_moderator is: {topic.human_moderator}')

if topic.human_moderator == 'yes' and data is not None and data.get(ext_src) is not None:
cur_user_is_qualified = self.crowd_service.is_worker_qualified(user_worker_id=user.id,
qual_name='human_moderator_qualification')

if cur_user_is_qualified:
log.info("Assign human moderator role to worker_id: ", user.id)
log.info(f"Assign human moderator role to worker_id: {user.id}")
user.role = User.ROLE_HUMAN_MODERATOR
else:
log.info("Not Assign human moderator role to worker_id: ", user.id)
log.info(f"Not Assign human moderator role to worker_id: {user.id}")

topic_threads = ChatThread.query.filter_by(topic_id=topic.id).all()
# TODO: appply this second filter directly into sqlalchemy
Expand All @@ -487,7 +486,7 @@ def get_thread_for_topic(self, user, topic: ChatTopic, create_if_missing=True,
# Mark the thread as "is being created".
# This is to prevent other users from joining the thread at the same time.
if tt.thread_state == 1:
log.info("thread is being created")
log.error("thread is being created")
return None

log.info('human_user_2 join thread!')
Expand Down Expand Up @@ -582,6 +581,7 @@ def get_thread_for_topic(self, user, topic: ChatTopic, create_if_missing=True,
thread.submit_url_dict[user.id] = data.get(ext_src).get('submit_url')

thread.thread_state = 1
log.info("Set thread state to 1")
log.info(f'1st user is: {user.id}, 1st speaker is: {thread.speakers[user.id]}')

thread.users.append(user)
Expand All @@ -601,6 +601,12 @@ def get_thread_for_topic(self, user, topic: ChatTopic, create_if_missing=True,
msg = ChatMessage(text=text, user_id=self.context_user.id, thread_id=thread.id, is_seed=True, data=data)
db.session.add(msg)
thread.messages.append(msg)
thread.thread_state = 2

# if moderator:
if topic.human_moderator == 'yes':
log.info("Set thread state to 2")

db.session.merge(thread)
db.session.flush()
db.session.commit()
Expand Down
29 changes: 23 additions & 6 deletions boteval/templates/user/chatui_two_users.html
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@
</li>
</ul>
{% if focus_mode %} <input name="focus_mode" value="True" type="hidden" /> {%endif%}
<input type="submit" value="Submit" class="btn btn-primary my-4 ml-2" {{is_disabled}} />
</form>
<input type="submit" value="Submit" form="ratings-form" class="btn btn-primary my-4 ml-2" {{is_disabled}} />
<hr />
</div>
<div {% if not cur_user.is_admin %} style="display:none" {%endif%}
Expand Down Expand Up @@ -282,10 +282,28 @@
*/
function refresh_view() {
scroll_chat_to_bottom();
$('#ratings-view').hide()
if (remaining_turns < 1 || Boolean({{ 'true' if cur_user.is_admin else 'false' }})) {
$('#end_info').show() // show end info
$('#next_msg_form').hide()
$('#waiting_info').hide()

// if the current user is the moderator, delete the form
if (reply_as_user == "Moderator") {
// delete all content of ratings-form
$('#ratings-form').empty()
waiting_for_other_human_reply = false;
waiting_for_bot_reply = false;
}

console.log("waiting_for_other_human_reply: ", waiting_for_other_human_reply)
console.log("waiting_for_bot_reply: ", waiting_for_bot_reply)
if (waiting_for_bot_reply || waiting_for_other_human_reply){

} else {
$('#end_info').show() // show end info
$('#next_msg_form').hide()
$('#waiting_info').hide()
$('#ratings-view').show()
}

} else { // ongoing conversation
$('#end_info').hide()
if (waiting_for_bot_reply || waiting_for_other_human_reply) { // but wating for bot or other human reply
Expand Down Expand Up @@ -414,8 +432,7 @@
console.log("posted")
try {
remaining_turns--;
if (remaining_turns == 0 || reply['episode_done']) {
$('#ratings-view').show();
if (reply['episode_done']) {
remaining_turns = 0;
}
$('#remaining-turns-count').html(remaining_turns);
Expand Down

0 comments on commit 2aa466d

Please sign in to comment.