-
Notifications
You must be signed in to change notification settings - Fork 68
Expand file tree
/
Copy pathtest.bat
More file actions
151 lines (127 loc) · 3.54 KB
/
test.bat
File metadata and controls
151 lines (127 loc) · 3.54 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
@echo off
chcp 65001 >nul
setlocal enabledelayedexpansion
REM Warp2Api Windows 对外接口测试脚本
REM 只测试对外API接口功能
REM 从 .env 文件加载环境变量(如果存在)
if exist ".env" (
for /f "tokens=*" %%i in (.env) do (
set "%%i"
)
)
REM 环境变量控制日志输出,默认不打印日志
REM 设置 W2A_VERBOSE=true 来启用详细日志输出
if "%W2A_VERBOSE%"=="" set "W2A_VERBOSE=false"
REM 颜色定义(Windows CMD不支持ANSI颜色,移除以保持一致性)
REM 日志函数
:log_info
if "%W2A_VERBOSE%"=="true" (
echo [%DATE% %TIME%] INFO: %~1
)
goto :eof
:log_success
if "%W2A_VERBOSE%"=="true" (
echo [%DATE% %TIME%] SUCCESS: %~1
)
goto :eof
:log_warning
if "%W2A_VERBOSE%"=="true" (
echo [%DATE% %TIME%] WARNING: %~1
)
goto :eof
:log_error
echo [%DATE% %TIME%] ERROR: %~1
goto :eof
if "%W2A_VERBOSE%"=="true" (
echo ============================================
echo 🚀 Warp2Api 对外接口测试
echo ============================================
REM 检查API服务器是否运行
echo 检查API服务器状态...
)
if exist ".env" (
REM 获取API_TOKEN
for /f "tokens=1,* delims==" %%a in (.env) do (
if "%%a"=="API_TOKEN" (
set "API_TOKEN=%%b"
set "API_TOKEN=!API_TOKEN:"=!"
)
)
)
curl -s http://localhost:28889/healthz >nul 2>&1
if %errorlevel% neq 0 (
call :log_error "OpenAI兼容API服务器 (28889) 未响应"
if "%W2A_VERBOSE%"=="true" (
echo 请先运行 start.bat 启动服务器
)
exit /b 1
)
if "%W2A_VERBOSE%"=="true" (
echo ✅ OpenAI兼容API服务器 (28889) 运行正常
)
REM 测试API接口
if "%W2A_VERBOSE%"=="true" (
echo.
echo 测试API接口...
)
REM 获取API Token
set "API_TOKEN="
if exist ".env" (
for /f "tokens=1,* delims==" %%a in (.env) do (
if "%%a"=="API_TOKEN" (
set "API_TOKEN=%%b"
set "API_TOKEN=!API_TOKEN:"=!"
)
)
)
if "!API_TOKEN!"=="" (
set "API_TOKEN=0000"
if "%W2A_VERBOSE%"=="true" (
echo ⚠️ 未找到API_TOKEN,使用默认值: !API_TOKEN!
)
)
REM 测试chat completions接口
if "%W2A_VERBOSE%"=="true" (
echo 测试 /v1/chat/completions 接口...
)
curl -s -X POST http://localhost:28889/v1/chat/completions ^
-H "Content-Type: application/json" ^
-H "Authorization: Bearer !API_TOKEN!" ^
-d "{\"model\": \"claude-4-sonnet\", \"messages\": [{\"role\": \"user\", \"content\": \"Say hello in one word\"}], \"max_tokens\": 10, \"stream\": false}" > response.json
findstr /C:"\"choices\"" response.json >nul 2>&1
if %errorlevel%==0 (
if "%W2A_VERBOSE%"=="true" (
call :log_success "Chat completions 接口正常"
)
) else (
call :log_error "Chat completions 接口异常"
if "%W2A_VERBOSE%"=="true" (
echo 响应内容:
type response.json
)
)
REM 测试models接口
if "%W2A_VERBOSE%"=="true" (
echo 测试 /v1/models 接口...
)
curl -s http://localhost:28889/v1/models > models_response.json
findstr /C:"\"data\"" models_response.json >nul 2>&1
if %errorlevel%==0 (
if "%W2A_VERBOSE%"=="true" (
call :log_success "Models 接口正常"
)
) else (
call :log_error "Models 接口异常"
if "%W2A_VERBOSE%"=="true" (
echo 响应内容:
type models_response.json
)
)
REM 清理临时文件
del response.json 2>nul
del models_response.json 2>nul
if "%W2A_VERBOSE%"=="true" (
echo.
call :log_success "🎉 对外接口测试完成!"
echo ============================================
)