diff --git a/.env.template b/.env.template index 3c85990..c9a2d9d 100644 --- a/.env.template +++ b/.env.template @@ -5,4 +5,5 @@ SERPER_KEY=your_serper_key BING_KEY=your_bing_key SEARCH_SERVICE=your_search_service MAX_RESULTS=the results of search -CRAWL_RESULTS=the r \ No newline at end of file +CRAWL_RESULTS=the reults of search you want to crawl +APIBASE=https://api.openai.com \ No newline at end of file diff --git a/README-EN.md b/README-EN.md index eee917f..8c3a813 100644 --- a/README-EN.md +++ b/README-EN.md @@ -131,4 +131,18 @@ Special note: Vercel project does not support streaming output and has a 10s res One-click deployment -[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Ffatwang2%2Fsearch2ai&env=SEARCH_SERVICE&envDescription=%E6%9A%82%E6%97%B6%E6%94%AF%E6%8C%81google%E3%80%81bing%E3%80%81se \ No newline at end of file +[![Deploy with Vercel](https://vercel.com/button)](https://vercel.com/new/clone?repository-url=https%3A%2F%2Fgithub.com%2Ffatwang2%2Fsearch2ai&env=SEARCH_SERVICE&envDescription=%E6%9A%82%E6%97%B6%E6%94%AF%E6%8C%81google%E3%80%81bing%E3%80%81serpapi%E3%80%81serper%E3%80%81duckduckgo%EF%BC%8C%E5%BF%85%E5%A1%AB) + +To ensure updates, you can also first fork this project and then deploy it on Vercel yourself + +# Risk statement +To ensure the persistence of this project, certain interface requests will be forwarded via [search1api](https://search.search2ai.one). Please be assured that this forwarding service does not save any private data. + +# Future Iterations +- Support for Azure OpenAI +- Fix streaming output issues in Vercel project +- Improve the speed of streaming output +- Support more vertical searches + + + diff --git a/gemini.js b/gemini.js index 8aec259..8c5f12a 100644 --- a/gemini.js +++ b/gemini.js @@ -365,4 +365,8 @@ async function fetchWithRetry(url, options, maxRetries = 3) { }); } function errorResponse(message, statusCode = 400) { - return new Response(JSON.stringi \ No newline at end of file + return new Response(JSON.stringify({ error: message }), { + status: statusCode, + headers: { 'Content-Type': 'application/json' }, + }); + } \ No newline at end of file diff --git a/units/news.js b/units/news.js index 712a34d..fe6efa7 100644 --- a/units/news.js +++ b/units/news.js @@ -27,4 +27,22 @@ async function news(query) { if (!response.ok) { console.error(`API 请求失败, 状态码: ${response.status}`); - return `API 请求失败, 状态码: ${response.s \ No newline at end of file + return `API 请求失败, 状态码: ${response.status}`; + } + + const contentType = response.headers.get("content-type"); + if (!contentType || !contentType.includes("application/json")) { + console.error("收到的响应不是有效的 JSON 格式"); + return "收到的响应不是有效的 JSON 格式"; + } + + const data = await response.json(); + console.log('新闻搜索服务调用完成'); + return JSON.stringify(data); + } catch (error) { + console.error(`在 news 函数中捕获到错误: ${error}`); + return `在 news 函数中捕获到错误: ${error}`; + } +} + +module.exports = news; \ No newline at end of file diff --git a/units/search.js b/units/search.js index b47171a..91a9d83 100644 --- a/units/search.js +++ b/units/search.js @@ -41,4 +41,9 @@ async function search(query) { console.log('自定义搜索服务调用完成'); return JSON.stringify(data); } catch (error) { - console.error(`在 search 函数 \ No newline at end of file + console.error(`在 search 函数中捕获到错误: ${error}`); + return `在 search 函数中捕获到错误: ${error}`; + } +} + +module.exports = search; \ No newline at end of file