-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_proxy.sh
More file actions
executable file
Β·144 lines (123 loc) Β· 4.27 KB
/
test_proxy.sh
File metadata and controls
executable file
Β·144 lines (123 loc) Β· 4.27 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#!/bin/bash
# Test script for Ollama Proxy
# This simulates the problematic requests that Elephas sends
set -e
PROXY_URL="${PROXY_URL:-http://127.0.0.1:11435}"
OLLAMA_URL="${OLLAMA_URL:-http://127.0.0.1:11434}"
echo "π§ͺ Testing Ollama Proxy"
echo "======================="
echo "Proxy URL: $PROXY_URL"
echo "Ollama URL: $OLLAMA_URL"
echo ""
# Check if Ollama is running
echo "π‘ Checking if Ollama is running..."
if ! curl -s "${OLLAMA_URL}/api/version" > /dev/null; then
echo "β Error: Ollama is not running on ${OLLAMA_URL}"
echo "Please start Ollama first."
exit 1
fi
echo "β
Ollama is running"
echo ""
# Check if proxy is running
echo "π‘ Checking if proxy is running..."
if ! curl -s "${PROXY_URL}/api/version" > /dev/null; then
echo "β Error: Proxy is not running on ${PROXY_URL}"
echo "Please start the proxy first: cargo run"
exit 1
fi
echo "β
Proxy is running"
echo ""
# Get list of models
echo "π Fetching available models..."
MODELS=$(curl -s "${PROXY_URL}/api/tags" | grep -o '"name":"[^"]*"' | cut -d'"' -f4 || echo "")
if [ -z "$MODELS" ]; then
echo "β οΈ No models found. Please pull a model first:"
echo " ollama pull nomic-embed-text"
exit 1
fi
echo "Available models:"
echo "$MODELS" | head -5
echo ""
# Test 1: Embedding request with excessive num_ctx (simulating Elephas behavior)
echo "π§ͺ Test 1: Embedding request with num_ctx=131072 (should be reduced to 8192)"
echo "------------------------------------------------------------------------"
# Check if nomic-embed-text is available
if echo "$MODELS" | grep -q "nomic-embed-text"; then
MODEL="nomic-embed-text"
elif echo "$MODELS" | grep -q "embed"; then
MODEL=$(echo "$MODELS" | grep "embed" | head -1)
else
echo "β οΈ No embedding model found. Skipping embedding test."
MODEL=""
fi
if [ -n "$MODEL" ]; then
echo "Using model: $MODEL"
# Send request through proxy
RESPONSE=$(curl -s -X POST "${PROXY_URL}/v1/embeddings" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"${MODEL}\",
\"input\": \"Hello, this is a test.\",
\"options\": {
\"num_ctx\": 131072
}
}")
if echo "$RESPONSE" | grep -q "embedding"; then
echo "β
Request successful - check proxy logs for parameter modifications"
else
echo "β Request failed:"
echo "$RESPONSE"
fi
else
echo "β οΈ Skipping Test 1 - no embedding model available"
fi
echo ""
# Test 2: Chat request (should pass through unchanged if within limits)
echo "π§ͺ Test 2: Chat request with reasonable num_ctx"
echo "------------------------------------------------"
CHAT_MODEL=$(echo "$MODELS" | grep -v "embed" | head -1)
if [ -n "$CHAT_MODEL" ]; then
echo "Using model: $CHAT_MODEL"
RESPONSE=$(curl -s -X POST "${PROXY_URL}/api/generate" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"${CHAT_MODEL}\",
\"prompt\": \"Say 'test successful'\",
\"stream\": false,
\"options\": {
\"num_ctx\": 4096
}
}")
if echo "$RESPONSE" | grep -q "response"; then
echo "β
Request successful - check proxy logs"
else
echo "β Request failed:"
echo "$RESPONSE"
fi
else
echo "β οΈ Skipping Test 2 - no chat model available"
fi
echo ""
# Test 3: Request without num_ctx (proxy should add it for embedding models)
echo "π§ͺ Test 3: Embedding request without num_ctx (proxy should add it)"
echo "-------------------------------------------------------------------"
if [ -n "$MODEL" ]; then
echo "Using model: $MODEL"
RESPONSE=$(curl -s -X POST "${PROXY_URL}/v1/embeddings" \
-H "Content-Type: application/json" \
-d "{
\"model\": \"${MODEL}\",
\"input\": \"Test without explicit context length.\"
}")
if echo "$RESPONSE" | grep -q "embedding"; then
echo "β
Request successful - proxy should have added num_ctx automatically"
else
echo "β Request failed:"
echo "$RESPONSE"
fi
else
echo "β οΈ Skipping Test 3 - no embedding model available"
fi
echo ""
echo "π Testing complete!"
echo "Check the proxy logs to verify parameter modifications."