-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathdebug_render.py
More file actions
37 lines (25 loc) · 963 Bytes
/
debug_render.py
File metadata and controls
37 lines (25 loc) · 963 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
import pathlib
import shutil
from dynaprompt import DynaPrompt
def test_debug_render():
prompts_dir = pathlib.Path("debug_prompts")
prompts_dir.mkdir(exist_ok=True)
with open(prompts_dir / "child.md", "w") as f:
f.write("Child content")
with open(prompts_dir / "parent.md", "w") as f:
f.write("---\nvar: 'hello'\n---\nParent: {{var}}, {{child}}")
try:
dp = DynaPrompt(settings_files=[str(prompts_dir)], auto_render=True)
print(f"Parent raw template: {dp.parent.raw_template!r}")
print(f"Parent rendered text (auto): {dp.parent.text!r}")
rendered = dp.parent.render()
print(f"Parent rendered text (explicit): {rendered.text!r}")
except Exception as e:
print(f"Error: {e}")
import traceback
traceback.print_exc()
finally:
if prompts_dir.exists():
shutil.rmtree(prompts_dir)
if __name__ == "__main__":
test_debug_render()