-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_api_mode.sh
More file actions
executable file
·251 lines (205 loc) · 7.28 KB
/
Copy pathtest_api_mode.sh
File metadata and controls
executable file
·251 lines (205 loc) · 7.28 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
#!/bin/bash
# 🧪 AgentFlow API Mode Testing Script
# Tests cloud API integration without affecting local setup
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
CYAN='\033[0;36m'
NC='\033[0m'
echo -e "${BLUE}🧪 AgentFlow API Mode Test${NC}"
echo -e "${BLUE}Testing cloud API integration...${NC}"
echo ""
# Check if API keys are set
check_api_keys() {
echo -e "${CYAN}🔑 Checking API Keys...${NC}"
keys_found=0
if [ ! -z "$OPENAI_API_KEY" ]; then
echo -e " ${GREEN}✅ OpenAI API key found${NC}"
keys_found=$((keys_found + 1))
else
echo -e " ${YELLOW}⚠️ OpenAI API key not set${NC}"
fi
if [ ! -z "$GEMINI_API_KEY" ]; then
echo -e " ${GREEN}✅ Gemini API key found${NC}"
keys_found=$((keys_found + 1))
else
echo -e " ${YELLOW}⚠️ Gemini API key not set${NC}"
fi
if [ ! -z "$ANTHROPIC_API_KEY" ]; then
echo -e " ${GREEN}✅ Anthropic API key found${NC}"
keys_found=$((keys_found + 1))
else
echo -e " ${YELLOW}⚠️ Anthropic API key not set${NC}"
fi
echo ""
if [ $keys_found -eq 0 ]; then
echo -e "${RED}❌ No API keys found!${NC}"
echo ""
echo -e "${CYAN}To test API mode, set at least one API key:${NC}"
echo ""
echo -e "${YELLOW}OpenAI (Recommended):${NC}"
echo "export OPENAI_API_KEY='sk-your-key-here'"
echo ""
echo -e "${YELLOW}Google Gemini (Has free tier):${NC}"
echo "export GEMINI_API_KEY='your-key-here'"
echo ""
echo -e "${YELLOW}Anthropic Claude:${NC}"
echo "export ANTHROPIC_API_KEY='sk-ant-your-key-here'"
echo ""
echo -e "${CYAN}Get API keys at:${NC}"
echo "• OpenAI: https://platform.openai.com/api-keys"
echo "• Gemini: https://makersuite.google.com/app/apikey"
echo "• Anthropic: https://console.anthropic.com/"
exit 1
fi
echo -e "${GREEN}✅ Found $keys_found API key(s) - ready to test!${NC}"
echo ""
}
# Test API connections
test_api_connections() {
echo -e "${CYAN}🌐 Testing API Connections...${NC}"
echo ""
# Test OpenAI
if [ ! -z "$OPENAI_API_KEY" ]; then
echo -n " 🤖 Testing OpenAI... "
response=$(curl -s -w "%{http_code}" -o /dev/null \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
"https://api.openai.com/v1/models" \
--connect-timeout 10)
if [ "$response" = "200" ]; then
echo -e "${GREEN}Connected!${NC}"
else
echo -e "${RED}Failed (HTTP $response)${NC}"
fi
fi
# Test Gemini
if [ ! -z "$GEMINI_API_KEY" ]; then
echo -n " 🌈 Testing Gemini... "
response=$(curl -s -w "%{http_code}" -o /dev/null \
"https://generativelanguage.googleapis.com/v1beta/models?key=$GEMINI_API_KEY" \
--connect-timeout 10)
if [ "$response" = "200" ]; then
echo -e "${GREEN}Connected!${NC}"
else
echo -e "${RED}Failed (HTTP $response)${NC}"
fi
fi
# Test Anthropic (just validate key format)
if [ ! -z "$ANTHROPIC_API_KEY" ]; then
echo -n " 🧠 Testing Anthropic... "
if [[ $ANTHROPIC_API_KEY == sk-ant-* ]]; then
echo -e "${GREEN}Key format valid!${NC}"
else
echo -e "${RED}Invalid key format${NC}"
fi
fi
echo ""
}
# Test actual AI generation
test_ai_generation() {
echo -e "${CYAN}🚀 Testing AI Generation...${NC}"
echo ""
# Test OpenAI
if [ ! -z "$OPENAI_API_KEY" ]; then
echo -e " 🤖 ${YELLOW}Testing OpenAI GPT-3.5...${NC}"
start_time=$(date +%s)
response=$(curl -s \
-H "Authorization: Bearer $OPENAI_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"model": "gpt-3.5-turbo",
"messages": [{"role": "user", "content": "Say hello in exactly 5 words"}],
"max_tokens": 20
}' \
"https://api.openai.com/v1/chat/completions")
end_time=$(date +%s)
duration=$((end_time - start_time))
if echo "$response" | grep -q "choices"; then
content=$(echo "$response" | grep -o '"content":"[^"]*"' | sed 's/"content":"//' | sed 's/"//')
echo -e " ${GREEN}✅ Success (${duration}s): $content${NC}"
else
echo -e " ${RED}❌ Failed${NC}"
echo " Error: $(echo "$response" | head -n 1)"
fi
echo ""
fi
# Test Gemini
if [ ! -z "$GEMINI_API_KEY" ]; then
echo -e " 🌈 ${YELLOW}Testing Gemini Pro...${NC}"
start_time=$(date +%s)
response=$(curl -s \
-H "Content-Type: application/json" \
-d '{
"contents": [{
"parts": [{"text": "Say hello in exactly 5 words"}]
}]
}' \
"https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent?key=$GEMINI_API_KEY")
end_time=$(date +%s)
duration=$((end_time - start_time))
if echo "$response" | grep -q "candidates"; then
content=$(echo "$response" | grep -o '"text":"[^"]*"' | sed 's/"text":"//' | sed 's/"//' | head -n 1)
echo -e " ${GREEN}✅ Success (${duration}s): $content${NC}"
else
echo -e " ${RED}❌ Failed${NC}"
echo " Error: $(echo "$response" | head -n 1)"
fi
echo ""
fi
}
# Start backend in API mode
start_api_backend() {
echo -e "${CYAN}🖥️ Starting Backend in API Mode...${NC}"
echo ""
if [ ! -d "backend" ]; then
echo -e "${RED}❌ Backend directory not found!${NC}"
echo "Make sure you're in the AgentFlow root directory"
exit 1
fi
cd backend
if [ ! -d "node_modules" ]; then
echo -e "${YELLOW}📦 Installing backend dependencies...${NC}"
npm install
fi
echo -e "${BLUE}🚀 Starting backend in API mode...${NC}"
echo " Press Ctrl+C to stop"
echo ""
DEPLOYMENT_MODE=api \
OPENAI_API_KEY="$OPENAI_API_KEY" \
GEMINI_API_KEY="$GEMINI_API_KEY" \
ANTHROPIC_API_KEY="$ANTHROPIC_API_KEY" \
npm run dev
}
# Main execution
main() {
echo -e "${CYAN}This script will:${NC}"
echo "1. Check your API keys"
echo "2. Test API connections"
echo "3. Test AI generation"
echo "4. Start backend in API mode"
echo ""
read -p "Continue? (y/N): " -n 1 -r
echo ""
if [[ ! $REPLY =~ ^[Yy]$ ]]; then
echo "Test cancelled."
exit 0
fi
check_api_keys
test_api_connections
test_ai_generation
echo -e "${GREEN}🎉 API tests completed!${NC}"
echo ""
read -p "Start backend in API mode? (y/N): " -n 1 -r
echo ""
if [[ $REPLY =~ ^[Yy]$ ]]; then
start_api_backend
else
echo -e "${CYAN}You can start API mode manually with:${NC}"
echo "export DEPLOYMENT_MODE=api"
echo "./start_backend.sh"
fi
}
# Run main function
main "$@"