trodo-python 2.18.1__py3-none-any.whl → 2.19.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- trodo/__init__.py +5 -3
- trodo/prompts/compile.py +21 -4
- trodo/prompts/types.py +10 -0
- {trodo_python-2.18.1.dist-info → trodo_python-2.19.0.dist-info}/METADATA +1 -1
- {trodo_python-2.18.1.dist-info → trodo_python-2.19.0.dist-info}/RECORD +7 -7
- {trodo_python-2.18.1.dist-info → trodo_python-2.19.0.dist-info}/WHEEL +0 -0
- {trodo_python-2.18.1.dist-info → trodo_python-2.19.0.dist-info}/top_level.txt +0 -0
trodo/__init__.py
CHANGED
|
@@ -41,7 +41,7 @@ Downstream microservice (join the caller's run instead of making a new one):
|
|
|
41
41
|
|
|
42
42
|
from __future__ import annotations
|
|
43
43
|
|
|
44
|
-
__version__ = "2.
|
|
44
|
+
__version__ = "2.19.0"
|
|
45
45
|
|
|
46
46
|
from typing import Any, Callable, Dict, List, Optional, Union
|
|
47
47
|
|
|
@@ -322,7 +322,7 @@ def reset(distinct_id: str) -> ResetResult:
|
|
|
322
322
|
def get_prompt(
|
|
323
323
|
name: str,
|
|
324
324
|
label: Optional[str] = None,
|
|
325
|
-
version: Optional[int] = None,
|
|
325
|
+
version: Optional[Union[int, str]] = None,
|
|
326
326
|
cache_ttl_seconds: Optional[float] = None,
|
|
327
327
|
fallback: Optional[Dict[str, Any]] = None,
|
|
328
328
|
max_retries: int = 2,
|
|
@@ -330,7 +330,9 @@ def get_prompt(
|
|
|
330
330
|
"""Fetch a managed prompt by name.
|
|
331
331
|
|
|
332
332
|
Follows the ``production`` label by default; pass ``label`` for a different
|
|
333
|
-
one or ``version`` to pin exactly.
|
|
333
|
+
one or ``version`` to pin exactly. ``version`` may be the integer
|
|
334
|
+
``version_no`` or a ``version_hash`` (full, or an unambiguous short prefix
|
|
335
|
+
like ``a3f9c2``) — the hash is the stable identity, so prefer it.
|
|
334
336
|
|
|
335
337
|
Cached for 60s with stale-while-revalidate, so a Trodo outage degrades
|
|
336
338
|
instead of taking your app down. Pass ``fallback`` to cover cold start::
|
trodo/prompts/compile.py
CHANGED
|
@@ -74,8 +74,12 @@ def build_scope(
|
|
|
74
74
|
) -> Dict[str, Any]:
|
|
75
75
|
"""Build the render scope from declarations + caller values.
|
|
76
76
|
|
|
77
|
-
Resolution order: caller value
|
|
78
|
-
raises
|
|
77
|
+
Resolution order: caller value -> declared default -> required-and-absent
|
|
78
|
+
raises -> optional-and-absent renders empty.
|
|
79
|
+
|
|
80
|
+
`required` is enforced HERE, in your process, before the model call -- Trodo
|
|
81
|
+
only stores the declaration. A variable with a default can never fail this
|
|
82
|
+
check, because the default is itself a value.
|
|
79
83
|
"""
|
|
80
84
|
errors: List[str] = []
|
|
81
85
|
scope: Dict[str, Any] = {}
|
|
@@ -100,11 +104,24 @@ def build_scope(
|
|
|
100
104
|
has = name in values
|
|
101
105
|
value = values.get(name) if has else None
|
|
102
106
|
|
|
103
|
-
#
|
|
104
|
-
#
|
|
107
|
+
# `required` asks a narrower question than default-substitution does:
|
|
108
|
+
# did the caller supply something that will actually render? None and ""
|
|
109
|
+
# both render as nothing, the very outcome the flag exists to prevent,
|
|
110
|
+
# so neither counts. (0 and False do -- they render.)
|
|
111
|
+
supplied = has and value is not None and value != ""
|
|
112
|
+
|
|
113
|
+
# Missing value -> the declared default, or empty.
|
|
105
114
|
if not has or value is None:
|
|
106
115
|
value = default if has_default else ([] if type_ == "messages" else "")
|
|
107
116
|
|
|
117
|
+
# A default always satisfies the requirement, so the two never both
|
|
118
|
+
# apply; the editor won't let you author both, but a hand-written
|
|
119
|
+
# declaration can.
|
|
120
|
+
required = v.get("required") if isinstance(v, dict) else getattr(v, "required", None)
|
|
121
|
+
if not supplied and required is True and not has_default:
|
|
122
|
+
errors.append(f"variable '{name}': required, but no value was provided")
|
|
123
|
+
continue
|
|
124
|
+
|
|
108
125
|
scope[name] = _coerce(value, type_, name, errors)
|
|
109
126
|
|
|
110
127
|
# Passing something the prompt doesn't declare is nearly always a rename
|
trodo/prompts/types.py
CHANGED
|
@@ -29,6 +29,16 @@ class PromptVariable:
|
|
|
29
29
|
regex, with no defaults and no required-ness. The declaration is what lets
|
|
30
30
|
``compile()`` fail before the model call rather than shipping a literal
|
|
31
31
|
``{{typo}}`` and finding out from the bill.
|
|
32
|
+
|
|
33
|
+
``required`` is enforced by ``compile()``, which runs in YOUR process —
|
|
34
|
+
Trodo only stores the declaration. Nothing server-side rejects a call for a
|
|
35
|
+
missing variable, and nothing rejects a version for declaring one.
|
|
36
|
+
|
|
37
|
+
Marking a variable required means the caller must pass a value that will
|
|
38
|
+
actually render: an omitted key, ``None`` and ``""`` all fail, since all
|
|
39
|
+
three render as nothing (``0`` and ``False`` pass). A variable with
|
|
40
|
+
a ``default`` can never fail the check — the default is a value — so the two
|
|
41
|
+
are mutually exclusive in practice.
|
|
32
42
|
"""
|
|
33
43
|
|
|
34
44
|
name: str
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
trodo/__init__.py,sha256=
|
|
1
|
+
trodo/__init__.py,sha256=n7YUScfJqdXfIUwWL-g1PekBrYfQ0A0m4kAme26rwUM,26928
|
|
2
2
|
trodo/client.py,sha256=9UYaHZtWPMYdlG2xWVf77PQJ9DfFgN-zobTh60i8_Cc,22453
|
|
3
3
|
trodo/types.py,sha256=eySgUvCXROG2TxtxgiU0MNr5iH0DEcduK8bmYtTKG44,3138
|
|
4
4
|
trodo/user_context.py,sha256=uHCI2WYoOI3cNwdIUEuZdX4VYSu14pzm348ksn6hn_c,8195
|
|
@@ -25,9 +25,9 @@ trodo/otel/register.py,sha256=bV_ePTfUvPugig2GZnylhzxi2QfoPWs96A9mGLPMrSQ,9387
|
|
|
25
25
|
trodo/otel/transport.py,sha256=hzZz8gwSMGJ8CxdijmLn1Ljt18owr9XTWy13DLbwYbw,2441
|
|
26
26
|
trodo/otel/wrap_agent.py,sha256=cJjrzlZNW2g6q_coLN7UR4uxn65h4u3-LNzMfE4dLVw,40999
|
|
27
27
|
trodo/prompts/__init__.py,sha256=yunNc8WkTSfEEkRR-NZWXAt_ZB3Ee2INRh-4RE7uHj4,806
|
|
28
|
-
trodo/prompts/compile.py,sha256=
|
|
28
|
+
trodo/prompts/compile.py,sha256=ydJDI7YS3PiLzAJ4H-kmqGV-1kkUxlQrf_xtZZ7fR5g,7267
|
|
29
29
|
trodo/prompts/template.py,sha256=obQiivPCR6LEdz7q1cby7uL25tYHYui4aoEaiUNqWfs,9357
|
|
30
|
-
trodo/prompts/types.py,sha256=
|
|
30
|
+
trodo/prompts/types.py,sha256=1TVGHp3vtWV1tr0l-IJfL7EKvrB8ZmQRwLvDqvbOfJ0,5007
|
|
31
31
|
trodo/queue/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
32
32
|
trodo/queue/batch_flusher.py,sha256=4Lg6T3Urwi9U0Q4FpFGPmjDYKg4ZliCTR-ND8BJvWaY,1298
|
|
33
33
|
trodo/queue/event_queue.py,sha256=EVFZrhlq_kwC3jJ2GK0wMhHISf9UzLCZNDnT_aZ2I2A,872
|
|
@@ -36,7 +36,7 @@ trodo/session/server_session.py,sha256=McsudEiq33XDq3nqxgzBcUvIjQxCMscwEuAPnYXrT
|
|
|
36
36
|
trodo/session/session_manager.py,sha256=7ht5LeeZX1HLLfPeNV_a8NkXGbHl3up0CRtCGr3EzjQ,2995
|
|
37
37
|
trodo/util/__init__.py,sha256=Z9c4rPPdKg06Kk3byKheDqksSgR4WNvS475oQ5sNljc,54
|
|
38
38
|
trodo/util/lru.py,sha256=QIsM7s6J_E9ZjiXatSyReZIEeGypTAcgrPWWy8YsRa4,2465
|
|
39
|
-
trodo_python-2.
|
|
40
|
-
trodo_python-2.
|
|
41
|
-
trodo_python-2.
|
|
42
|
-
trodo_python-2.
|
|
39
|
+
trodo_python-2.19.0.dist-info/METADATA,sha256=RD_p3hblnxk6pAacML6IkqzfdIqP33lD50GS1kApkW8,25308
|
|
40
|
+
trodo_python-2.19.0.dist-info/WHEEL,sha256=YVMoNqKzERt-wjUZwJ33xBGAwnFl-4cqbYkTtWa4itE,91
|
|
41
|
+
trodo_python-2.19.0.dist-info/top_level.txt,sha256=VCQu1CJWFmNsqTs1YxMcw4Mq35Tc3z3uI9RwHEXAayQ,6
|
|
42
|
+
trodo_python-2.19.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|