Ask LLM to fix the broken code.
(original_code: str, error: str, client, model: str)
| 231 | return None, error |
| 232 | |
| 233 | def generate_fixed_code(original_code: str, error: str, client, model: str) -> Tuple[str, int]: |
| 234 | """Ask LLM to fix the broken code.""" |
| 235 | logger.info("Requesting code fix from LLM") |
| 236 | logger.info(f"Original error: {error}") |
| 237 | |
| 238 | response = client.chat.completions.create( |
| 239 | model=model, |
| 240 | messages=[ |
| 241 | {"role": "system", "content": CODE_FIX_PROMPT.format( |
| 242 | code=original_code, error=error)}, |
| 243 | {"role": "user", "content": "Fix the code to make it work."} |
| 244 | ], |
| 245 | temperature=0.2 |
| 246 | ) |
| 247 | |
| 248 | fixed_code = response.choices[0].message.content |
| 249 | code_blocks = extract_code_blocks(fixed_code) |
| 250 | |
| 251 | if code_blocks: |
| 252 | logger.info("Received fixed code from LLM") |
| 253 | return code_blocks[0], response.usage.completion_tokens |
| 254 | else: |
| 255 | logger.warning("No code block found in LLM response") |
| 256 | return None, response.usage.completion_tokens |
| 257 | |
| 258 | def simulate_execution(code: str, error: str, client, model: str) -> Tuple[Any, int]: |
| 259 | """Ask LLM to simulate code execution.""" |
no test coverage detected