mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-12-12 02:45:18 +00:00
fix: normalize nested diff markers before YAML parsing
This commit is contained in:
parent
6561d0478e
commit
1a4df62f89
1 changed files with 34 additions and 0 deletions
|
|
@ -868,6 +868,40 @@ def try_fix_yaml(response_text: str,
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
# 5.5 fallback - try to normalize diff-style removal markers ('-') within list items
|
||||||
|
response_text_lines_copy = response_text_lines.copy()
|
||||||
|
modified = False
|
||||||
|
|
||||||
|
for i, line in enumerate(response_text_lines_copy):
|
||||||
|
if line.startswith('+'):
|
||||||
|
response_text_lines_copy[i] = ' ' + line[1:]
|
||||||
|
modified = True
|
||||||
|
|
||||||
|
for i, line in enumerate(response_text_lines_copy):
|
||||||
|
if not line.startswith('-'):
|
||||||
|
continue
|
||||||
|
remainder = line[1:]
|
||||||
|
if line.startswith('- '):
|
||||||
|
second_char = remainder[1] if len(remainder) > 1 else ''
|
||||||
|
if second_char and second_char not in (' ', '\t', '+', '-'):
|
||||||
|
continue
|
||||||
|
cleaned = remainder
|
||||||
|
while cleaned and cleaned[0] in ('+', '-'):
|
||||||
|
cleaned = cleaned[1:]
|
||||||
|
if cleaned and cleaned[0] not in (' ', '\t'):
|
||||||
|
cleaned = ' ' + cleaned
|
||||||
|
if cleaned != line:
|
||||||
|
response_text_lines_copy[i] = cleaned
|
||||||
|
modified = True
|
||||||
|
if modified:
|
||||||
|
try:
|
||||||
|
data = yaml.safe_load('\n'.join(response_text_lines_copy))
|
||||||
|
get_logger().info("Successfully parsed AI prediction after normalizing diff removal markers")
|
||||||
|
return data
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
# sixth fallback - replace tabs with spaces
|
# sixth fallback - replace tabs with spaces
|
||||||
if '\t' in response_text:
|
if '\t' in response_text:
|
||||||
response_text_copy = copy.deepcopy(response_text)
|
response_text_copy = copy.deepcopy(response_text)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue