Upload 2 files
Browse files- src/index.js +28 -5
src/index.js
CHANGED
|
@@ -56,9 +56,16 @@ const makeRequest = async (session_id, requestModel, messages) => {
|
|
| 56 |
};
|
| 57 |
|
| 58 |
// console.log(requestConfig)
|
| 59 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 60 |
} catch (error) {
|
| 61 |
console.log('error1', error)
|
|
|
|
| 62 |
}
|
| 63 |
}
|
| 64 |
|
|
@@ -75,6 +82,11 @@ router.post('/v1/chat/completions', async (ctx) => {
|
|
| 75 |
|
| 76 |
try {
|
| 77 |
const response = await makeRequest(session_id, model, messages)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 78 |
if (stream == "true" || stream == true) {
|
| 79 |
ctx.set({
|
| 80 |
'Content-Type': 'text/event-stream',
|
|
@@ -211,8 +223,11 @@ router.post('/v1/chat/completions', async (ctx) => {
|
|
| 211 |
|
| 212 |
} catch (error) {
|
| 213 |
console.error('请求处理出错:', error)
|
| 214 |
-
ctx.status = 500
|
| 215 |
-
ctx.body = {
|
|
|
|
|
|
|
|
|
|
| 216 |
}
|
| 217 |
})
|
| 218 |
|
|
@@ -229,6 +244,11 @@ router.post('/hf/v1/chat/completions', async (ctx) => {
|
|
| 229 |
|
| 230 |
try {
|
| 231 |
const response = await makeRequest(session_id, model, messages)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 232 |
if (stream == "true" || stream == true) {
|
| 233 |
ctx.set({
|
| 234 |
'Content-Type': 'text/event-stream',
|
|
@@ -355,8 +375,11 @@ router.post('/hf/v1/chat/completions', async (ctx) => {
|
|
| 355 |
}
|
| 356 |
} catch (error) {
|
| 357 |
console.error('请求处理出错:', error)
|
| 358 |
-
ctx.status = 500
|
| 359 |
-
ctx.body = {
|
|
|
|
|
|
|
|
|
|
| 360 |
}
|
| 361 |
})
|
| 362 |
|
|
|
|
| 56 |
};
|
| 57 |
|
| 58 |
// console.log(requestConfig)
|
| 59 |
+
const response = await fetch("https://www.genspark.ai/api/copilot/ask", requestConfig)
|
| 60 |
+
|
| 61 |
+
if (!response.ok) {
|
| 62 |
+
throw new Error(`HTTP error! status: ${response.status}`)
|
| 63 |
+
}
|
| 64 |
+
|
| 65 |
+
return response
|
| 66 |
} catch (error) {
|
| 67 |
console.log('error1', error)
|
| 68 |
+
throw error // 重新抛出错误,让调用者处理
|
| 69 |
}
|
| 70 |
}
|
| 71 |
|
|
|
|
| 82 |
|
| 83 |
try {
|
| 84 |
const response = await makeRequest(session_id, model, messages)
|
| 85 |
+
|
| 86 |
+
if (!response.body) {
|
| 87 |
+
throw new Error('Response body is null')
|
| 88 |
+
}
|
| 89 |
+
|
| 90 |
if (stream == "true" || stream == true) {
|
| 91 |
ctx.set({
|
| 92 |
'Content-Type': 'text/event-stream',
|
|
|
|
| 223 |
|
| 224 |
} catch (error) {
|
| 225 |
console.error('请求处理出错:', error)
|
| 226 |
+
ctx.status = error.status || 500
|
| 227 |
+
ctx.body = {
|
| 228 |
+
error: error.message || '请求处理失败',
|
| 229 |
+
details: error.toString()
|
| 230 |
+
}
|
| 231 |
}
|
| 232 |
})
|
| 233 |
|
|
|
|
| 244 |
|
| 245 |
try {
|
| 246 |
const response = await makeRequest(session_id, model, messages)
|
| 247 |
+
|
| 248 |
+
if (!response.body) {
|
| 249 |
+
throw new Error('Response body is null')
|
| 250 |
+
}
|
| 251 |
+
|
| 252 |
if (stream == "true" || stream == true) {
|
| 253 |
ctx.set({
|
| 254 |
'Content-Type': 'text/event-stream',
|
|
|
|
| 375 |
}
|
| 376 |
} catch (error) {
|
| 377 |
console.error('请求处理出错:', error)
|
| 378 |
+
ctx.status = error.status || 500
|
| 379 |
+
ctx.body = {
|
| 380 |
+
error: error.message || '请求处理失败',
|
| 381 |
+
details: error.toString()
|
| 382 |
+
}
|
| 383 |
}
|
| 384 |
})
|
| 385 |
|