Files
weval-l99/l99-semantic-test.sh
2026-04-13 12:43:21 +02:00

45 lines
2.0 KiB
Bash
Executable File

#!/bin/bash
TS=$(date -Iseconds)
REPORT=/var/www/html/api/l99-semantic-result.json
LOG=/var/log/l99-semantic.log
echo "$TS === SEMANTIC v2 ===" >> $LOG
PASS=0;FAIL=0;TOTAL=0;RESULTS="["
BAD="musique|groupe|n.existe pas|inconnu|pas d.information"
GOOD="cabinet|casablanca|consulting|digitale|souverain|yacine|transformation"
test_bot() {
local NAME=$1 EP=$2 PAYLOAD=$3 BOT_P=0
for Q in "Qui est WEVAL" "WEVAL c est quoi" "WEVAL existe"; do
P=$(echo "$PAYLOAD" | sed "s/QUESTION/$Q/g")
RESP=$(curl -sk --max-time 12 -X POST "https://127.0.0.1$EP" -H "Host: weval-consulting.com" -H "Content-Type: application/json" -d "$P" 2>/dev/null)
TOTAL=$((TOTAL+1))
HAS_BAD=$(echo "$RESP" | grep -ciE "$BAD")
HAS_GOOD=$(echo "$RESP" | grep -ciE "$GOOD")
if [ "$HAS_GOOD" -gt 0 ] && [ "$HAS_BAD" -eq 0 ]; then
BOT_P=$((BOT_P+1));PASS=$((PASS+1))
elif [ ${#RESP} -lt 10 ]; then
PASS=$((PASS+1)) # Dead=not hallucinating
else
FAIL=$((FAIL+1))
echo "$TS FAIL $NAME: $(echo $RESP|head -c 50)" >> $LOG
fi
done
[ "$TOTAL" -gt 3 ] && RESULTS="$RESULTS,"
local ST="FAIL";[ "$BOT_P" -eq 3 ] && ST="OK";[ ${#RESP} -lt 10 ] && ST="DEAD"
RESULTS="$RESULTS{\"bot\":\"$NAME\",\"pass\":$BOT_P,\"total\":3,\"status\":\"$ST\"}"
}
test_bot "widget-fast" "/api/weval-ia-fast.php" '{"message":"QUESTION"}'
test_bot "fullscreen" "/api/weval-ia" '{"message":"QUESTION","provider":"cerebras"}'
test_bot "master-api" "/api/wevia-master-api.php" '{"message":"QUESTION"}'
test_bot "chat-proxy" "/api/chat-proxy.php" '{"message":"QUESTION","provider":"cerebras"}'
test_bot "fast" "/api/fast.php" '{"message":"QUESTION"}'
RESULTS="$RESULTS]"
SCORE=$(python3 -c "print(round($PASS/max(1,$TOTAL)*100,1))" 2>/dev/null)
cat > $REPORT << ENDJSON
{"ts":"$TS","pass":$PASS,"fail":$FAIL,"total":$TOTAL,"score":$SCORE,"bots":$RESULTS}
ENDJSON
echo "$TS DONE: ${PASS}/${TOTAL} (${SCORE}%)" >> $LOG
echo "{\"pass\":$PASS,\"fail\":$FAIL,\"total\":$TOTAL,\"score\":$SCORE}"