29 lines
935 B
Bash
Executable file
29 lines
935 B
Bash
Executable file
#!/bin/sh
|
|
# Capture a non-streaming local OpenAI-compatible completion measurement.
|
|
set -eu
|
|
|
|
if [ "$#" -ne 4 ]; then
|
|
echo "usage: $0 BASE_URL MODEL PROMPT_FILE OUTPUT_JSON" >&2
|
|
exit 1
|
|
fi
|
|
|
|
base_url=$1
|
|
model=$2
|
|
prompt_file=$3
|
|
output=$4
|
|
|
|
if [ ! -r "$prompt_file" ]; then
|
|
echo "gem: prompt file is not readable: $prompt_file" >&2
|
|
exit 1
|
|
fi
|
|
|
|
request=$(jq -n --rawfile prompt "$prompt_file" --arg model "$model" \
|
|
'{model: $model, messages: [{role: "user", content: $prompt}], max_tokens: 128, stream: false}')
|
|
metrics=$(mktemp /private/tmp/gem-server-probe.XXXXXX)
|
|
trap 'rm -f "$metrics"' EXIT
|
|
|
|
curl --fail --silent --show-error --output "$output" --write-out '%{time_starttransfer} %{time_total}\n' \
|
|
-H 'Content-Type: application/json' --data "$request" "$base_url/chat/completions" > "$metrics"
|
|
|
|
read -r ttfb total < "$metrics"
|
|
printf 'ttfb_seconds=%s\ntotal_seconds=%s\nresponse=%s\n' "$ttfb" "$total" "$output"
|