MCPcopy Index your code
hub / github.com/FSoft-AI4Code/CodeWiki / format_cluster_prompt

Function format_cluster_prompt

codewiki/src/be/prompt_template.py:331–374  ·  view source on GitHub ↗

Format the cluster prompt with potential core components and module tree.

(potential_core_components: str, module_tree: dict[str, any] = {}, module_name: str = None)

Source from the content-addressed store, hash-verified

329
330
331def format_cluster_prompt(potential_core_components: str, module_tree: dict[str, any] = {}, module_name: str = None) -> str:
332 """
333 Format the cluster prompt with potential core components and module tree.
334 """
335
336 # format module tree
337 lines = []
338
339 # print(f"Module tree:\n{json.dumps(module_tree, indent=2)}")
340
341 def _format_module_tree(module_tree: dict[str, any], indent: int = 0):
342 for key, value in module_tree.items():
343 if key == module_name:
344 lines.append(f"{' ' * indent}{key} (current module)")
345 else:
346 lines.append(f"{' ' * indent}{key}")
347
348 # Group components by file
349 from collections import defaultdict
350 by_file = defaultdict(list)
351 for c in value['components']:
352 if "::" in c:
353 fpath, name = c.split("::", 1)
354 by_file[fpath].append(name)
355 else:
356 by_file[""].append(c)
357 for fpath, names in by_file.items():
358 if fpath:
359 lines.append(f"{' ' * (indent + 1)} {fpath}: {', '.join(names)}")
360 else:
361 lines.append(f"{' ' * (indent + 1)} {', '.join(names)}")
362
363 if ("children" in value) and isinstance(value["children"], dict) and len(value["children"]) > 0:
364 lines.append(f"{' ' * (indent + 1)} Children:")
365 _format_module_tree(value["children"], indent + 2)
366
367 _format_module_tree(module_tree, 0)
368 formatted_module_tree = "\n".join(lines)
369
370
371 if module_tree == {}:
372 return CLUSTER_REPO_PROMPT.format(potential_core_components=potential_core_components)
373 else:
374 return CLUSTER_MODULE_PROMPT.format(potential_core_components=potential_core_components, module_tree=formatted_module_tree, module_name=module_name)
375
376
377def format_system_prompt(module_name: str, custom_instructions: str = None) -> str:

Callers 2

cluster_modulesFunction · 0.90
_resolve_promptFunction · 0.90

Calls 2

_format_module_treeFunction · 0.85
formatMethod · 0.80

Tested by

no test coverage detected