forked from lza6/perplexity-2api-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstart_and_test.ps1
More file actions
33 lines (29 loc) · 1.24 KB
/
start_and_test.ps1
File metadata and controls
33 lines (29 loc) · 1.24 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
# 启动服务
Write-Host "正在启动服务..." -ForegroundColor Green
$process = Start-Process -NoNewWindow -PassThru -FilePath "python" -ArgumentList "-m uvicorn main:app --host 127.0.0.1 --port 8091 --reload"
Start-Sleep -Seconds 5
Write-Host "服务已启动,正在测试 API..." -ForegroundColor Green
# 测试 /v1/chat/completions 端点
$url = "http://127.0.0.1:8091/v1/chat/completions"
$headers = @{
"Content-Type" = "application/json"
"Authorization" = "Bearer 1"
}
$body = @{
model = "gemini30pro"
messages = @(@{role = "user"; content = "Hello"})
stream = $false
} | ConvertTo-Json
try {
$response = Invoke-RestMethod -Uri $url -Method Post -Headers $headers -Body $body -ErrorAction Stop
Write-Host "✅ API 测试成功!响应:" -ForegroundColor Green
$response | ConvertTo-Json -Depth 10
} catch {
Write-Host "❌ API 测试失败:" -ForegroundColor Red
Write-Host "状态码: $($_.Exception.Response.StatusCode.value__)" -ForegroundColor Red
Write-Host "响应内容: $($_.Exception.Response.Body | Out-String)" -ForegroundColor Red
}
# 停止服务
Write-Host "正在停止服务..." -ForegroundColor Yellow
Stop-Process -Id $process.Id -Force
Write-Host "服务已停止。" -ForegroundColor Green