apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: huggingface-inference
  labels:
    dagweave.io/catalog-item: huggingface-inference
  annotations:
    # The catalog semver this manifest was authored at. The dagweave app records
    # (catalog-item-id, semver) -> content-hash -> base-vN when it mints the tenant
    # cluster name via ResolveOrMint. Keep in sync with metadata.yaml `version`.
    dagweave.io/catalog-version: "1.0.3"
    dagweave.io/catalog-category: "AI"
spec:
  entrypoint: infer
  templates:
    - name: infer
      inputs:
        parameters:
          # HuggingFace model repo id, e.g. "distilbert-base-uncased".
          - name: model
          # The input text to run inference on.
          - name: input-text
          # Name/key of a Kubernetes Secret holding the HuggingFace access token.
          - name: token-secret-name
            default: huggingface-token
          - name: token-secret-key
            default: token
      container:
        # Pinned by digest per the catalog convention: an image rebuild can never
        # silently change the behaviour of an already-released item version.
        # badouralix/curl-jq:ubuntu — provides sh, curl and jq.
        image: badouralix/curl-jq@sha256:38362e9b8ef4bd09a88c0db07941e61e0bf0f7240e9f36a3ff2c31ad75546be2
        command: [sh, -c]
        # Values are passed as env vars (below), never interpolated into the shell.
        # jq assembles the {"inputs": ...} body with --arg so text containing quotes
        # or newlines is escaped correctly. The model id is URL-path data; it is
        # expanded by curl, not the shell.
        args:
          - |
            set -eu
            BODY=$(jq -cn --arg t "${INPUT_TEXT}" '{inputs: $t}')
            curl -sSf -X POST \
              "https://router.huggingface.co/hf-inference/models/${MODEL}" \
              -H "Content-Type: application/json" \
              -H "Authorization: Bearer ${HF_TOKEN}" \
              --data-raw "${BODY}"
        env:
          - name: MODEL
            value: "{{inputs.parameters.model}}"
          - name: INPUT_TEXT
            value: "{{inputs.parameters.input-text}}"
          - name: HF_TOKEN
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.token-secret-name}}"
                key: "{{inputs.parameters.token-secret-key}}"
