fix yaml parse error
Use re to handle the unexpected conversion of colons in the yaml format
This commit is contained in:
@@ -1,3 +1,4 @@
|
|||||||
|
import re
|
||||||
from pocketflow import Node, BatchNode
|
from pocketflow import Node, BatchNode
|
||||||
from utils import call_llm
|
from utils import call_llm
|
||||||
import yaml
|
import yaml
|
||||||
@@ -21,6 +22,11 @@ sections:
|
|||||||
```"""
|
```"""
|
||||||
response = call_llm(prompt)
|
response = call_llm(prompt)
|
||||||
yaml_str = response.split("```yaml")[1].split("```")[0].strip()
|
yaml_str = response.split("```yaml")[1].split("```")[0].strip()
|
||||||
|
yaml_str = re.sub(
|
||||||
|
r'(?m)^(\s*)-\s*([^"\n]+)',
|
||||||
|
r'\1- "\2"',
|
||||||
|
yaml_str
|
||||||
|
)
|
||||||
structured_result = yaml.safe_load(yaml_str)
|
structured_result = yaml.safe_load(yaml_str)
|
||||||
return structured_result
|
return structured_result
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user