I have a json like this: {'messageid':43,'replyingtoid':null, 'text': "Hi! My name is…
- User
I have a json like this:
{'message_id':43,'replying_to_id':null, 'text': "Hi! My name is Bob"} {'message_id':44,'replying_to_id':43, 'text': "Hello Bob!"} {'message_id':45,'replying_to_id':null, 'text': "Boring"} {'message_id':46,'replying_to_id':43, 'text': "Sup bob!"} {'message_id':47,'replying_to_id':null, 'text': "Did you see the door?"} {'message_id':48,'replying_to_id':43, 'text': "Wow! You're Bob!? Hey!!!"} {'message_id':49,'replying_to_id':44, 'text': "Hey Sara!"} {'message_id':50,'replying_to_id':47, 'text': "What do you mean did i see the door?"}
Please write a python script that creates branches of dialoges based on what post user replied to. Return a list of those dialogues so the result would be: [["Hi! My name is Bob", "Hello Bob!","Hey Sara!"],["Hi! My name is Bob","Sup bob!"],["Hi! My name is Bob","Wow! You're Bob!? Hey!!!"],["Did you see the door?","What do you mean did i see the door?"]
- Assistant
Here's a Python script that processes the given JSON data and creates the desired branches of dialogues:
import json json_data = '''[ {"message_id":43,"replying_to_id":null, "text": "Hi! My name is Bob"}, {"message_id":44,"replying_to_id":43, "text": "Hello Bob!"}, {"message_id":45,"replying_to_id":null, "text": "Boring"}, {"message_id":46,"replying_to_id":43, "text": "Sup bob!"}, {"message_id":47,"replying_to_id":null, "text": "Did you see the door?"}, {"message_id":48,"replying_to_id":43, "text": "Wow! You're Bob!? Hey!!!"}, {"message_id":49,"replying_to_id":44, "text": "Hey Sara!"}, {"message_id":50,"replying_to_id":47, "text": "What do you mean did i see the door?"} ]''' data = json.loads(json_data) def build_dialogues(message_id, dialogue, dialogues): children = [] for msg in data: if msg['replying_to_id'] == message_id: new_dialogue = dialogue + [msg['text']] dialogues.append(new_dialogue) children.append(msg['message_id']) for child_id in children: build_dialogues(child_id, dialogue, dialogues) dialogues = [] for msg in data: if msg['replying_to_id'] == None: build_dialogues(msg['message_id'], [msg['text']], dialogues) print(dialogues)
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.