q
File size: 3,167 Bytes
96601d6
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
<!DOCTYPE html>
<html>
<head>
    <title>API 接口说明</title>
    <link rel="icon" type="image/png" href="/static/favicon.png">
    <style>
        body { font-family: Arial, sans-serif; margin: 20px; }
        h1 { color: #333; }
        .endpoint { margin: 20px 0; padding: 15px; background: #f5f5f5; border-radius: 5px; }
        .method { font-weight: bold; color: #007bff; }
        .url { color: #28a745; }
        .description { margin-top: 10px; }
    </style>
</head>
<body>
    <h1>API 接口说明</h1>
    
    <h2>项目概述</h2>
    <p>这是一个基于 FastAPI 实现的通义千问 API 代理服务器,用于转发和处理与通义千问 API 的通信。</p>

    <h2>主要功能</h2>
    <ul>
        <li>模型列表获取 API</li>
        <li>聊天完成 API</li>
        <li>支持流式响应</li>
        <li>内置模型列表缓存机制</li>
        <li>自动重试机制</li>
    </ul>

    <h2>环境要求</h2>
    <ul>
        <li>Python 3.7+</li>
        <li>FastAPI 0.104.1+</li>
        <li>Uvicorn 0.24.0+</li>
        <li>HTTPX 0.25.1+</li>
    </ul>

    <h2>安装步骤</h2>
    <ol>
        <li>克隆项目到本地</li>
        <li>安装依赖:
            <pre><code>pip install -r requirements.txt</code></pre>
        </li>
        <li>使用 Docker(可选):
            <pre><code>docker build -t qwen-api-proxy .
docker run -p 8000:8000 qwen-api-proxy</code></pre>
        </li>
    </ol>

    <h2>运行服务</h2>
    <pre><code>python qwen.py</code></pre>
    <p>或使用 uvicorn:</p>
    <pre><code>uvicorn qwen:app --host 0.0.0.0 --port 8000</code></pre>
    <p>服务将在 <a href="http://localhost:8000">http://localhost:8000</a> 上运行。</p>

    <h2>错误处理</h2>
    <ul>
        <li>服务内置了自动重试机制,最多重试3次</li>
        <li>500错误或HTML响应会触发重试</li>
        <li>401错误表示未授权,需要检查token</li>
        <li>400错误表示请求参数有误</li>
    </ul>

    <h2>获取 API Key</h2>
    <ol>
        <li>访问 <a href="https://chat.qwenlm.ai/">https://chat.qwenlm.ai/</a> 并登录</li>
        <li>打开浏览器开发者工具(通常按 F12)</li>
        <li>切换到"应用程序"选项卡</li>
        <li>在左侧菜单中选择"Cookies" -> "https://chat.qwenlm.ai"</li>
        <li>找到名称为"token"的cookie</li>
        <li>复制其值,这就是你的API Key</li>
    </ol>

    <h2>许可证</h2>
    <p>本项目采用 MIT License 开源许可证。</p>
    
    <div class="endpoint">
        <div class="method">GET</div>
        <div class="url">/api/models</div>
        <div class="description">
            获取可用模型列表<br>
            请求头需要包含 Authorization: Bearer {api_key}
        </div>
    </div>

    <div class="endpoint">
        <div class="method">POST</div>
        <div class="url">/api/chat/completions</div>
        <div class="description">
            与模型进行对话<br>
            请求头需要包含 Authorization: Bearer {api_key}<br>
            支持流式响应(stream: true)
        </div>
    </div>
</body>
</html>