File size: 1,903 Bytes
d3cadd5
 
 
 
0edbd7b
d3cadd5
0edbd7b
d3cadd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
0edbd7b
 
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
#!/usr/bin/env python3
"""测试 Kiro 反向代理"""

import requests
import os

PROXY_URL = os.getenv("KIRO_PROXY_URL", "http://127.0.0.1:8080").rstrip("/")

def test_health():
    print("1. 测试健康检查...")
    r = requests.get(f"{PROXY_URL}/")
    print(f"   ✅ {r.json()}")

def test_token():
    print("\n2. 检查 Token 状态...")
    r = requests.get(f"{PROXY_URL}/token/status")
    data = r.json()
    if data.get("valid"):
        print(f"   ✅ Token 有效,过期时间: {data.get('expires_at')}")
    else:
        print(f"   ❌ Token 无效: {data.get('error')}")

def test_models():
    print("\n3. 列出可用模型...")
    r = requests.get(f"{PROXY_URL}/v1/models")
    models = r.json().get("data", [])
    for m in models:
        print(f"   - {m['id']}")

def test_chat():
    print("\n4. 测试聊天接口...")
    r = requests.post(
        f"{PROXY_URL}/v1/chat/completions",
        json={
            "model": "claude-sonnet-4",
            "messages": [
                {"role": "user", "content": "说一句话测试"}
            ]
        },
        timeout=60
    )
    
    if r.status_code == 200:
        data = r.json()
        content = data["choices"][0]["message"]["content"]
        print(f"   ✅ AI 回复: {content[:200]}...")
    else:
        print(f"   ❌ 错误 {r.status_code}: {r.text}")

if __name__ == "__main__":
    print("=" * 50)
    print("Kiro 反向代理测试")
    print("=" * 50)
    
    try:
        test_health()
        test_token()
        test_models()
        test_chat()
        print("\n" + "=" * 50)
        print("测试完成")
        print("=" * 50)
    except requests.exceptions.ConnectionError:
        print("\n❌ 连接失败!请先启动代理服务器:")
        print("   python run.py")
        print("如需自定义地址/端口:设置环境变量 KIRO_PROXY_URL (例如 http://127.0.0.1:6696)")