Source: oafp 35a922f9. See documentation baseline for availability and verification.

OpenAF processor examples

Below is a list of examples. You can check for more examples in https://docs.openaf.io/docs/guides/oafp/oafp-examples.html or by executing:

oafp -examples
# OR by keywords
oafp examples=llm
# OR by category
oafp examples=AWS::

πŸ₯‰ Basic

OUTPUT JSON: Creating ndjson file from json files

Command:

# Creates a data.ndjson file where each record is formatted from json files in /some/data
find /some/data -name "*.json" -exec oafp {} output=json \; > data.ndjson

FILTER PATH: Manipulate text in a field

Command:

# Get a json with the lyrics of a song
curl -s https://api.lyrics.ovh/v1/Coldplay/Viva%20La%20Vida | oafp path="substring(lyrics,index_of(lyrics, '\n'),length(lyrics))"

Results:

I used to rule the world
[...]
Oooooh Oooooh Oooooh

FILTER PATH: Docker ps formatting

Command:

oafp cmd="docker ps --format json" input=ndjson ndjsonjoin=true path="[].{id:ID,name:Names,state:State,image:Image,networks:Networks,ports:Ports,Status:Status}" sql="select * order by networks,state,name" output=ctable

Result:

     id     β”‚          name          β”‚ state β”‚            image             β”‚       networks       β”‚                         ports                         β”‚  Status
────────────┼────────────────────────┼───────┼──────────────────────────────┼──────────────────────┼───────────────────────────────────────────────────────┼──────────
af3adb5b8349β”‚registry                β”‚runningβ”‚registry:2                    β”‚bridge,k3d-k3s-defaultβ”‚0.0.0.0:5000->5000/tcp                                 β”‚Up 2 hours
cba6e3807b44β”‚k3d-k3s-default-server-0β”‚runningβ”‚rancher/k3s:v1.27.4-k3s1      β”‚k3d-k3s-default       β”‚                                                       β”‚Up 2 hours
b775ad480764β”‚k3d-k3s-default-serverlbβ”‚runningβ”‚ghcr.io/k3d-io/k3d-proxy:5.6.0β”‚k3d-k3s-default       β”‚80/tcp, 0.0.0.0:1080->1080/tcp, 0.0.0.0:45693->6443/tcpβ”‚Up 2 hours
[#3 rows]

ASK: Interactively ask questions

Command:

oafp in=ask
[
    (name: simple, prompt: "What is your name? ", type: question) |
    (name: secret, prompt: "Write a secret word: ", type: secret) |
    (name: option, prompt: "Which color you like best? ", type: choose, options: [ "blue" | "green" | "red" ]) |
    (name: multiple, prompt: "Choose the numbers you like more: ", type: multiple, options: [ "One" | "Two" | "Three" ], output: index, max: 2) |
    (name: char, prompt: "Did you like this? (Y/N)", type: char, options: YNyn)
]

The resull will be an array with β€˜name’ and the corresponding β€˜answer’.

πŸ₯ˆ Medium

FILTER PATH: Kubectl get pods formatting

Command:

oafp cmd="kubectl get pods -A -o json" path="items[].{ns:metadata.namespace,kind:metadata.ownerReferences[].kind,name:metadata.name,status:status.phase,restarts:sum(status.containerStatuses[].restartCount),node:spec.nodeName,age:timeago(status.startTime)}" sql="select * order by status,name" output=ctable

Result:

    ns     β”‚   kind   β”‚                 name                 β”‚ status  β”‚restartsβ”‚          node          β”‚     age
───────────┼──────────┼──────────────────────────────────────┼─────────┼────────┼────────────────────────┼──────────────
kube-systemβ”‚ReplicaSetβ”‚coredns-77ccd57875-5m44t              β”‚Running  β”‚0       β”‚k3d-k3s-default-server-0β”‚66 minutes ago
kube-systemβ”‚ReplicaSetβ”‚local-path-provisioner-957fdf8bc-24hmfβ”‚Running  β”‚0       β”‚k3d-k3s-default-server-0β”‚66 minutes ago
kube-systemβ”‚ReplicaSetβ”‚metrics-server-648b5df564-hzbwb       β”‚Running  β”‚0       β”‚k3d-k3s-default-server-0β”‚66 minutes ago
kube-systemβ”‚ReplicaSetβ”‚socks-server-d7c8c4d78-r6jc9          β”‚Running  β”‚0       β”‚k3d-k3s-default-server-0β”‚66 minutes ago
kube-systemβ”‚DaemonSet β”‚svclb-socks-server-78b973ca-zvf58     β”‚Running  β”‚0       β”‚k3d-k3s-default-server-0β”‚66 minutes ago
kube-systemβ”‚DaemonSet β”‚svclb-traefik-e1776788-7z2gf          β”‚Running  β”‚0       β”‚k3d-k3s-default-server-0β”‚66 minutes ago
kube-systemβ”‚ReplicaSetβ”‚traefik-64f55bb67d-g2vps              β”‚Running  β”‚0       β”‚k3d-k3s-default-server-0β”‚66 minutes ago
kube-systemβ”‚Job       β”‚helm-install-traefik-6j5zx            β”‚Succeededβ”‚1       β”‚k3d-k3s-default-server-0β”‚66 minutes ago
kube-systemβ”‚Job       β”‚helm-install-traefik-crd-z59fs        β”‚Succeededβ”‚0       β”‚k3d-k3s-default-server-0β”‚66 minutes ago
[#9 rows]

FILTER PATH:

Command:

oafp cmd="kubectl get nodes -o json" path="items[].{node:metadata.name,totalCPU:status.capacity.cpu,allocCPU:status.allocatable.cpu,totalMem:to_bytesAbbr(from_bytesAbbr(status.capacity.memory)),allocMem:to_bytesAbbr(from_bytesAbbr(status.allocatable.memory)),totalStorage:to_bytesAbbr(from_bytesAbbr(status.capacity.\"ephemeral-storage\")),allocStorage:to_bytesAbbr(to_number(status.allocatable.\"ephemeral-storage\")),conditions:join(\`, \`,status.conditions[].reason)}" output=ctable

Result:

          node          β”‚totalCPUβ”‚allocCPUβ”‚totalMemβ”‚allocMemβ”‚totalStorageβ”‚allocStorageβ”‚                                        conditions
────────────────────────┼────────┼────────┼────────┼────────┼────────────┼────────────┼───────────────────────────────────────────────────────────────────────────────────────────
k3d-k3s-default-server-0β”‚4       β”‚4       β”‚3.85 GB β”‚3.85 GB β”‚77.6 GB     β”‚73.8 GB     β”‚KubeletHasSufficientMemory, KubeletHasNoDiskPressure, KubeletHasSufficientPID, KubeletReady
[#1 row]

INPUT LLM: Using a LLM to generate a table

Setting up the LLM model and gather the data into a data.json file:

Command:

export OAFP_MODEL="(type: openai, model: gpt-3.5-turbo, key: ..., timeout: 900000)"
echo "list all United Nations secretaries with their corresponding 'name', their mandate 'begin date', their mandate 'end date' and their corresponding secretary 'numeral'" | oafp input=llm output=json > data.json

Checking the obtain data:

Result:

oafp data.json
─ secretaries β•­ [0] β•­ name      : Trygve Lie
              β”‚     β”œ begin date: 1946-02-01
              β”‚     β”œ end date  : 1952-11-10
              β”‚     β•° numeral   : 1
              β”œ [1] β•­ name      : Dag HammarskjΓΆld
              β”‚     β”œ begin date: 1953-04-10
              β”‚     β”œ end date  : 1961-09-18
              β”‚     β•° numeral   : 2
              β”œ [2] β•­ name      : U Thant
              β”‚     β”œ begin date: 1961-11-30
              β”‚     β”œ end date  : 1971-12-31
              β”‚     β•° numeral   : 3
              β”œ [3] β•­ name      : Kurt Waldheim
              β”‚     β”œ begin date: 1972-01-01
              β”‚     β”œ end date  : 1981-12-31
              β”‚     β•° numeral   : 4
              β”œ [4] β•­ name      : Javier PΓ©rez de CuΓ©llar
              β”‚     β”œ begin date: 1982-01-01
              β”‚     β”œ end date  : 1991-12-31
              β”‚     β•° numeral   : 5
              β”œ [5] β•­ name      : Boutros Boutros-Ghali
              β”‚     β”œ begin date: 1992-01-01
              β”‚     β”œ end date  : 1996-12-31
              β”‚     β•° numeral   : 6
              β”œ [6] β•­ name      : Kofi Annan
              β”‚     β”œ begin date: 1997-01-01
              β”‚     β”œ end date  : 2006-12-31
              β”‚     β•° numeral   : 7
              β”œ [7] β•­ name      : Ban Ki-moon
              β”‚     β”œ begin date: 2007-01-01
              β”‚     β”œ end date  : 2016-12-31
              β”‚     β•° numeral   : 8
              β•° [8] β•­ name      : AntΓ³nio Guterres
                    β”œ begin date: 2017-01-01
                    β”œ end date  : present
                    β•° numeral   : 9

Checking the data in a table format:

Result:

oafp data.json path=secretaries output=ctable
         name          β”‚begin dateβ”‚ end date β”‚numeral
───────────────────────┼──────────┼──────────┼───────
Trygve Lie             β”‚1946-02-01β”‚1952-11-10β”‚1
Dag HammarskjΓΆld       β”‚1953-04-10β”‚1961-09-18β”‚2
U Thant                β”‚1961-11-30β”‚1971-12-31β”‚3
Kurt Waldheim          β”‚1972-01-01β”‚1981-12-31β”‚4
Javier PΓ©rez de CuΓ©llarβ”‚1982-01-01β”‚1991-12-31β”‚5
Boutros Boutros-Ghali  β”‚1992-01-01β”‚1996-12-31β”‚6
Kofi Annan             β”‚1997-01-01β”‚2006-12-31β”‚7
Ban Ki-moon            β”‚2007-01-01β”‚2016-12-31β”‚8
AntΓ³nio Guterres       β”‚2017-01-01β”‚present   β”‚9
[#9 rows]

TRANSFORM LLM: Using a LLM to transform an input

Using the data gather in β€˜Using a LLM to generate a table’ use a LLM to transform it:

Command:

export OAFP_MODEL="(type: openai, model: gpt-3.5-turbo, key: ..., timeout: 900000)"
oafp data.json llmprompt="convert the numeral number into a roman number" path=secretaries output=ctable

Result:

         name          β”‚begin dateβ”‚ end date β”‚numeral
───────────────────────┼──────────┼──────────┼───────
Trygve Lie             β”‚1946-02-01β”‚1952-11-10β”‚I
Dag HammarskjΓΆld       β”‚1953-04-10β”‚1961-09-18β”‚II
U Thant                β”‚1961-11-30β”‚1971-12-31β”‚III
Kurt Waldheim          β”‚1972-01-01β”‚1981-12-31β”‚IV
Javier PΓ©rez de CuΓ©llarβ”‚1982-01-01β”‚1991-12-31β”‚V
Boutros Boutros-Ghali  β”‚1992-01-01β”‚1996-12-31β”‚VI
Kofi Annan             β”‚1997-01-01β”‚2006-12-31β”‚VII
Ban Ki-moon            β”‚2007-01-01β”‚2016-12-31β”‚VIII
AntΓ³nio Guterres       β”‚2017-01-01β”‚present   β”‚IX
[#9 rows]

INPUT LLM: Using a private LLM to generate sample data

Command:

export OAFP_MODEL="(type: ollama, model: 'mistral:instruct', url: 'https://models.local', timeout: 900000)"
echo "Output a JSON array with 15 cities where each entry has the 'city' name, the estimated population and the corresponding 'country'" | oafp input=llm output=json > data.json
oafp data.json output=ctable sql="select * order by population desc"

Result:

   city    β”‚populationβ”‚ country
───────────┼──────────┼──────────
Shanghai   β”‚270584000 β”‚China
Tokyo      β”‚37436958  β”‚Japan
Delhi      β”‚30290936  β”‚India
SΓ£o Paulo  β”‚21935296  β”‚Brazil
Beijing    β”‚21516000  β”‚China
Mexico Cityβ”‚21402981  β”‚Mexico
Mumbai     β”‚20712874  β”‚India
Cairo      β”‚20636449  β”‚Egypt
Osaka      β”‚19365701  β”‚Japan
Dhaka      β”‚18568373  β”‚Bangladesh
[#10 rows]

πŸ₯‡ Advanced

OUTPUT XLS: Creating an XLSx file with multiple sheets

Command:

# Processes each json file in /some/data creating and updating the data.xlsx file with a sheet for each file
find /some/data -name "*.json" | xargs -I '{}' /bin/sh -c 'oafp file={} output=xls xlsfile=data.xlsx xlsopen=false xlssheet=$(echo {} | sed "s/.*\/\(.*\)\.json/\1/g" )'

JSON Schema validation

See JSON Schema for validation examples, Ajv options, draft selection, v8 error fields and sample generation.

Stateless LLM decisions: Gemini, Ollama and OpenAI

Generate the request files below automatically, then edit state and questions:

oafp in=llmdecide llmdecidesample=gemini out=yaml > gemini-request.yaml
oafp in=llmdecide llmdecidesample=ollama out=yaml > ollama-request.yaml
oafp in=llmdecide llmdecidesample=openai out=yaml > openai-request.yaml

Sample output also supports out=json and requires no inference, input stream or credentials. Replace the explicit model/key placeholders below with your configuration. All providers use the same named question syntax; each command evaluates the whole state once. Alternatively set OAFP_MODEL (or OAF_DECIDE_MODEL, then OAF_MODEL as fallback), use llmenv=YOUR_CONFIG_ENV, or use the existing sBucket fields in llmoptions (secRepo, secBucket, secPass, secMainPass, secFile) and their OAFP_SEC* environment counterparts. See oafp help=usage for secret setup.

Gemini structured decisions

Save this complete request as gemini-request.yaml:

state:
  ticket: The customer was charged twice.
questions:
  route:
    type: choice
    instructions: Select the responsible team.
    criteria:
      billing: Charges, payments, and refunds
      technical: Software errors and outages
  urgent:
    type: boolean
    instructions: Does this require immediate attention?
  priority:
    type: score
    instructions: Assess the urgency.
    criteria:
      - Routine
      - Soon
      - Urgent
options:
  strategy: structured
export OAFP_MODEL="(type: gemini, model: YOUR_GEMINI_MODEL, key: YOUR_GEMINI_API_KEY)"
oafp in=llmdecide file=gemini-request.yaml out=json
oafp in=llmdecide file=gemini-request.yaml llmdecidestats=true out=json
# Alternatively supply the configuration directly:
oafp in=llmdecide file=gemini-request.yaml out=json llmoptions="(type: gemini, model: YOUR_GEMINI_MODEL, key: YOUR_GEMINI_API_KEY)"

Gemini uses schema-constrained structured output. Probability fields are null; requireProbabilities: true is unsupported. Optional request settings (replace the options block above) include explicit selection of the legacy schema:

options:
  strategy: structured
  providerOptions:
    schemaProfile: legacy-schema
    temperature: 0
    maxOutputTokens: 1024

The default schemaProfile is response-format; legacy-schema explicitly selects the older Schema format. Profiles do not mix or retry. Temperature is 0–2; maxOutputTokens is a positive integer.

Ollama native decisions

Save this complete request as ollama-request.yaml:

state:
  ticket: The customer was charged twice.
questions:
  route:
    type: choice
    instructions: Select the responsible team.
    criteria:
      billing: Charges, payments, and refunds
      technical: Software errors and outages
  urgent:
    type: boolean
    instructions: Does this require immediate attention?
  priority:
    type: score
    instructions: Assess the urgency.
    criteria:
      - Routine
      - Soon
      - Urgent
options:
  strategy: native
  requireProbabilities: true
  providerOptions:
    keepAlive: 0
export OAFP_MODEL="(type: ollama, url: 'http://localhost:11434', model: YOUR_DECISION_MODEL)"
oafp in=llmdecide file=ollama-request.yaml out=json
oafp in=llmdecide file=ollama-request.yaml path=answers.route.value out=raw
# Alternatively supply the configuration directly:
oafp in=llmdecide file=ollama-request.yaml out=json llmoptions="(type: ollama, url: 'http://localhost:11434', model: YOUR_DECISION_MODEL)"

Native decisions require Ollama v0.35.0+ and compatible scoring-capable GGUF weights/runner; an arbitrary chat model is insufficient. Choice and score questions support 2–26 criteria. The text-only serialized UTF-8 request body must be at most 65,536 bytes; state is never truncated. Root URLs and URLs ending in /v1 are supported; a base ending in /api is rejected. Models must already be available; decisions do not download or warm them up. keepAlive is optional and accepts a duration string or finite seconds, including zero.

Score levels are zero-based (Routine = 0, Soon = 1, Urgent = 2). selectedProbability measures the selected alternative’s probability; providerConfidence measures distribution concentration independently; expectedScore is the expectation and may differ from the selected level. Provider errors and invalid answers remain visible without strategy/model fallback. These examples describe the API contract, not verified live inference.

OpenAI native decisions API

Generate a request using the same state and named questions as above:

oafp in=llmdecide llmdecidesample=openai out=yaml > openai-request.yaml
export OAFP_MODEL="(type: openai, model: gpt-6-luna, key: YOUR_OPENAI_API_KEY)"
oafp in=llmdecide file=openai-request.yaml out=json
oafp in=llmdecide file=openai-request.yaml llmdecidestats=true out=json
oafp in=llmdecide file=openai-request.yaml path=answers.route.value out=raw
# Alternatively supply the configuration directly:
oafp in=llmdecide file=openai-request.yaml out=json llmoptions="(type: openai, model: gpt-6-luna, key: YOUR_OPENAI_API_KEY)"

The generated request selects strategy: native and requireProbabilities: true. OpenAF sends it to the official OpenAI /v1/decisions endpoint. The current adapter enables native decisions for gpt-6-luna; account and model access are checked by the provider. This requires an updated OpenAF runtime with OpenAI native decision support. The sample omits Ollama’s keepAlive option.

Ollama image decisions

Use Ollama v0.35.1+ with CLEF/CLEF Flash vision weights and an updated OpenAF runtime. Every question receives the same ordered images; state is required. For one local PNG, JPEG or WebP file:

{
  "state": "Inspect the screenshot for a visible error message.",
  "questions": {
    "error": { "type": "boolean", "instructions": "Is an error message visible?" }
  },
  "options": { "strategy": "native" }
}

Save this as image-request.json, then run:

oafp in=llmdecide file=image-request.json llmimage=screenshot.png out=json llmoptions="(type: ollama, url: 'http://localhost:11434', model: YOUR_VISION_DECISION_MODEL)"

For multiple images, place raw base64 strings in options.images in your request JSON/SLON/YAML. For example, generate a request with OpenAF:

var request = {
  state: "Compare the screenshots in order.",
  questions: { changed: { type: "boolean", instructions: "Did the visible error disappear in the second screenshot?" } },
  options: { strategy: "native", images: ["before.png", "after.png"].map(file =>
    af.fromBytes2String(af.toBase64Bytes(io.readFileBytes(file)))) }
}
io.writeFileString("image-request.json", stringify(request))

Run that request without llmimage; combining the shortcut with options.images is rejected. llmdecidestats=true supports both forms. URLs and data URLs are unsupported. OpenAF rejects image options on other providers, while Ollama validates image contents and vision support. Image requests may be up to 32 MiB including base64 and JSON; images are never truncated.

Add a decision classification column

Save the following as classify.yaml and configure OAFP_MODEL (or OAF_DECIDE_MODEL) with an OpenAF model configuration:

questions:
  category:
    type: choice
    instructions: Classify the ticket.
    criteria:
      billing: Payments, charges, and refunds
      technical: Software errors and outages
options:
  strategy: structured
statePath: description
assign:
  classification: answers.category.value
echo '[{"id":1,"description":"I was charged twice"},{"id":2,"description":"The app crashes"}]' | oafp llmdecide=classify.yaml parallel=true out=table

Use out=csv for a report or opath="[].classification" out=json for just the classifications. Omit statePath to send the entire entry, and omit assign to return full decision responses. Questions and options can also be supplied inline:

echo '[{"description":"I was charged twice"}]' | oafp llmdecide='(questions: (urgent: (type: boolean, instructions: "Does this require immediate attention?")), assign: (urgent: answers.urgent.value))' out=json

See USAGE’s Decision enrichment section for field collisions, stats extraction, model configuration and parallel failure behavior.


This site uses Just the Docs, a documentation theme for Jekyll.