templates
Templates
Manages templates, both in-memory and on-disk.
This class provides functionality to store, retrieve, and delete templates. It supports both in-memory storage and persistent storage on disk.
Source code in src/lmflux/core/templates.py
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 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 | |
__init__()
Initializes the Templates instance.
Sets up the in-memory template storage, ignored template IDs, external location for persistent templates, and permission for external deletion.
Source code in src/lmflux/core/templates.py
12 13 14 15 16 17 18 19 20 21 22 | |
clear()
Clears all the state in the Templates class
Source code in src/lmflux/core/templates.py
47 48 49 50 51 52 53 54 | |
delete_template(template_id)
Remove a template.
- If the template exists in memory, drop it from
__inmem_templates. - If it does not exist in memory:
- When
__allow_external_deletionis True, attempt to delete the corresponding file from__external_location. - Otherwise, record the id in
__ignore_template_id.
Source code in src/lmflux/core/templates.py
98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 | |
get_with_context(template_id, context)
Retrieves a template with context replacement.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_id
|
str
|
The ID of the template to retrieve. |
required |
context
|
dict
|
A dictionary of key-value pairs to replace in the template. |
required |
Returns:
| Name | Type | Description |
|---|---|---|
str |
str
|
The template content with replacements made. |
Source code in src/lmflux/core/templates.py
131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 | |
put_template(template_id, template_src, persistent=False)
Stores a template.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
template_id
|
str
|
The ID of the template. |
required |
template_src
|
str
|
The source content of the template. |
required |
persistent
|
bool
|
Whether to store the template persistently on disk. Defaults to False. |
False
|
Raises:
| Type | Description |
|---|---|
AttributeError
|
If persistent is True but the external location is not defined. |
Source code in src/lmflux/core/templates.py
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | |
set_allow_external_deletion(allow=True)
Toggle permission to delete templates that live on disk.
Source code in src/lmflux/core/templates.py
56 57 58 | |
set_hard_external_delete()
Makes persisted templates deletes permanent (not session level).
Source code in src/lmflux/core/templates.py
147 148 149 150 151 | |
set_location(location)
Sets the external location for template storage.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
location
|
str
|
The new external location path. |
required |
Source code in src/lmflux/core/templates.py
60 61 62 63 64 65 66 67 | |
set_soft_external_delete()
Makes persisted templates deletes soft (session level only).
Source code in src/lmflux/core/templates.py
153 154 155 156 157 | |