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.