"""Fix the broken regex escapes in inference.py parse_action function.""" with open(r'd:\Meta Hackathon\adaptive-world-env\inference.py', 'r', encoding='utf-8') as f: content = f.read() # Exact broken strings as they appear in the file (using \n line endings) OLD1 = r" match = re.search(r'```(?:json)?\\s*(\\{.*?\\})\\s*```', llm_output, re.DOTALL)" NEW1 = r" match = re.search(r'```(?:json)?\s*(\{.*?\})\s*```', llm_output, re.DOTALL)" OLD2 = r" raw_match = re.search(r'\\{.*\\}', llm_output, re.DOTALL)" NEW2 = r" raw_match = re.search(r'\{.*\}', llm_output, re.DOTALL)" print("Looking for OLD1:", repr(OLD1)) print("Found:", OLD1 in content) print() print("Looking for OLD2:", repr(OLD2)) print("Found:", OLD2 in content) if OLD1 in content and OLD2 in content: content = content.replace(OLD1, NEW1, 1) content = content.replace(OLD2, NEW2, 1) with open(r'd:\Meta Hackathon\adaptive-world-env\inference.py', 'w', encoding='utf-8') as f: f.write(content) print("\nSUCCESS: Fixed both regex lines!") else: # Show the actual lines around parse_action idx = content.find("def parse_action") snippet = content[idx:idx+600] print("\nActual content:") for i, line in enumerate(snippet.split('\n')): print(f" {i}: {repr(line)}")