-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprompt_rendering.py
More file actions
31 lines (21 loc) · 804 Bytes
/
Copy pathprompt_rendering.py
File metadata and controls
31 lines (21 loc) · 804 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
"""Minimal package-owned example for rendering a packaged prompt."""
from importlib.resources import as_file, files
from context_compiler import State
from context_compiler_directive_drafter import render_prompt
def main() -> None:
state: State = {
"premise": "concise replies",
"policies": {
"docker": "use",
"peanuts": "prohibit",
},
"version": 2,
}
prompt_resource = files("context_compiler_directive_drafter").joinpath("prompts/default.txt")
with as_file(prompt_resource) as prompt_path:
rendered = render_prompt(prompt_path, state)
if rendered is None:
raise RuntimeError("prompt resource could not be loaded")
print("\n".join(rendered.splitlines()[:8]))
if __name__ == "__main__":
main()