mirror of
https://github.com/qodo-ai/pr-agent.git
synced 2025-12-11 18:35:18 +00:00
Compare commits
3 commits
8e88bf065f
...
5d378385a6
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
5d378385a6 | ||
|
|
46f889b314 | ||
|
|
3e9b15de15 |
2 changed files with 27 additions and 4 deletions
|
|
@ -812,14 +812,19 @@ def try_fix_yaml(response_text: str,
|
|||
pass
|
||||
|
||||
# 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))
|
||||
if not snippet:
|
||||
snippet = re.search(snippet_pattern, response_text_original) # before we removed the "```"
|
||||
if snippet:
|
||||
snippet_text = snippet.group()
|
||||
prefix = (
|
||||
'```yaml'
|
||||
if snippet_text.startswith('```yaml')
|
||||
else ('```yml' if snippet_text.startswith('```yml') else '```')
|
||||
)
|
||||
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")
|
||||
return data
|
||||
except:
|
||||
|
|
|
|||
|
|
@ -21,16 +21,34 @@ class TestTryFixYaml:
|
|||
|
||||
# The function extracts YAML snippet
|
||||
def test_extract_snippet(self):
|
||||
review_text = '''\
|
||||
review_text1 = '''\
|
||||
Here is the answer in YAML format:
|
||||
|
||||
```yaml
|
||||
name: John Smith
|
||||
age: 35
|
||||
```
|
||||
'''
|
||||
review_text2 = '''\
|
||||
Here is the answer in YAML format:
|
||||
|
||||
```yml
|
||||
name: John Smith
|
||||
age: 35
|
||||
```
|
||||
'''
|
||||
review_text3 = '''\
|
||||
Here is the answer in YAML format:
|
||||
|
||||
```
|
||||
name: John Smith
|
||||
age: 35
|
||||
```
|
||||
'''
|
||||
expected_output = {'name': 'John Smith', 'age': 35}
|
||||
assert try_fix_yaml(review_text) == expected_output
|
||||
assert try_fix_yaml(review_text1) == expected_output
|
||||
assert try_fix_yaml(review_text2) == expected_output
|
||||
assert try_fix_yaml(review_text3) == expected_output
|
||||
|
||||
|
||||
# The YAML string is empty.
|
||||
|
|
|
|||
Loading…
Reference in a new issue