Skip to content

Commit

Permalink
2023/06/09 change
Browse files Browse the repository at this point in the history
  • Loading branch information
tkmtnt7000 authored and JSK fetch user committed Jun 10, 2023
1 parent a48667f commit 9e4b988
Showing 1 changed file with 18 additions and 4 deletions.
22 changes: 18 additions & 4 deletions database_talker/scripts/hoge.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def make_reply(self, message, lang="en", startdate=datetime.datetime.now(JST)-da
# sort based on similarity with 'query'
chat_msgs_sorted = sorted(results, key=lambda x: x['similarity'], reverse=True)

rospy.logerr("chat_msgs_sorted: {}".format(chat_msgs_sorted))
#rospy.logerr("chat_msgs_sorted: {}".format(chat_msgs_sorted))
if len(chat_msgs_sorted) == 0:
rospy.logwarn("no chat message was found")
else:
Expand Down Expand Up @@ -195,6 +195,7 @@ def make_reply(self, message, lang="en", startdate=datetime.datetime.now(JST)-da

# make prompt
prompt = 'if you are a pet and someone tells you \"' + message + '\" when we went together, ' + \
'and ' + 'you remembered that someone said "' + self.translate(text, dest="en").text + '" ' + \
'and ' + reaction + ' in your memory of that moment, what would you reply? '+ \
'Show only the reply in {lang}'.format(lang={'en': 'English', 'ja':'Japanese'}[lang])
loop = 0
Expand Down Expand Up @@ -251,7 +252,7 @@ def write_image_with_annotation(self, filename, best_result, prompt, smach_state
rospy.logwarn("save images to {}".format(filename))


def query_dialogflow(self, query, start_time, end_time, limit=30, threshold=0.0):
def query_dialogflow(self, query, start_time, end_time, limit=100, threshold=0.0):
results = []
for message_type, message_value in [('dialogflow_task_executive/DialogTextActionResult', 'msg.result.response.query'),
('smach_msgs/SmachContainerStatus', 'msg.active_states[0].lower()'),
Expand Down Expand Up @@ -283,6 +284,8 @@ def query_dialogflow(self, query, start_time, end_time, limit=30, threshold=0.0)
msg = deserialise_message(msg)
meta = json.loads(meta.pairs[0].second)
timestamp = datetime.datetime.fromtimestamp(meta['timestamp']//1000000000, JST)
### kei okada 2023/06/09
timestamp = datetime.datetime.fromtimestamp(meta['inserted_at']['$date']//1000, JST)
message = eval(message_value)
if len(messages) > 0:
message_translate = messages.pop(0).strip()
Expand All @@ -306,14 +309,25 @@ def query_dialogflow(self, query, start_time, end_time, limit=30, threshold=0.0)
if msg.result.response.action in ['make_reply', 'input.unknown']:
rospy.logwarn("Found dialogflow messages {}({}) at {} but skipping (action:{})".format(result['message'], result['message_translate'], result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), msg.result.response.action))
else:
rospy.loginfo("Found dialogflow messages {}({}) ({}) at {} ({}:{:.2f})".format(result['message'], result['message_translate'], msg.result.response.action, result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity']))
query_info = "Found dialogflow messages {}({}) ({}) at {} ({}:{:.2f})".format(result['message'], result['message_translate'], msg.result.response.action, result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity'])
if ( result['similarity'] > threshold):
rospy.loginfo(query_info)
results.append(result)
else:
rospy.logwarn(query_info)
rospy.logwarn(" ... skipping (threshold: {:.2f})".format(threshold))
else:
result.update({'action': ''})
rospy.loginfo("Found {} messages {}({}) at {} ({}:{:.2f})".format(message_type.split('/')[1], result['message'], result['message_translate'], result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity']))
if message_type == 'sound_play/SoundRequestActionGoal':
if any([x in msg.goal_id.id for x in ['/dialogflow_client', 'nav_speak', 'move_base', 'audible_warning', 'tweet_client']]):
# rospy.logwarn("Found {} messages {}({}) at {} ({}:{:.2f})".format(message_type.split('/')[1], result['message'], result['message_translate'], result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity']))
rospy.logwarn(" ... skipping ({})".format(msg.goal_id.id))
continue
else:
rospy.loginfo("Found {} messages {}({}) at {} ({}:{:.2f}) from {}".format(message_type.split('/')[1], result['message'], result['message_translate'], result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity'], msg.goal_id.id))

else:
rospy.loginfo("Found {} messages {}({}) at {} ({}:{:.2f})".format(message_type.split('/')[1], result['message'], result['message_translate'], result['timestamp'].strftime('%Y-%m-%d %H:%M:%S'), query, result['similarity']))

results.append(result)

Expand Down

0 comments on commit 9e4b988

Please sign in to comment.