apiVersion: argoproj.io/v1alpha1
kind: WorkflowTemplate
metadata:
  name: llm-prompt
  labels:
    dagweave.io/catalog-item: llm-prompt
  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.2"
    dagweave.io/catalog-category: "AI"
spec:
  entrypoint: prompt
  templates:
    - name: prompt
      inputs:
        parameters:
          # Base URL of an OpenAI-compatible API. The item POSTs to
          # <base-url>/v1/chat/completions. Point this at any OpenAI-compatible
          # gateway (OpenAI, Azure OpenAI, vLLM, LiteLLM, OpenRouter, ...).
          - name: base-url
            default: https://api.openai.com
          # Model identifier understood by the target endpoint.
          - name: model
          # The user prompt to send.
          - name: prompt
          # Name/key of a Kubernetes Secret holding the API key (sent as a bearer).
          - name: api-key-secret-name
            default: llm-api-key
          - name: api-key-secret-key
            default: api-key
      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 chat-completions request body with --arg so a prompt
        # containing quotes or newlines is escaped correctly, then the raw JSON
        # response is echoed for a downstream step to consume.
        args:
          - |
            set -eu
            BODY=$(jq -cn --arg m "${MODEL}" --arg p "${PROMPT}" \
              '{model: $m, messages: [{role: "user", content: $p}]}')
            curl -sSf -X POST "${BASE_URL}/v1/chat/completions" \
              -H "Content-Type: application/json" \
              -H "Authorization: Bearer ${API_KEY}" \
              --data-raw "${BODY}"
        env:
          - name: BASE_URL
            value: "{{inputs.parameters.base-url}}"
          - name: MODEL
            value: "{{inputs.parameters.model}}"
          - name: PROMPT
            value: "{{inputs.parameters.prompt}}"
          - name: API_KEY
            valueFrom:
              secretKeyRef:
                name: "{{inputs.parameters.api-key-secret-name}}"
                key: "{{inputs.parameters.api-key-secret-key}}"
