mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-12-12 02:45:18 +00:00
Update utils.py
more robust try_fix_yaml
This commit is contained in:
parent
8dbc53271e
commit
3e9b15de15
1 changed files with 7 additions and 2 deletions
|
|
@ -812,14 +812,19 @@ def try_fix_yaml(response_text: str,
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# second fallback - try to extract only range from first ```yaml to the last ```
|
# second fallback - try to extract only range from first ```yaml to the last ```
|
||||||
snippet_pattern = r'```yaml([\s\S]*?)```(?=\s*$|")'
|
snippet_pattern = r'```(yaml|yml)?([\s\S]*?)```(?=\s*$|")'
|
||||||
snippet = re.search(snippet_pattern, '\n'.join(response_text_lines_copy))
|
snippet = re.search(snippet_pattern, '\n'.join(response_text_lines_copy))
|
||||||
if not snippet:
|
if not snippet:
|
||||||
snippet = re.search(snippet_pattern, response_text_original) # before we removed the "```"
|
snippet = re.search(snippet_pattern, response_text_original) # before we removed the "```"
|
||||||
if snippet:
|
if snippet:
|
||||||
snippet_text = snippet.group()
|
snippet_text = snippet.group()
|
||||||
|
prefix = (
|
||||||
|
'```yaml'
|
||||||
|
if snippet_text.startswith('```yaml')
|
||||||
|
else ('```yml' if snippet_text.startswith('```yml') else '```')
|
||||||
|
)
|
||||||
try:
|
try:
|
||||||
data = yaml.safe_load(snippet_text.removeprefix('```yaml').rstrip('`'))
|
data = yaml.safe_load(snippet_text.removeprefix(prefix).rstrip('`'))
|
||||||
get_logger().info(f"Successfully parsed AI prediction after extracting yaml snippet")
|
get_logger().info(f"Successfully parsed AI prediction after extracting yaml snippet")
|
||||||
return data
|
return data
|
||||||
except:
|
except:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue