Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
hahuyhoang411 committed Oct 29, 2024
1 parent f064260 commit f4fb522
Showing 1 changed file with 18 additions and 11 deletions.
29 changes: 18 additions & 11 deletions .github/workflows/create-model-yml.yml
Original file line number Diff line number Diff line change
Expand Up @@ -74,18 +74,25 @@ jobs:
if subsection:
file.write(f"# BEGIN {subsection}\n")
yaml_content = yaml.dump(content, Dumper=CustomDumper, default_flow_style=False, sort_keys=False)
# Special handling for prompt_template to ensure it's quoted
# Special handling for prompt_template to ensure it's a single line with preserved \n
if 'prompt_template' in content:
yaml_lines = yaml_content.split('\n')
for i, line in enumerate(yaml_lines):
if line.startswith('prompt_template:'):
yaml_lines[i] = f'prompt_template: "{content["prompt_template"]}"'
yaml_content = '\n'.join(yaml_lines)
file.write(yaml_content)
# Create a copy of the content to modify
modified_content = content.copy()
# Convert the prompt template to a literal string that preserves \n
prompt_template = modified_content['prompt_template']
# Remove the prompt_template from the content to handle it separately
del modified_content['prompt_template']
# Dump the rest of the content
yaml_content = yaml.dump(modified_content, Dumper=CustomDumper, default_flow_style=False, sort_keys=False)
file.write(yaml_content)
# Write the prompt_template separately with proper escaping
file.write(f'prompt_template: "{prompt_template}"\n')
else:
yaml_content = yaml.dump(content, Dumper=CustomDumper, default_flow_style=False, sort_keys=False)
file.write(yaml_content)
if subsection:
file.write(f"# END {subsection}\n")
if section_name:
Expand Down

0 comments on commit f4fb522

Please sign in to comment.