Resolve a prompt template with optional variable substitution.
(prompt_type: str, variables: Dict[str, Any])
| 104 | |
| 105 | |
| 106 | def _resolve_prompt(prompt_type: str, variables: Dict[str, Any]) -> str: |
| 107 | """Resolve a prompt template with optional variable substitution.""" |
| 108 | |
| 109 | if prompt_type == "cluster": |
| 110 | potential_core_components = variables.get("potential_core_components", "<POTENTIAL_CORE_COMPONENTS placeholder>") |
| 111 | module_tree = variables.get("module_tree", {}) |
| 112 | module_name = variables.get("module_name", None) |
| 113 | return format_cluster_prompt( |
| 114 | potential_core_components=potential_core_components, |
| 115 | module_tree=module_tree, |
| 116 | module_name=module_name, |
| 117 | ) |
| 118 | |
| 119 | elif prompt_type == "system_complex": |
| 120 | module_name = variables.get("module_name", "MODULE_NAME") |
| 121 | custom_instructions = variables.get("custom_instructions", None) |
| 122 | return format_system_prompt(module_name, custom_instructions) |
| 123 | |
| 124 | elif prompt_type == "system_leaf": |
| 125 | module_name = variables.get("module_name", "MODULE_NAME") |
| 126 | custom_instructions = variables.get("custom_instructions", None) |
| 127 | return format_leaf_system_prompt(module_name, custom_instructions) |
| 128 | |
| 129 | elif prompt_type == "user": |
| 130 | module_name = variables.get("module_name", "MODULE_NAME") |
| 131 | module_tree = variables.get("module_tree", {}) |
| 132 | |
| 133 | # Return the template with placeholders filled as possible |
| 134 | return USER_PROMPT.format( |
| 135 | module_name=module_name, |
| 136 | module_tree=json.dumps(module_tree, indent=2) if module_tree else "<MODULE_TREE placeholder>", |
| 137 | formatted_core_component_codes=variables.get( |
| 138 | "formatted_core_component_codes", |
| 139 | "<CORE_COMPONENT_CODES placeholder — use read_code_components to get source code>" |
| 140 | ), |
| 141 | ) |
| 142 | |
| 143 | elif prompt_type == "overview_module": |
| 144 | module_name = variables.get("module_name", "MODULE_NAME") |
| 145 | repo_structure = variables.get("repo_structure", "<REPO_STRUCTURE placeholder>") |
| 146 | return MODULE_OVERVIEW_PROMPT.format( |
| 147 | module_name=module_name, |
| 148 | repo_structure=repo_structure if isinstance(repo_structure, str) else json.dumps(repo_structure, indent=4), |
| 149 | ) |
| 150 | |
| 151 | elif prompt_type == "overview_repo": |
| 152 | repo_name = variables.get("repo_name", "REPO_NAME") |
| 153 | repo_structure = variables.get("repo_structure", "<REPO_STRUCTURE placeholder>") |
| 154 | return REPO_OVERVIEW_PROMPT.format( |
| 155 | repo_name=repo_name, |
| 156 | repo_structure=repo_structure if isinstance(repo_structure, str) else json.dumps(repo_structure, indent=4), |
| 157 | ) |
| 158 | |
| 159 | return f"Unknown prompt type: {prompt_type}" |
no test coverage detected