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iddleware({
|
| 43 |
target: 'http://localhost:3010/v1/chat/completions',
|
|
@@ -89,6 +238,23 @@ app.get('/', (req, res) => {
|
|
| 89 |
margin-top: 20px;
|
| 90 |
border: 1px solid ${proxyConfig ? '#c3e6cb' : '#ffeeba'};
|
| 91 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 92 |
</style>
|
| 93 |
</head>
|
| 94 |
<body>
|
|
@@ -107,11 +273,34 @@ app.get('/', (req, res) => {
|
|
| 107 |
<strong>代理状态:</strong> ${proxyConfig ? '已启用' : '未启用'}
|
| 108 |
${proxyConfig ? `<p>代理服务器: ${proxyConfig.host}:${proxyConfig.port}</p>` : ''}
|
| 109 |
</div>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
</div>
|
| 111 |
<script>
|
| 112 |
const url = new URL(window.location.href);
|
| 113 |
const link = url.protocol + '//' + url.host + '/hf/v1';
|
| 114 |
document.getElementById('endpoint-url').textContent = link;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 115 |
</script>
|
| 116 |
</body>
|
| 117 |
</html>
|
|
|
|
| 38 |
}
|
| 39 |
}
|
| 40 |
|
| 41 |
+
// 添加模型列表API
|
| 42 |
+
app.get('/hf/v1/models', (req, res) => {
|
| 43 |
+
const models = {
|
| 44 |
+
"object": "list",
|
| 45 |
+
"data": [
|
| 46 |
+
{
|
| 47 |
+
"id": "claude-3.5-sonnet",
|
| 48 |
+
"object": "model",
|
| 49 |
+
"created": 1706745938,
|
| 50 |
+
"owned_by": "cursor"
|
| 51 |
+
},
|
| 52 |
+
{
|
| 53 |
+
"id": "gpt-4",
|
| 54 |
+
"object": "model",
|
| 55 |
+
"created": 1706745938,
|
| 56 |
+
"owned_by": "cursor"
|
| 57 |
+
},
|
| 58 |
+
{
|
| 59 |
+
"id": "gpt-4o",
|
| 60 |
+
"object": "model",
|
| 61 |
+
"created": 1706745938,
|
| 62 |
+
"owned_by": "cursor"
|
| 63 |
+
},
|
| 64 |
+
{
|
| 65 |
+
"id": "claude-3-opus",
|
| 66 |
+
"object": "model",
|
| 67 |
+
"created": 1706745938,
|
| 68 |
+
"owned_by": "cursor"
|
| 69 |
+
},
|
| 70 |
+
{
|
| 71 |
+
"id": "gpt-3.5-turbo",
|
| 72 |
+
"object": "model",
|
| 73 |
+
"created": 1706745938,
|
| 74 |
+
"owned_by": "cursor"
|
| 75 |
+
},
|
| 76 |
+
{
|
| 77 |
+
"id": "gpt-4-turbo-2024-04-09",
|
| 78 |
+
"object": "model",
|
| 79 |
+
"created": 1706745938,
|
| 80 |
+
"owned_by": "cursor"
|
| 81 |
+
},
|
| 82 |
+
{
|
| 83 |
+
"id": "gpt-4o-128k",
|
| 84 |
+
"object": "model",
|
| 85 |
+
"created": 1706745938,
|
| 86 |
+
"owned_by": "cursor"
|
| 87 |
+
},
|
| 88 |
+
{
|
| 89 |
+
"id": "gemini-1.5-flash-500k",
|
| 90 |
+
"object": "model",
|
| 91 |
+
"created": 1706745938,
|
| 92 |
+
"owned_by": "cursor"
|
| 93 |
+
},
|
| 94 |
+
{
|
| 95 |
+
"id": "claude-3-haiku-200k",
|
| 96 |
+
"object": "model",
|
| 97 |
+
"created": 1706745938,
|
| 98 |
+
"owned_by": "cursor"
|
| 99 |
+
},
|
| 100 |
+
{
|
| 101 |
+
"id": "claude-3-5-sonnet-200k",
|
| 102 |
+
"object": "model",
|
| 103 |
+
"created": 1706745938,
|
| 104 |
+
"owned_by": "cursor"
|
| 105 |
+
},
|
| 106 |
+
{
|
| 107 |
+
"id": "claude-3-5-sonnet-20241022",
|
| 108 |
+
"object": "model",
|
| 109 |
+
"created": 1706745938,
|
| 110 |
+
"owned_by": "cursor"
|
| 111 |
+
},
|
| 112 |
+
{
|
| 113 |
+
"id": "gpt-4o-mini",
|
| 114 |
+
"object": "model",
|
| 115 |
+
"created": 1706745938,
|
| 116 |
+
"owned_by": "cursor"
|
| 117 |
+
},
|
| 118 |
+
{
|
| 119 |
+
"id": "o1-mini",
|
| 120 |
+
"object": "model",
|
| 121 |
+
"created": 1706745938,
|
| 122 |
+
"owned_by": "cursor"
|
| 123 |
+
},
|
| 124 |
+
{
|
| 125 |
+
"id": "o1-preview",
|
| 126 |
+
"object": "model",
|
| 127 |
+
"created": 1706745938,
|
| 128 |
+
"owned_by": "cursor"
|
| 129 |
+
},
|
| 130 |
+
{
|
| 131 |
+
"id": "o1",
|
| 132 |
+
"object": "model",
|
| 133 |
+
"created": 1706745938,
|
| 134 |
+
"owned_by": "cursor"
|
| 135 |
+
},
|
| 136 |
+
{
|
| 137 |
+
"id": "claude-3.5-haiku",
|
| 138 |
+
"object": "model",
|
| 139 |
+
"created": 1706745938,
|
| 140 |
+
"owned_by": "cursor"
|
| 141 |
+
},
|
| 142 |
+
{
|
| 143 |
+
"id": "gemini-exp-1206",
|
| 144 |
+
"object": "model",
|
| 145 |
+
"created": 1706745938,
|
| 146 |
+
"owned_by": "cursor"
|
| 147 |
+
},
|
| 148 |
+
{
|
| 149 |
+
"id": "gemini-2.0-flash-thinking-exp",
|
| 150 |
+
"object": "model",
|
| 151 |
+
"created": 1706745938,
|
| 152 |
+
"owned_by": "cursor"
|
| 153 |
+
},
|
| 154 |
+
{
|
| 155 |
+
"id": "gemini-2.0-flash-exp",
|
| 156 |
+
"object": "model",
|
| 157 |
+
"created": 1706745938,
|
| 158 |
+
"owned_by": "cursor"
|
| 159 |
+
},
|
| 160 |
+
{
|
| 161 |
+
"id": "deepseek-v3",
|
| 162 |
+
"object": "model",
|
| 163 |
+
"created": 1706745938,
|
| 164 |
+
"owned_by": "cursor"
|
| 165 |
+
},
|
| 166 |
+
{
|
| 167 |
+
"id": "deepseek-r1",
|
| 168 |
+
"object": "model",
|
| 169 |
+
"created": 1706745938,
|
| 170 |
+
"owned_by": "cursor"
|
| 171 |
+
},
|
| 172 |
+
// 新增模型
|
| 173 |
+
{
|
| 174 |
+
"id": "claude-3.7-sonnet",
|
| 175 |
+
"object": "model",
|
| 176 |
+
"created": 1706745938,
|
| 177 |
+
"owned_by": "cursor"
|
| 178 |
+
},
|
| 179 |
+
{
|
| 180 |
+
"id": "claude-3.7-sonnet-thinking",
|
| 181 |
+
"object": "model",
|
| 182 |
+
"created": 1706745938,
|
| 183 |
+
"owned_by": "cursor"
|
| 184 |
+
}
|
| 185 |
+
]
|
| 186 |
+
};
|
| 187 |
+
res.json(models);
|
| 188 |
+
});
|
| 189 |
+
|
| 190 |
// 配置代理中间件
|
| 191 |
app.use('/hf/v1/chat/completions', createProxyMiddleware({
|
| 192 |
target: 'http://localhost:3010/v1/chat/completions',
|
|
|
|
| 238 |
margin-top: 20px;
|
| 239 |
border: 1px solid ${proxyConfig ? '#c3e6cb' : '#ffeeba'};
|
| 240 |
}
|
| 241 |
+
.models-container {
|
| 242 |
+
margin-top: 20px;
|
| 243 |
+
border-top: 1px solid #eee;
|
| 244 |
+
padding-top: 20px;
|
| 245 |
+
}
|
| 246 |
+
.model-list {
|
| 247 |
+
display: grid;
|
| 248 |
+
grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
|
| 249 |
+
gap: 10px;
|
| 250 |
+
margin-top: 15px;
|
| 251 |
+
}
|
| 252 |
+
.model-item {
|
| 253 |
+
background: #f0f0f0;
|
| 254 |
+
padding: 8px 12px;
|
| 255 |
+
border-radius: 4px;
|
| 256 |
+
font-size: 0.9em;
|
| 257 |
+
}
|
| 258 |
</style>
|
| 259 |
</head>
|
| 260 |
<body>
|
|
|
|
| 273 |
<strong>代理状态:</strong> ${proxyConfig ? '已启用' : '未启用'}
|
| 274 |
${proxyConfig ? `<p>代理服务器: ${proxyConfig.host}:${proxyConfig.port}</p>` : ''}
|
| 275 |
</div>
|
| 276 |
+
|
| 277 |
+
<div class="models-container">
|
| 278 |
+
<h3>支持的模型</h3>
|
| 279 |
+
<div id="model-list" class="model-list">加载中...</div>
|
| 280 |
+
</div>
|
| 281 |
</div>
|
| 282 |
<script>
|
| 283 |
const url = new URL(window.location.href);
|
| 284 |
const link = url.protocol + '//' + url.host + '/hf/v1';
|
| 285 |
document.getElementById('endpoint-url').textContent = link;
|
| 286 |
+
|
| 287 |
+
// 加载模型列表
|
| 288 |
+
fetch('/hf/v1/models')
|
| 289 |
+
.then(response => response.json())
|
| 290 |
+
.then(data => {
|
| 291 |
+
const modelListEl = document.getElementById('model-list');
|
| 292 |
+
modelListEl.innerHTML = '';
|
| 293 |
+
|
| 294 |
+
data.data.forEach(model => {
|
| 295 |
+
const modelEl = document.createElement('div');
|
| 296 |
+
modelEl.className = 'model-item';
|
| 297 |
+
modelEl.textContent = model.id;
|
| 298 |
+
modelListEl.appendChild(modelEl);
|
| 299 |
+
});
|
| 300 |
+
})
|
| 301 |
+
.catch(err => {
|
| 302 |
+
document.getElementById('model-list').textContent = '加载模型失败: ' + err.message;
|
| 303 |
+
});
|
| 304 |
</script>
|
| 305 |
</body>
|
| 306 |
</html>
|