-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-streaming.sh
More file actions
executable file
·256 lines (220 loc) · 8.55 KB
/
test-streaming.sh
File metadata and controls
executable file
·256 lines (220 loc) · 8.55 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
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
#!/bin/bash
echo "🌊 Testing Streaming Functionality - Copilot Ollama Bridge"
echo "========================================================"
echo ""
# Colors for output
GREEN='\033[0;32m'
RED='\033[0;31m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Configuration
BRIDGE_PORT=11435
BASE_URL="http://localhost:${BRIDGE_PORT}"
# Function to test if server is running
check_server() {
echo -e "${BLUE}🔍 Checking if Copilot Bridge is running on port ${BRIDGE_PORT}...${NC}"
if curl -s "${BASE_URL}/api/version" > /dev/null 2>&1; then
echo -e "${GREEN}✅ Server is running${NC}"
return 0
else
echo -e "${RED}❌ Server is not running. Please start the Copilot Bridge extension.${NC}"
return 1
fi
}
# Function to test OpenAI streaming
test_openai_streaming() {
echo -e "\n${BLUE}📡 Testing OpenAI /v1/chat/completions streaming...${NC}"
echo "----------------------------------------"
echo -e "${YELLOW}Request: Simple streaming test${NC}"
curl -N -X POST "${BASE_URL}/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-token" \
-d '{
"model": "copilot:latest",
"messages": [
{"role": "user", "content": "Count from 1 to 5, with each number on a new line."}
],
"stream": true,
"max_tokens": 50
}' 2>/dev/null | head -20
echo -e "\n${GREEN}✅ OpenAI streaming test completed${NC}"
}
# Function to test OpenAI streaming with usage
test_openai_streaming_with_usage() {
echo -e "\n${BLUE}📊 Testing OpenAI streaming with usage information...${NC}"
echo "----------------------------------------------------"
echo -e "${YELLOW}Request: Streaming with usage stats${NC}"
curl -N -X POST "${BASE_URL}/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-token" \
-d '{
"model": "copilot:latest",
"messages": [
{"role": "user", "content": "Write a short haiku about coding."}
],
"stream": true,
"stream_options": {
"include_usage": true
}
}' 2>/dev/null | tail -10
echo -e "\n${GREEN}✅ OpenAI streaming with usage test completed${NC}"
}
# Function to test Ollama streaming
test_ollama_streaming() {
echo -e "\n${BLUE}🦙 Testing Ollama /api/chat streaming...${NC}"
echo "--------------------------------------"
echo -e "${YELLOW}Request: Ollama format streaming${NC}"
curl -N -X POST "${BASE_URL}/api/chat" \
-H "Content-Type: application/json" \
-d '{
"model": "copilot:latest",
"messages": [
{"role": "user", "content": "Explain what streaming is in 2 sentences."}
],
"stream": true
}' 2>/dev/null | head -10
echo -e "\n${GREEN}✅ Ollama streaming test completed${NC}"
}
# Function to test complex content
test_complex_content() {
echo -e "\n${BLUE}🔧 Testing complex content format (OpenAI)...${NC}"
echo "---------------------------------------------"
echo -e "${YELLOW}Request: Complex content array format${NC}"
curl -N -X POST "${BASE_URL}/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-token" \
-d '{
"model": "copilot:latest",
"messages": [
{
"role": "user",
"content": [
{"type": "text", "text": "What is the capital of France?"}
]
}
],
"stream": true
}' 2>/dev/null | head -15
echo -e "\n${GREEN}✅ Complex content streaming test completed${NC}"
}
# Function to test non-streaming for comparison
test_non_streaming() {
echo -e "\n${BLUE}📝 Testing non-streaming for comparison...${NC}"
echo "------------------------------------------"
echo -e "${YELLOW}Request: Non-streaming OpenAI${NC}"
curl -s -X POST "${BASE_URL}/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-token" \
-d '{
"model": "copilot:latest",
"messages": [
{"role": "user", "content": "Say hello world."}
],
"stream": false
}' | jq '.' 2>/dev/null || echo "Response received (jq not available for formatting)"
echo -e "\n${GREEN}✅ Non-streaming test completed${NC}"
}
# Function to test error handling
test_error_handling() {
echo -e "\n${BLUE}🚨 Testing error handling in streaming...${NC}"
echo "----------------------------------------"
echo -e "${YELLOW}Request: Invalid model name${NC}"
curl -N -X POST "${BASE_URL}/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-token" \
-d '{
"model": "invalid:model",
"messages": [
{"role": "user", "content": "This should handle errors gracefully."}
],
"stream": true
}' 2>/dev/null | head -5
echo -e "\n${GREEN}✅ Error handling test completed${NC}"
}
# Function to test different models
test_different_models() {
echo -e "\n${BLUE}🔄 Testing different model families...${NC}"
echo "-------------------------------------"
# Test gpt-4o
echo -e "${YELLOW}Request: Using copilot:gpt-4o${NC}"
curl -N -X POST "${BASE_URL}/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-token" \
-d '{
"model": "copilot:gpt-4o",
"messages": [
{"role": "user", "content": "Hello from GPT-4o!"}
],
"stream": true
}' 2>/dev/null | head -5
echo -e "\n${YELLOW}Request: Using copilot:latest${NC}"
curl -N -X POST "${BASE_URL}/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-token" \
-d '{
"model": "copilot:latest",
"messages": [
{"role": "user", "content": "Hello from latest!"}
],
"stream": true
}' 2>/dev/null | head -5
echo -e "\n${GREEN}✅ Different models test completed${NC}"
}
# Function to measure streaming performance
test_streaming_performance() {
echo -e "\n${BLUE}⚡ Testing streaming performance...${NC}"
echo "----------------------------------"
echo -e "${YELLOW}Measuring time to first chunk...${NC}"
START_TIME=$(date +%s.%N)
# Get just the first few chunks to measure initial latency
timeout 10s curl -N -X POST "${BASE_URL}/v1/chat/completions" \
-H "Content-Type: application/json" \
-H "Authorization: Bearer dummy-token" \
-d '{
"model": "copilot:latest",
"messages": [
{"role": "user", "content": "Write a paragraph about the benefits of streaming responses."}
],
"stream": true
}' 2>/dev/null | head -3
END_TIME=$(date +%s.%N)
DURATION=$(echo "$END_TIME - $START_TIME" | bc 2>/dev/null || echo "Time measurement unavailable")
echo -e "\n${GREEN}✅ Performance test completed (Duration: ${DURATION}s)${NC}"
}
# Main execution
main() {
echo "Starting comprehensive streaming tests..."
echo "========================================"
# Check if server is running
if ! check_server; then
exit 1
fi
# Run all tests
test_openai_streaming
test_openai_streaming_with_usage
test_ollama_streaming
test_complex_content
test_non_streaming
test_error_handling
test_different_models
test_streaming_performance
echo -e "\n${GREEN}🎉 All streaming tests completed!${NC}"
echo -e "${BLUE}📋 Test Summary:${NC}"
echo " ✅ OpenAI streaming format"
echo " ✅ OpenAI streaming with usage stats"
echo " ✅ Ollama streaming format"
echo " ✅ Complex content arrays"
echo " ✅ Non-streaming comparison"
echo " ✅ Error handling"
echo " ✅ Multiple model families"
echo " ✅ Performance measurement"
echo ""
echo -e "${YELLOW}💡 Tips:${NC}"
echo " - Check VS Code Output channel 'Copilot Bridge' for detailed logs"
echo " - Streaming should show real-time chunks, not all at once"
echo " - Each test shows different aspects of streaming functionality"
echo ""
}
# Run main function
main "$@"