-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathtest_vision_proxy.sh
More file actions
executable file
·81 lines (66 loc) · 1.83 KB
/
Copy pathtest_vision_proxy.sh
File metadata and controls
executable file
·81 lines (66 loc) · 1.83 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/env bash
# Test vision capabilities through the proxy
# Usage: ./test_vision_proxy.sh [image_path]
set -euo pipefail
PROXY_URL="${PROXY_URL:-http://localhost:8081}"
IMAGE_PATH="${1:-dog.jpeg}"
PROMPT="${2:-Describe the attached image in detail.}"
if [[ ! -f "$IMAGE_PATH" ]]; then
echo "Image '$IMAGE_PATH' does not exist." >&2
exit 1
fi
# Get token from config
TOKEN=no_token
echo "Testing vision through proxy at $PROXY_URL..."
echo "Image: $IMAGE_PATH"
echo "Token: ${TOKEN:0:10}..."
# Encode image
IMAGE_MIME="$(file --brief --mime-type "$IMAGE_PATH")"
IMAGE_BASE64="$(
python3 - "$IMAGE_PATH" <<'PY'
import base64, sys
with open(sys.argv[1], "rb") as f:
print(base64.b64encode(f.read()).decode("ascii"))
PY
)"
# Create request payload
REQUEST_FILE="$(mktemp)"
trap 'rm -f "$REQUEST_FILE"' EXIT
jq -n \
--arg model "gpt-4o" \
--arg prompt "$PROMPT" \
--arg image "data:$IMAGE_MIME;base64,$IMAGE_BASE64" \
'{
model: $model,
messages: [
{
role: "user",
content: [
{type: "text", text: $prompt},
{type: "image_url", image_url: {url: $image}}
]
}
],
max_tokens: 500
}' > "$REQUEST_FILE"
echo "Request payload size: $(stat -f%z "$REQUEST_FILE") bytes"
echo "Sending request..."
# Send request through proxy (NOT directly to GitHub)
RESPONSE="$(curl -sS -X POST "$PROXY_URL/v1/chat/completions" \
-H "Content-Type: application/json" \
--data-binary @"$REQUEST_FILE")"
echo ""
echo "Response:"
echo "$RESPONSE" | jq .
# Extract and display just the content
CONTENT=$(echo "$RESPONSE" | jq -r '.choices[0].message.content // "No content"')
echo ""
echo "=== AI Response ==="
echo "$CONTENT"
echo ""
# Check for errors
if echo "$RESPONSE" | jq -e '.error' > /dev/null 2>&1; then
echo "ERROR in response!" >&2
exit 1
fi
echo "✓ Vision test successful!"