Policy Environments
Main Class
PolicyEnv
The global environment accessible to policies.
It can be used for:
- Fetching prompts, data, and examples.
- Caching LLM requests.
- Tracing nodes, query, answers, and logging information.
Attributes:
Name | Type | Description |
---|---|---|
requests_cache |
LLMCache | None
|
The requests cache, or |
templates |
The prompt templates manager. |
|
tracer |
The tracer, which can also be used for logging. |
|
examples |
The example database. |
Source code in src/delphyne/stdlib/environments.py
311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|
__init__
__init__(
*,
prompt_dirs: Sequence[Path] = (),
demonstration_files: Sequence[Path] = (),
data_dirs: Sequence[Path] = (),
cache: CacheSpec | None = None,
do_not_match_identical_queries: bool = False,
)
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt_dirs
|
Sequence[Path]
|
A sequence of directories where Jinja prompt templates can be found. |
()
|
demonstration_files
|
Sequence[Path]
|
A sequence of paths to demonstration
files (with or without extension |
()
|
data_dirs
|
Sequence[Path]
|
A sequence of directories where data files can be found. |
()
|
cache
|
CacheSpec | None
|
A cache specification, or |
None
|
do_not_match_identical_queries
|
bool
|
See |
False
|
Source code in src/delphyne/stdlib/environments.py
331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 |
|
InvalidDemoFile
dataclass
Bases: Exception
Exception raised when a demonstration file could not be parsed.
Source code in src/delphyne/stdlib/environments.py
301 302 303 304 305 306 307 308 |
|
Example Database
Example
dataclass
An example, usable for few-shot prompting.
Attributes:
Name | Type | Description |
---|---|---|
args |
QuerySerializedArgs
|
The serialized query arguments. |
answer |
Answer
|
The answer to the query. |
tags |
Sequence[str]
|
A sequence of tags associated with the example, which policies can use to select appropriate examples. |
Source code in src/delphyne/stdlib/environments.py
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
|
QuerySerializedArgs
QuerySerializedArgs: dict[str, Any]
Serialized query arguments, as a dictionary mapping attributed to JSON values (assemblies of integers, strings, dictionnaries, list, tuples...).
ExampleDatabase
dataclass
A simple example database.
Attributes:
Name | Type | Description |
---|---|---|
do_not_match_identical_queries |
bool
|
If set to |
TODO: add provenance info for better error messages.
Source code in src/delphyne/stdlib/environments.py
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 |
|
add_query_demonstration
add_query_demonstration(demo: QueryDemo)
Add all examples from a standalone query demonstration to the database.
Source code in src/delphyne/stdlib/environments.py
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
|
add_demonstration
add_demonstration(demo: Demo)
Add all exmples from a demonstration to the database.
Source code in src/delphyne/stdlib/environments.py
111 112 113 114 115 116 117 118 119 120 |
|
examples
examples(query_name: str, query_args: QuerySerializedArgs) -> Iterable[Example]
Obtain all potential examples that can be used for few-shot prompting with a given query.
Source code in src/delphyne/stdlib/environments.py
122 123 124 125 126 127 128 129 130 131 132 133 |
|
Tracer
TemplatesManager
Bases: AbstractTemplatesManager
A class for managing Jinja prompt templates.
Templates are configured with the trim_blocks
and lstrip_blocks
options set to True
(no newlines are inserted after blocks and
indentation can be used within blocks without affecting the output).
The keep_trailing_newline
option is set to False
so trailing new
lines at the end of template files are ignored.
Templates are first searched in the provided prompt folders and then
in the standard library (delphyne.stdlib.templates
). For example,
to show standard formatting instructions, you can include the
following in your instance prompts:
{% include 'stdlib/format.jinja' %}
All templates automatically have access to the following global objects:
- A
yaml
filter for converting an object into a YAML string. - A
json
filter for converting an object into a JSON string. - A
fail
function that takes an error message as an argument and raises an exception on Python side.
Source code in src/delphyne/stdlib/environments.py
186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 |
|
__init__
__init__(prompt_dirs: Sequence[Path], data_dirs: Sequence[Path])
Parameters:
Name | Type | Description | Default |
---|---|---|---|
prompt_dirs
|
Sequence[Path]
|
A sequence of directories where Jinja prompt templates can be found. |
required |
data_dirs
|
Sequence[Path]
|
A sequence of directories where data files can be found. |
required |
Source code in src/delphyne/stdlib/environments.py
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
|
TemplateFileMissing
dataclass
Bases: Exception
Exception raised when a template file is missing.
This exception should only be raised when a top-level template file
is missing. If an include
statement fails within a template, a
TemplateError
exception should be raised instead.
Source code in src/delphyne/core/queries.py
144 145 146 147 148 149 150 151 152 153 154 |
|