Jev · Noul
ivy.node.jev-noul · v0.1.0
ivyx✓
Asks TypeSafe Jev a yes-or-no question about a text or JSON state and returns noul, the probability that the answer is yes, with answer true when it reaches the threshold. Use it to judge a yes-or-no question: is this an injection attempt, does it matter to a customer, is it urgent. Ask one proposition per node and add criteria when the boundary is subtle; a noul has no separate confidence, the number is the certainty. When the state is a JSON object its fields come back beside the answer.
Inputs
| Field | Type | Description |
|---|---|---|
| staterequired | Not declared | The text, or a JSON object or array, that Jev judges. |
| instructionsrequired | string | The yes-or-no question; the model never sees anything else about it. |
| criteria | object | Optional {"true": ..., "false": ...} descriptions of what counts as yes and as no. |
| threshold | number | answer is true when noul reaches this; raise it when a false yes costs more. |
| jev_api_keyrequired | string | The TypeSafe API key; reference the stored secret jev-api-key, never the key itself. |
| base_url | string | The System One server. |
| model | string | The Jev model; pin a version such as jev-1.13.0 before tuning a threshold. |
Outputs
| Field | Type | Description |
|---|---|---|
| noulrequired | number | The probability that the answer is yes, 0 to 1. |
| answerrequired | boolean | True when noul reaches the threshold. |
| thresholdrequired | number | The threshold used. |
| model | string | The model version that answered. |
Source
python
inp = __ivy_ctx__["nodes"][__ivy_node_id__]["input"]
import json
import re
import requests
def slug(text):
"""The key a branch reads: "Needs action today" → "needs_action_today"."""
return re.sub(r"[^a-z0-9]+", "_", str(text).lower()).strip("_")
def ask(question):
state = inp.get("state")
if state is None or (isinstance(state, str) and not state.strip()) or state == {} or state == []:
raise ValueError("state is empty; give Jev the text or JSON to judge.")
instructions = str(inp.get("instructions") or "").strip()
if not instructions:
raise ValueError("instructions is empty; say what Jev should decide.")
key = inp.get("jev_api_key")
if not key:
raise ValueError("jev_api_key is missing; reference the stored secret jev-api-key.")
question["instructions"] = instructions
base = str(inp.get("base_url") or "https://api.typesafe.ai").rstrip("/")
response = requests.post(
base + "/v1/systemone",
headers={"Authorization": "Bearer " + str(key), "Content-Type": "application/json"},
json={"state": state, "model": inp.get("model") or "jev-latest", "questions": {"q": question}},
timeout=60,
)
if response.status_code in (401, 403):
raise PermissionError(f"Jev refused the API key (HTTP {response.status_code}).")
if response.status_code != 200:
raise RuntimeError(f"Jev answered HTTP {response.status_code}: {response.text[:300]}")
body = response.json()
answer = (body.get("answers") or {}).get("q")
if not isinstance(answer, dict):
raise RuntimeError("Jev's answer has no entry for the question.")
return answer, body.get("model")
question = {"type": "noul"}
criteria = inp.get("criteria")
if isinstance(criteria, dict) and criteria:
question["criteria"] = {str(k).lower(): v for k, v in criteria.items()}
threshold = float(inp.get("threshold", 0.5))
if not 0 <= threshold <= 1:
raise ValueError("threshold is a probability between 0 and 1.")
answer, model = ask(question)
noul = float(answer.get("noul"))
out = __ivy_ctx__["nodes"][__ivy_node_id__]["output"]
out["noul"] = noul
out["answer"] = noul >= threshold
out["threshold"] = threshold
out["model"] = model
# An object state's fields come back beside the answer, so a for-each over
# rows keeps each row (its date, its question) next to its score.
if isinstance(inp.get("state"), dict):
for _k, _v in inp["state"].items():
out.setdefault(_k, _v)Tests
Requires: python:3.9, requests
- yes
A state the stand-in reads as yes passes the default threshold.
- strict
A threshold above the probability turns a likely yes into false.
- no
A plain statement reads as no.
- no-key
A missing key is refused before any call.