Spaces:
Paused
Paused
Update hf.js
Browse files
hf.js
CHANGED
|
@@ -179,48 +179,21 @@ app.post('/hf/v1/chat/completions', async (req, res) => {
|
|
| 179 |
'Authorization': authHeader,
|
| 180 |
'Content-Type': 'application/json',
|
| 181 |
'x-cursor-checksum': checksum,
|
|
|
|
| 182 |
'User-Agent': 'cursor/0.2.0',
|
| 183 |
-
'Accept': 'application/json'
|
| 184 |
-
'Connection': 'keep-alive',
|
| 185 |
-
'Cookie': `user_token=${token}`, // 添加 cookie
|
| 186 |
-
'x-cursor-token': token, // 添加 cursor token
|
| 187 |
-
'Origin': 'https://cursor.sh',
|
| 188 |
-
'Referer': 'https://cursor.sh/',
|
| 189 |
-
'Host': 'cursor.sh'
|
| 190 |
};
|
| 191 |
|
| 192 |
// 构建请求体
|
| 193 |
const requestBody = {
|
| 194 |
...req.body,
|
| 195 |
-
stream: false
|
| 196 |
-
user: {
|
| 197 |
-
id: token.split('::')[0] // 添加用户ID
|
| 198 |
-
}
|
| 199 |
};
|
| 200 |
|
| 201 |
-
console.log('Request details:', {
|
| 202 |
-
url: 'http://localhost:3010/v1/chat/completions',
|
| 203 |
-
method: 'POST',
|
| 204 |
-
headers: {
|
| 205 |
-
...headers,
|
| 206 |
-
'Authorization': 'Bearer [TOKEN]',
|
| 207 |
-
'Cookie': 'user_token=[TOKEN]',
|
| 208 |
-
'x-cursor-token': '[TOKEN]'
|
| 209 |
-
},
|
| 210 |
-
body: requestBody
|
| 211 |
-
});
|
| 212 |
-
|
| 213 |
// 转发请求到目标服务器
|
| 214 |
const response = await axios.post('http://localhost:3010/v1/chat/completions', requestBody, {
|
| 215 |
headers: headers,
|
| 216 |
-
timeout: 30000
|
| 217 |
-
validateStatus: status => true
|
| 218 |
-
});
|
| 219 |
-
|
| 220 |
-
console.log('Response details:', {
|
| 221 |
-
status: response.status,
|
| 222 |
-
headers: response.headers,
|
| 223 |
-
data: response.data
|
| 224 |
});
|
| 225 |
|
| 226 |
// 返回响应
|
|
@@ -228,14 +201,8 @@ app.post('/hf/v1/chat/completions', async (req, res) => {
|
|
| 228 |
} catch (error) {
|
| 229 |
console.error('Error in chat completions:', error);
|
| 230 |
if (error.response) {
|
| 231 |
-
console.error('Response error:', {
|
| 232 |
-
status: error.response.status,
|
| 233 |
-
data: error.response.data,
|
| 234 |
-
headers: error.response.headers
|
| 235 |
-
});
|
| 236 |
res.status(error.response.status).json(error.response.data);
|
| 237 |
} else {
|
| 238 |
-
console.error('Request error:', error.message);
|
| 239 |
res.status(500).json({
|
| 240 |
error: 'Internal server error',
|
| 241 |
message: error.message
|
|
|
|
| 179 |
'Authorization': authHeader,
|
| 180 |
'Content-Type': 'application/json',
|
| 181 |
'x-cursor-checksum': checksum,
|
| 182 |
+
'x-cursor-token': token,
|
| 183 |
'User-Agent': 'cursor/0.2.0',
|
| 184 |
+
'Accept': 'application/json'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 185 |
};
|
| 186 |
|
| 187 |
// 构建请求体
|
| 188 |
const requestBody = {
|
| 189 |
...req.body,
|
| 190 |
+
stream: false
|
|
|
|
|
|
|
|
|
|
| 191 |
};
|
| 192 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
// 转发请求到目标服务器
|
| 194 |
const response = await axios.post('http://localhost:3010/v1/chat/completions', requestBody, {
|
| 195 |
headers: headers,
|
| 196 |
+
timeout: 30000
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 197 |
});
|
| 198 |
|
| 199 |
// 返回响应
|
|
|
|
| 201 |
} catch (error) {
|
| 202 |
console.error('Error in chat completions:', error);
|
| 203 |
if (error.response) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 204 |
res.status(error.response.status).json(error.response.data);
|
| 205 |
} else {
|
|
|
|
| 206 |
res.status(500).json({
|
| 207 |
error: 'Internal server error',
|
| 208 |
message: error.message
|