MCPcopy Create free account
hub / github.com/PERSONA-bench/PERSONA / build_post_context_excluding_node

Function build_post_context_excluding_node

demo/3.3PromptMaker.py:243–265  ·  view source on GitHub ↗
(post_data_orig, node_to_remove_id)

Source from the content-addressed store, hash-verified

241
242
243def build_post_context_excluding_node(post_data_orig, node_to_remove_id):
244 if not node_to_remove_id: return deepcopy(post_data_orig)
245 context_data = deepcopy(post_data_orig)
246 if context_data.get('id') == node_to_remove_id and context_data.get('type') == 'post': return None
247 if 'comments' in context_data:
248 new_comments = []
249 for c_top in context_data.get('comments', []):
250 if isinstance(c_top, dict) and c_top.get('id') != node_to_remove_id:
251 new_comments.append(c_top)
252 context_data['comments'] = new_comments
253
254 q = deque(context_data.get('comments', []))
255 while q:
256 current_parent_node = q.popleft()
257 if not isinstance(current_parent_node, dict): continue
258 if 'replies' in current_parent_node and current_parent_node['replies']:
259 new_replies = []
260 for r_child in current_parent_node['replies']:
261 if isinstance(r_child, dict) and r_child.get('id') != node_to_remove_id:
262 new_replies.append(r_child)
263 current_parent_node['replies'] = new_replies
264 for r_child_ok in current_parent_node['replies']: q.append(r_child_ok)
265 return context_data
266
267
268def get_truncated_dialogue_tree_for_body_fewshot(full_post_flat_nodes, few_shot_reply_obj):

Callers 1

mainFunction · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…