← All ivy-nodes
IVYXSTUDIO · IVY NODE
D

Design: the request as the model's context

ivy.node.design-brief · v0.1.0

ivyx✓

Puts the request together as one text for the model's turn: the client, the service, the month, the brief and the figures, so the model writes for the right client. No model, no network.

#design#brief#agency

Inputs

FieldTypeDescription
briefstringNot declared
clientstringNot declared
servicestringNot declared
monthstringNot declared
request_idstringNot declared
chartsarrayNot declared

Outputs

FieldTypeDescription
contextrequiredstringThe request as one text.
clientstringNot declared

Source

python

# Input preparation
inp = __ivy_ctx__["nodes"][__ivy_node_id__]["input"]

# Compute
# Shared by every design node (built into each by build.mjs): colours, text, files.
import base64, re, math

SAFE_PALETTES = [
    {"bg": "#1E1B4B", "accent": "#F6A23B", "text": "#F8F7FF"},
    {"bg": "#F4F2FF", "accent": "#6C3BFF", "text": "#1E1B4B"},
    {"bg": "#0F3D3E", "accent": "#E8C547", "text": "#F3F7F6"},
    {"bg": "#FFF4E6", "accent": "#D9480F", "text": "#2B1D12"},
    {"bg": "#101418", "accent": "#3DDC97", "text": "#F2F4F6"},
]

def hex_ok(s):
    return isinstance(s, str) and re.fullmatch(r"#[0-9a-fA-F]{6}", s.strip()) is not None

def palette_of(p, seed=0):
    """A palette with three valid hex colours; what the model got wrong is replaced from a safe pair."""
    base = SAFE_PALETTES[abs(int(seed)) % len(SAFE_PALETTES)]
    out = {}
    p = p if isinstance(p, dict) else {}
    for k in ("bg", "accent", "text"):
        v = p.get(k)
        out[k] = v.strip().upper() if hex_ok(v) else base[k]
    if out["bg"].upper() == out["text"].upper():
        out["text"] = base["text"] if base["text"].upper() != out["bg"].upper() else base["bg"]
    return out

def rgb(h):
    h = h.lstrip("#")
    return (int(h[0:2], 16), int(h[2:4], 16), int(h[4:6], 16))

def mix(a, b, t):
    return tuple(int(round(a[i] + (b[i] - a[i]) * t)) for i in range(3))

def to_hex(c):
    return "#%02X%02X%02X" % c

def lum(h):
    r, g, b = [x / 255 for x in rgb(h)]
    return 0.2126 * r + 0.7152 * g + 0.0722 * b

def esc(s):
    return (str(s).replace("&", "&amp;").replace("<", "&lt;").replace(">", "&gt;").replace('"', "&quot;"))

def text_of(v, limit, default=""):
    s = " ".join(str(v).split()) if isinstance(v, (str, int, float)) else ""
    if not s:
        s = default
    return s[:limit].rstrip() if len(s) > limit else s

def wrap(s, max_chars):
    words = s.split()
    lines, cur = [], ""
    for w in words:
        if cur and len(cur) + 1 + len(w) > max_chars:
            lines.append(cur)
            cur = w
        else:
            cur = (cur + " " + w).strip()
    if cur:
        lines.append(cur)
    return lines or [""]

def b64(data):
    return base64.b64encode(data).decode("ascii")

def file_entry(name, mime, data, kind, width=None, height=None, caption=None, variant=None, extra=None):
    f = {"name": name, "mime": mime, "kind": kind, "bytes": len(data), "data": b64(data)}
    if width:
        f["width"] = int(width)
    if height:
        f["height"] = int(height)
    if caption:
        f["caption"] = caption
    if variant:
        f["variant"] = variant
    if extra:
        f.update(extra)
    return f

def slug(s):
    s = re.sub(r"[^a-z0-9]+", "-", str(s).lower()).strip("-")
    return s[:40] or "design"

def font():
    return "Inter, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif"


class DesignBrief:
    "Design: the request as the model's context"

    def run(self, inp):
        out = {}
        # design-brief: the request as one text for the model's turn: the client, the service, the month and the brief, so the model knows whose work it is.
        parts = []
        for key, label in (("client", "Client"), ("service", "Service"), ("month", "Month"), ("request_id", "Request")):
            v = text_of(inp.get(key), 120, "")
            if v:
                parts.append("%s: %s" % (label, v))
        brief = text_of(inp.get("brief"), 4000, "")
        if brief:
            parts.append("Brief: %s" % brief)
        charts = inp.get("charts")
        if isinstance(charts, list) and charts:
            import json
            parts.append("Figures: %s" % json.dumps(charts)[:3000])
        out = {"context": "\n".join(parts) or "No brief was given.", "client": text_of(inp.get("client"), 120, "")}
        return out


result = DesignBrief().run(inp)

# Output collection (the runner reads it here)
out = __ivy_ctx__["nodes"][__ivy_node_id__]["output"]
out.update(result)

Tests

Requires: python:3.9

  • names

    The context opens with the client, then the service, then the brief.

  • empty

    An empty request says no brief was given rather than inventing one.