wren node: Train in the panel, as a run of wren's training flow
POST/GET /flows/{name}/nodes/{id}/train submit wren_train on the node's
targets, examples and tests and read its latest run (run.for_node,
cause "train"); "Use this model" writes `model` into the draft.
This commit is contained in:
@@ -46,6 +46,13 @@ def _wren() -> Any:
|
||||
return wren
|
||||
|
||||
|
||||
def pack_meta(path: Any) -> dict[str, Any]:
|
||||
"""What a model records of its training: its targets, threshold and,
|
||||
when it had tests, ``test_exact_match``."""
|
||||
found: dict[str, Any] = _wren().load_pack(path)["meta"]
|
||||
return found
|
||||
|
||||
|
||||
#: The input the command arrives on, and the only one that wakes the node.
|
||||
PROMPT = "prompt"
|
||||
#: The output the calls are reported on, and the two that say what came of
|
||||
@@ -55,6 +62,8 @@ REPLY = "reply"
|
||||
UNHANDLED = "unhandled"
|
||||
#: The reply when nothing was done and nothing reads ``unhandled``.
|
||||
CANT = "Sorry, I can't do that yet."
|
||||
#: wren's training flow, which wren registers: ``fluksio sync wren.flow``.
|
||||
TRAIN_FLOW = "wren_train"
|
||||
|
||||
_TARGET_TYPES = {DType.BOOL, DType.INT, DType.FLOAT, DType.STR}
|
||||
|
||||
@@ -260,6 +269,17 @@ class WrenNode(Node):
|
||||
description="Your own words, and words heard wrong, in the model's: "
|
||||
'{"traverse": "living room light", "page too": "patio"}.',
|
||||
)
|
||||
examples: list[dict[str, Any]] = Field(
|
||||
default_factory=list,
|
||||
description="Training only: commands to learn, targets named by port, "
|
||||
'as {"state": {"user_location": "kitchen"}, "command": "lights on", '
|
||||
'"calls": [["kitchen_light", true]]}.',
|
||||
)
|
||||
tests: list[dict[str, Any]] = Field(
|
||||
default_factory=list,
|
||||
description="Training only: commands a new model is scored on, like "
|
||||
'examples. "calls": [] is one it must pass on.',
|
||||
)
|
||||
|
||||
__slots__ = ("cfg", "targets", "pack", "untrained")
|
||||
|
||||
@@ -339,6 +359,15 @@ class WrenNode(Node):
|
||||
name=name or "wren",
|
||||
)
|
||||
|
||||
def installation(self) -> dict[str, Any]:
|
||||
"""What wren's training flow learns from: the targets, each with a
|
||||
value, and the ``examples`` and ``tests``."""
|
||||
return {
|
||||
"targets": [t | {"value": _unset(t)} for t in self.targets.values()],
|
||||
"examples": self.cfg.examples,
|
||||
"tests": self.cfg.tests,
|
||||
}
|
||||
|
||||
async def start(self, app: FastAPI | None = None) -> None:
|
||||
store = getattr(app.state, "artifact_store", None) if app else None
|
||||
self.pack = self._load(store)
|
||||
|
||||
Reference in New Issue
Block a user