Files

59 lines
2.5 KiB
Bash
Executable File

#!/usr/bin/env bash
# Quick end-to-end check: translate one fixed synthetic sentence with an installed Hy-MT3 model.
# Usage: scripts/smoke-ollama.sh [model-tag]
set -euo pipefail
cd "$(dirname "$0")/.."
BASE="${OLLAMA_BASE:-http://127.0.0.1:11434}"
TEXT="The quick brown fox jumps over the lazy dog. Please open https://example.com and set the limit to 10."
TARGET="German"
ver=$(curl -fsS --max-time 3 "$BASE/api/version" | jq -r .version) || { echo "✗ Ollama not reachable at $BASE"; exit 1; }
echo "✓ Ollama $ver"
models=$(curl -fsS "$BASE/api/tags" | jq -r '.models[].name' | grep -i 'hy-mt3' || true)
if [[ -z "$models" ]]; then
echo "✗ no Hy-MT3 model installed. Pull one:"
echo " ollama pull hf.co/tencent/Hy-MT3-7B-GGUF:Q4_K_M"
echo " ollama pull hf.co/tencent/Hy-MT3-1.8B-GGUF:Q4_K_M"
exit 1
fi
MODEL="${1:-}"
if [[ -z "$MODEL" ]]; then
MODEL=$(echo "$models" | grep -E '7B-GGUF' | head -1 || true)
[[ -z "$MODEL" ]] && MODEL=$(echo "$models" | head -1)
fi
if ! echo "$models" | grep -Fxq "$MODEL"; then
echo "✗ model not installed: $MODEL"
echo "$models" | sed 's/^/ installed: /'
exit 1
fi
PROMPT=$(printf 'Translate the following text into %s. Note that you should **only output the translated result without any additional explanation**:\n\n%s' "$TARGET" "$TEXT")
BODY=$(jq -nc --arg m "$MODEL" --arg p "$PROMPT" '{model:$m, messages:[{role:"user",content:$p}], stream:false, keep_alive:"30m",
options:{temperature:0.7, top_p:0.6, top_k:20, repeat_penalty:1.05, num_predict:512, num_ctx:8192}}')
res=$(curl -fsS "$BASE/api/chat" -H 'Content-Type: application/json' -d "$BODY")
content=$(jq -r '.message.content // ""' <<<"$res")
if [[ -z "${content//[[:space:]]/}" ]]; then
echo "✗ $MODEL returned an empty translation"
exit 1
fi
total=$(jq -r '(.total_duration // 0) / 1e9' <<<"$res")
load=$(jq -r '(.load_duration // 0) / 1e9' <<<"$res")
prompt_tokens=$(jq -r '.prompt_eval_count // 0' <<<"$res")
out_tokens=$(jq -r '.eval_count // 0' <<<"$res")
eval_secs=$(jq -r '(.eval_duration // 0) / 1e9' <<<"$res")
rate=$(awk -v t="$out_tokens" -v s="$eval_secs" 'BEGIN { if (s > 0) printf "%.2f", t/s; else print "?" }')
echo "✓ $MODEL"
echo "--- translation ---"
printf '%s\n' "$content" | head -c 800
printf '\n--- metrics ---\n'
printf 'total %.2fs · load %.2fs · prompt %s tokens · output %s tokens · %s tok/s\n' "$total" "$load" "$prompt_tokens" "$out_tokens" "$rate"
if ! grep -qi 'fuchs' <<<"$content"; then
echo "! expected 'Fuchs' in the German translation; review the output"
fi