55 lines
1.9 KiB
Bash
Executable File
55 lines
1.9 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
set -euo pipefail
|
|
|
|
ROOT_OVERRIDE="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
|
|
export ROOT_OVERRIDE
|
|
# shellcheck disable=SC1091
|
|
source "${ROOT_OVERRIDE}/scripts/common.sh"
|
|
|
|
init_log selftest-native
|
|
acquire_lock jr-sql-ai-native-model.lock
|
|
print_header "selftest-native: START"
|
|
|
|
load_env
|
|
need_cmd curl
|
|
need_cmd python
|
|
need_cmd "$OLLAMA_BIN"
|
|
need_cmd grep
|
|
check_for_legacy_docker_ollama
|
|
[[ -x "$SQLAI_BIN" ]] || fail "bin/sqlai missing or not executable at ${SQLAI_BIN}" 70
|
|
|
|
log "selftest-native: ensuring local Ollama runtime is ready at ${OLLAMA_URL}"
|
|
ensure_ollama_ready "$OLLAMA_API_MAX_WAIT" "$OLLAMA_API_START_WAIT" || fail "Ollama API not reachable at ${OLLAMA_URL}" 71
|
|
ok "selftest-native: Ollama API reachable"
|
|
|
|
tags="$(fetch_tags)"
|
|
[[ -n "$tags" ]] || fail "/api/tags returned empty body" 72
|
|
printf '%s' "$tags" | is_json || fail "/api/tags did not return valid JSON" 73
|
|
ok "selftest-native: /api/tags returned valid JSON"
|
|
|
|
model_in_tags "$EXPERT_MODEL" "$tags" || fail "expert model missing: ${EXPERT_MODEL}" 74
|
|
ok "selftest-native: expert model present: ${EXPERT_MODEL}"
|
|
|
|
if [[ -n "$BASE_MODEL" ]]; then
|
|
model_in_tags "$BASE_MODEL" "$tags" || fail "base model missing: ${BASE_MODEL}" 75
|
|
ok "selftest-native: base model present: ${BASE_MODEL}"
|
|
fi
|
|
|
|
log "selftest-native: warmup request via sqlai"
|
|
set +e
|
|
"$SQLAI_BIN" ask --text "Warmup: reply with exactly 'OK'." --no-metrics >/dev/null 2>&1
|
|
rc=$?
|
|
set -e
|
|
[[ "$rc" -eq 0 ]] || warn "warmup failed rc=${rc}"
|
|
|
|
log "selftest-native: real query via sqlai"
|
|
set +e
|
|
out="$("$SQLAI_BIN" ask --text "Give a concise checklist to troubleshoot parameter sniffing in SQL Server 2022. Keep it technical." --no-metrics 2>&1)"
|
|
rc=$?
|
|
set -e
|
|
[[ "$rc" -eq 0 ]] || fail "real query failed rc=${rc}" 76
|
|
[[ -n "${out//[[:space:]]/}" ]] || fail "real query returned empty output" 77
|
|
ok "selftest-native: real query returned non-empty output"
|
|
|
|
print_footer "selftest-native: END status=OK log=${LOG_FILE}"
|