Spaces:
Paused
Paused
Update hf.js
Browse files
hf.js
CHANGED
|
@@ -166,8 +166,12 @@ app.get('/hf/v1/models', (req, res) => {
|
|
| 166 |
// 聊天完成度代理
|
| 167 |
app.post('/hf/v1/chat/completions', async (req, res) => {
|
| 168 |
try {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 169 |
// 生成 checksum
|
| 170 |
-
const checksum = `
|
| 171 |
|
| 172 |
// 构建请求头
|
| 173 |
const headers = {
|
|
@@ -182,23 +186,28 @@ app.post('/hf/v1/chat/completions', async (req, res) => {
|
|
| 182 |
// 构建请求体
|
| 183 |
const requestBody = {
|
| 184 |
...req.body,
|
| 185 |
-
stream: false,
|
| 186 |
temperature: req.body.temperature || 0.7,
|
| 187 |
max_tokens: req.body.max_tokens || 1000
|
| 188 |
};
|
| 189 |
|
|
|
|
|
|
|
|
|
|
| 190 |
// 转发请求到目标服务器
|
| 191 |
const response = await axios.post('http://localhost:3010/v1/chat/completions', requestBody, {
|
| 192 |
headers: headers,
|
| 193 |
-
timeout: 30000
|
| 194 |
});
|
| 195 |
|
|
|
|
|
|
|
|
|
|
| 196 |
// 返回响应
|
| 197 |
res.status(response.status).json(response.data);
|
| 198 |
} catch (error) {
|
| 199 |
console.error('Error in chat completions:', error);
|
| 200 |
if (error.response) {
|
| 201 |
-
// 打印详细错误信息
|
| 202 |
console.error('Response error:', {
|
| 203 |
status: error.response.status,
|
| 204 |
data: error.response.data,
|
|
@@ -218,6 +227,7 @@ app.post('/hf/v1/chat/completions', async (req, res) => {
|
|
| 218 |
|
| 219 |
|
| 220 |
|
|
|
|
| 221 |
// 主页路由
|
| 222 |
app.get('/', (req, res) => {
|
| 223 |
const htmlContent = `
|
|
|
|
| 166 |
// 聊天完成度代理
|
| 167 |
app.post('/hf/v1/chat/completions', async (req, res) => {
|
| 168 |
try {
|
| 169 |
+
// 打印请求内容
|
| 170 |
+
console.log('Incoming request body:', JSON.stringify(req.body, null, 2));
|
| 171 |
+
console.log('Incoming request headers:', req.headers);
|
| 172 |
+
|
| 173 |
// 生成 checksum
|
| 174 |
+
const checksum = `ICMlQsvO${getRandomIDPro({ dictType: 'max', size: 64 })}/${getRandomIDPro({ dictType: 'max', size: 64 })}`;
|
| 175 |
|
| 176 |
// 构建请求头
|
| 177 |
const headers = {
|
|
|
|
| 186 |
// 构建请求体
|
| 187 |
const requestBody = {
|
| 188 |
...req.body,
|
| 189 |
+
stream: false,
|
| 190 |
temperature: req.body.temperature || 0.7,
|
| 191 |
max_tokens: req.body.max_tokens || 1000
|
| 192 |
};
|
| 193 |
|
| 194 |
+
console.log('Outgoing request body:', JSON.stringify(requestBody, null, 2));
|
| 195 |
+
console.log('Outgoing request headers:', headers);
|
| 196 |
+
|
| 197 |
// 转发请求到目标服务器
|
| 198 |
const response = await axios.post('http://localhost:3010/v1/chat/completions', requestBody, {
|
| 199 |
headers: headers,
|
| 200 |
+
timeout: 30000
|
| 201 |
});
|
| 202 |
|
| 203 |
+
// 打印响应内容
|
| 204 |
+
console.log('Response data:', JSON.stringify(response.data, null, 2));
|
| 205 |
+
|
| 206 |
// 返回响应
|
| 207 |
res.status(response.status).json(response.data);
|
| 208 |
} catch (error) {
|
| 209 |
console.error('Error in chat completions:', error);
|
| 210 |
if (error.response) {
|
|
|
|
| 211 |
console.error('Response error:', {
|
| 212 |
status: error.response.status,
|
| 213 |
data: error.response.data,
|
|
|
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
+
|
| 231 |
// 主页路由
|
| 232 |
app.get('/', (req, res) => {
|
| 233 |
const htmlContent = `
|