Skip to content

Commit f219996

Browse files
fix validation error for python code
1 parent b438243 commit f219996

File tree

2 files changed

+5
-3
lines changed

2 files changed

+5
-3
lines changed

codeflash/models/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -273,10 +273,10 @@ def parse_markdown_code(markdown_code: str) -> CodeStringsMarkdown:
273273
"""
274274
matches = markdown_pattern.findall(markdown_code)
275275
code_string_list = []
276-
for file_path, code in matches:
277-
path = file_path.strip()
278-
code_string_list.append(CodeString(code=code, file_path=Path(path)))
279276
try:
277+
for file_path, code in matches:
278+
path = file_path.strip()
279+
code_string_list.append(CodeString(code=code, file_path=Path(path)))
280280
return CodeStringsMarkdown(code_strings=code_string_list)
281281
except ValidationError:
282282
# if any file is invalid, return an empty CodeStringsMarkdown for the entire context

tests/test_validate_python_code.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,3 +69,5 @@ def test_generated_candidates_validation():
6969
]
7070
candidates = ai_service._get_valid_candidates(mock_generate_candidates, OptimizedCandidateSource.OPTIMIZE)
7171
assert len(candidates) == 1
72+
assert candidates[0].source_code.code_strings[0].code == "print('Hello, World!')"
73+
assert candidates[0].source_code.code_strings[0].file_path.as_posix() == "file.py"

0 commit comments

Comments
 (0)