char-fork/llama.cpp

git clone https://git.t4t.associates/char-fork/llama.cpp

Georgi Gerganovexamples : add llama-eval (#21152)fde69a360

char/aliceai-t5-moe
2.7 KiB86 linesraw
1#!/bin/bash
2
3set -e
4
5# Get the directory where this script is located
6SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
7
8echo "=== llama-server-simulator Test Script ==="
9echo ""
10
11PORT=8033
12SUCCESS_RATE=0.8
13TEST_PORT=8034
14
15echo "Starting simulator on port $PORT with success rate $SUCCESS_RATE..."
16source "$SCRIPT_DIR/venv/bin/activate"
17python3 "$SCRIPT_DIR/llama-server-simulator.py" --port $PORT --success-rate $SUCCESS_RATE > /tmp/simulator-test.log 2>&1 &
18SIMULATOR_PID=$!
19
20echo "Waiting for simulator to start..."
21sleep 5
22
23# Helper function to make a request and extract the answer
24make_request() {
25  local question="$1"
26  curl -s -X POST http://localhost:$PORT/v1/chat/completions \
27    -H "Content-Type: application/json" \
28    -d "{
29      \"model\": \"llama\",
30      \"messages\": [
31        {\"role\": \"user\", \"content\": \"$question\"}
32      ],
33      \"temperature\": 0,
34      \"max_tokens\": 2048
35    }" | python3 -c "import sys, json; data = json.load(sys.stdin); print(data.get('choices', [{}])[0].get('message', {}).get('content', data.get('error', 'No response')))"
36}
37
38# Test question (repeated in multiple tests)
39TEST_QUESTION="Quadratic polynomials P(x) and Q(x) have leading coefficients 2 and -2, respectively. The graphs of both polynomials pass through the two points (16,54) and (20,53). Find P(0) + Q(0)."
40
41echo ""
42echo "=== Test 1: Correct Answer ==="
43echo "Sending request with known question..."
44answer=$(make_request "$TEST_QUESTION")
45echo "Answer: $answer"
46echo "Expected: 116"
47echo "Correct: $([ "$answer" == "116" ] && echo "Yes" || echo "No")"
48
49echo ""
50echo "=== Test 2: Wrong Answer ==="
51echo "Sending request with known question (success rate 0.0)..."
52answer=$(make_request "$TEST_QUESTION")
53echo "Answer: $answer"
54echo "Expected: 116"
55echo "Correct: $([ "$answer" == "116" ] && echo "Yes" || echo "No")"
56
57echo ""
58echo "=== Test 3: No Matching Question ==="
59echo "Sending request with non-matching text..."
60response=$(make_request "What is the capital of France?")
61echo "Response: $response"
62echo "Expected: No matching question found"
63echo "Correct: $([ "$response" == "No matching question found" ] && echo "Yes" || echo "No")"
64
65echo ""
66echo "=== Test 4: Success Rate Verification ==="
67echo "Sending 10 requests to test success rate..."
68correct_count=0
69for i in {1..10}; do
70  answer=$(make_request "$TEST_QUESTION")
71  if [ "$answer" == "116" ]; then
72    correct_count=$((correct_count + 1))
73  fi
74  echo "  Request $i: Answer = $answer"
75done
76echo "Correct answers: $correct_count/10"
77echo "Expected: ~8/10 (80% success rate)"
78echo "Success rate: $(echo "scale=1; $correct_count * 10" | bc)%"
79
80echo ""
81echo "=== Test Complete ==="
82echo "Stopping simulator..."
83kill $SIMULATOR_PID 2>/dev/null
84wait $SIMULATOR_PID 2>/dev/null || true
85
86echo "Simulator stopped."