From ffa239a903799ddd2eaf40013298767e37f33ce9 Mon Sep 17 00:00:00 2001 From: fatwang2 Date: Wed, 6 Mar 2024 00:57:04 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0V0.1.8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README-EN.md | 23 +++++++++++++---------- README.md | 22 ++++++++++++---------- gemini.js | 14 ++++++++++++-- openai.js | 7 ++++--- units/news.js | 5 ++--- units/search.js | 1 + 6 files changed, 44 insertions(+), 28 deletions(-) diff --git a/README-EN.md b/README-EN.md index bf14559..aaeec85 100644 --- a/README-EN.md +++ b/README-EN.md @@ -7,6 +7,7 @@ Buy Me A Coffee # Version Updates +- V0.1.8, 20240305, support search1api search service, update Gemini version search variable configuration, open news search capability, add risk statement - V0.1.7, 20240224, Gemini version supports streaming output and is compatible with vision model - V0.1.6, 20240221, Supports Gemini model, can be temporarily configured through Cloudflare worker method - V0.1.5, 20240205, supports news search, making it more convenient to quickly browse news @@ -64,9 +65,9 @@ To keep the project updated, it is recommended to fork this repository first, th [![Deployed on Zeabur](https://zeabur.com/deployed-on-zeabur-dark.svg)](https://zeabur.com?referralCode=fatwang2&utm_source=fatwang2&utm_campaign=oss) Environment variables -- SEARCH_SERVICE: Currently supports google, bing, serpapi, serper, duckduckgo (recommended), required -- APIBASE: If you are using an OpenAI third-party proxy, you can fill it in here, note that v1 is not needed, not required -- NEWS_KEY: News search, if you need plz join in [telegram](https://sum4all.one/telegram)for the Key,free now +- SEARCH_SERVICE: temporarily supports search1api, google, bing, serpapi, serper, duckduckgo, required +- APIBASE: if you are using OpenAI three-way proxy, you can fill in here, note that you do not need to add v1, non-required! +- SEARCH1API_KEY: such as the selection of search1api required, I build their own search services, 0.99 U.S. dollars / 1000 times per month, the application address https://search2ai.online/docs - BING_KEY: Required if choosing bing search, please search for tutorials, application address https://search2ai.online/bing - GOOGLE_CX: Required if choosing Google search, Search engine ID, please search for tutorials, application address https://search2ai.online/googlecx - GOOGLE_KEY: Required if choosing Google search, API key, application address https://search2ai.online/googlekey @@ -79,9 +80,9 @@ Environment variables git clone https://github.com/fatwang2/search2ai ``` 2. Copy .env.template as .env, configure environment variables -- SEARCH_SERVICE: Currently supports google, bing, serpapi, serper, duckduckgo (recommended), required -- APIBASE: If you are using an OpenAI third-party proxy, you can fill it in here, note that v1 is not needed, not required -- NEWS_KEY: News search, if you need plz join in [telegram](https://sum4all.one/telegram)for the Key,free now +- SEARCH_SERVICE: temporarily supports search1api, google, bing, serpapi, serper, duckduckgo, required +- APIBASE: if you are using OpenAI three-way proxy, you can fill in here, note that you do not need to add v1, non-required! +- SEARCH1API_KEY: such as the selection of search1api required, I build their own search services, 0.99 U.S. dollars / 1000 times per month, the application address https://search2ai.online/docs - BING_KEY: Required if choosing bing search, please search for tutorials, application address https://search2ai.online/bing - GOOGLE_CX: Required if choosing Google search, Search engine ID, please search for tutorials, application address https://search2ai.online/googlecx - GOOGLE_KEY: Required if choosing Google search, API key, application address https://search2ai.online/googlekey @@ -103,9 +104,9 @@ http://localhost:3014/v1/chat/completions 2. Configure variables in the worker(only openai) ![Effect Example](pictures/worker.png) -- SEARCH_SERVICE: Currently supports google, bing, serpapi, serper, duckduckgo (recommended), required -- APIBASE: If you are using an OpenAI third-party proxy, you can fill it in here, note that v1 is not needed, not required -- NEWS_KEY: News search, if you need plz join in [telegram](https://sum4all.one/telegram)for the Key,free now +- SEARCH_SERVICE: temporarily supports search1api, google, bing, serpapi, serper, duckduckgo, required +- APIBASE: if you are using OpenAI three-way proxy, you can fill in here, note that you do not need to add v1, non-required! +- SEARCH1API_KEY: such as the selection of search1api required, I build their own search services, 0.99 U.S. dollars / 1000 times per month, the application address https://search2ai.online/docs - BING_KEY: Required if choosing bing search, please search for tutorials, application address https://search2ai.online/bing - GOOGLE_CX: Required if choosing Google search, Search engine ID, please search for tutorials, application address https://search2ai.online/googlecx - GOOGLE_KEY: Required if choosing Google search, API key, application address https://search2ai.online/googlekey @@ -125,8 +126,10 @@ One-click deployment 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 Gemini stream mode - Support for Azure OpenAI - Fix streaming output issues in Vercel project - Improve the speed of streaming output diff --git a/README.md b/README.md index 718b2fb..e07d7f4 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,12 @@ Buy Me A Coffee # 版本更新 +- V0.1.8,20240305,支持search1api搜索服务,更新Gemini版本搜索变量配置,开放新闻搜索能力,增加风险声明 - V0.1.7,20240224,Gemini版本支持流式输出,且兼容vision model - V0.1.6,20240221,支持Gemini模型,暂时可通过cloudflare worker的方式配置 - V0.1.5,20240205,支持新闻搜索,快速浏览新闻更方便 - V0.1.4,20240120,支持Zeabur一键部署,非常方便,强烈推荐! - V0.1.3,20240120,支持本地部署,可自行部署在自己的服务器上 -- V0.1.2,20240115,修复cloudflare worker版本非搜索场景下的流式输出问题 -- V0.1.1,20240114,支持vercel一键部署,目前只适合喜欢折腾的人 更多历史更新,请参见 [版本记录](https://github.com/fatwang2/search2ai/releases) @@ -65,9 +64,9 @@ demo站体验地址:[OpenAI](https://search2ai.online/demo),根据提示使 [![Deployed on Zeabur](https://zeabur.com/deployed-on-zeabur-dark.svg)](https://zeabur.com?referralCode=fatwang2&utm_source=fatwang2&utm_campaign=oss) 环境变量 -- SEARCH_SERVICE:暂时支持google、bing、serpapi、serper、duckduckgo(推荐),必填 -- APIBASE:如果你在用 OpenAI 三方代理,可在这里填入,注意不需要加v1,非必填 -- NEWS_KEY: 单独的新闻搜索服务,如需体验可加入 [telegram频道 ](https://sum4all.one/telegram)申请Key,暂时免费 +- SEARCH_SERVICE:暂时支持search1api、google、bing、serpapi、serper、duckduckgo,必填 +- APIBASE:如果你在用 OpenAI 三方代理,在这里填入,注意不需要加v1,非必填 +- SEARCH1API_KEY:如选search1api必填,我自己搭建的搜索服务,0.99美金/1000次每个月,申请地址 https://search2ai.online/docs - BING_KEY:如选bing搜索必填,请自行搜索教程,申请地址 https://search2ai.online/bing - GOOGLE_CX:如选Google搜索必填,Search engine ID,请自行搜索教程,申请地址 https://search2ai.online/googlecx - GOOGLE_KEY:如选Google搜索必填,API key,申请地址 https://search2ai.online/googlekey @@ -80,9 +79,9 @@ demo站体验地址:[OpenAI](https://search2ai.online/demo),根据提示使 git clone https://github.com/fatwang2/search2ai ``` 2. 复制.env.template为.env,配置环境变量 -- SEARCH_SERVICE:暂时支持google、bing、serpapi、serper、duckduckgo(推荐),必填 +- SEARCH_SERVICE:暂时支持search1api、google、bing、serpapi、serper、duckduckgo,必填 - APIBASE:如果你在用 OpenAI 三方代理,可在这里填入,注意不需要加v1,非必填 -- NEWS_KEY: 单独的新闻搜索服务,如需体验可加入 [telegram频道 ](https://sum4all.one/telegram)申请Key,暂时免费 +- SEARCH1API_KEY:如选search1api必填,我自己搭建的搜索服务,0.99美金/1000次每个月,申请地址 https://search2ai.online/docs - BING_KEY:如选bing搜索必填,请自行搜索教程,申请地址 https://search2ai.online/bing - GOOGLE_CX:如选Google搜索必填,Search engine ID,请自行搜索教程,申请地址 https://search2ai.online/googlecx - GOOGLE_KEY:如选Google搜索必填,API key,申请地址 https://search2ai.online/googlekey @@ -102,11 +101,11 @@ http://localhost:3014/v1/chat/completions **cloudflare worker部署** 1. 复制[openai.js](https://search2ai.online/cloudflare)或者[gemini.js](https://search2ai.online/geminicf)的代码,不需要任何修改!在cloudflare的worker里部署,上线后的worker的地址可作为你接口调用时的自定义域名地址,注意拼接,worker地址仅代表v1前的部分 -2. 在worker中配置变量(部署openai时需要配置,gemini暂不支持) +2. 在worker中配置变量 ![效果示例](pictures/worker.png) -- SEARCH_SERVICE:暂时支持google、bing、serpapi、serper、duckduckgo(推荐),必填 +- SEARCH_SERVICE:暂时支持search1api、google、bing、serpapi、serper、duckduckgo,必填 - APIBASE:如果你在用 OpenAI 三方代理,可在这里填入,注意不需要加v1,非必填 -- NEWS_KEY: 单独的新闻搜索服务,如需体验可加入 [telegram频道 ](https://sum4all.one/telegram)申请Key,暂时免费 +- SEARCH1API_KEY:如选search1api必填,我自己搭建的搜索服务,0.99美金/1000次每个月,申请地址 https://search2ai.online/docs - BING_KEY:如选bing搜索必填,请自行搜索教程,申请地址 https://search2ai.online/bing - GOOGLE_CX:如选Google搜索必填,Search engine ID,请自行搜索教程,申请地址 https://search2ai.online/googlecx - GOOGLE_KEY:如选Google搜索必填,API key,申请地址 https://search2ai.online/googlekey @@ -126,6 +125,9 @@ http://localhost:3014/v1/chat/completions 为保证更新,也可以先fork本项目后自己在vercel上部署 +# 风险声明 +为了确保本项目的持久运行,某些接口请求将通过[search1api](https://search.search2ai.one)进行转发。请放心,该转发服务不会保存任何隐私数据。 + # 后续迭代 - 支持Azure OpenAI - 修复Vercel项目流式输出问题 diff --git a/gemini.js b/gemini.js index aeceb90..d6e4ddc 100644 --- a/gemini.js +++ b/gemini.js @@ -13,10 +13,20 @@ addEventListener('fetch', event => { try { const url = "https://search.search2ai.one"; - const headers = {"Content-Type": "application/json"}; + const headers= { + "Content-Type": "application/json", + "Authorization": typeof SEARCH1API_KEY !== 'undefined' ? `Bearer ${SEARCH1API_KEY}` : '', + "google_cx": typeof GOOGLE_CX !== 'undefined' ? GOOGLE_CX : '', + "google_key": typeof GOOGLE_KEY !== 'undefined' ? GOOGLE_KEY : '', + "serpapi_key": typeof SERPAPI_KEY !== 'undefined' ? SERPAPI_KEY : '', + "serper_key": typeof SERPER_KEY !== 'undefined' ? SERPER_KEY : '', + "bing_key": typeof BING_KEY !== 'undefined' ? BING_KEY : '', + "apibase": typeof APIBASE !== 'undefined' ? APIBASE : 'https://api.openai.com' + }; const body = { "query": query, - "search_service": "duckduckgo" + search_service: SEARCH_SERVICE, + max_results: 5 }; const response = await fetch(url, { diff --git a/openai.js b/openai.js index 5454d79..019f44d 100644 --- a/openai.js +++ b/openai.js @@ -79,6 +79,7 @@ async function search(query) { method: 'POST', headers: { "Content-Type": "application/json", + "Authorization": typeof SEARCH1API_KEY !== 'undefined' ? `Bearer ${SEARCH1API_KEY}` : '', "google_cx": typeof GOOGLE_CX !== 'undefined' ? GOOGLE_CX : '', "google_key": typeof GOOGLE_KEY !== 'undefined' ? GOOGLE_KEY : '', "serpapi_key": typeof SERPAPI_KEY !== 'undefined' ? SERPAPI_KEY : '', @@ -88,7 +89,8 @@ async function search(query) { }, body: JSON.stringify({ query: query, - search_service: SEARCH_SERVICE + search_service: SEARCH_SERVICE, + max_results: 5 }) }); @@ -118,8 +120,7 @@ async function news(query) { const response = await fetch('https://ddg.search2ai.online/searchNews', { method: 'POST', headers: { - "Content-Type": "application/json", - "newskey": typeof NEWS_KEY !== 'undefined' ? NEWS_KEY : '' + "Content-Type": "application/json" }, body: JSON.stringify({ q: query, diff --git a/units/news.js b/units/news.js index 10b9424..aaa351d 100644 --- a/units/news.js +++ b/units/news.js @@ -6,11 +6,10 @@ config({ path: __dirname + '/../.env' }); async function news(query) { console.log(`正在使用查询进行新闻搜索: ${JSON.stringify(query)}`); try { - const response = await fetch('https://crawler.search2ai.one/searchNews', { + const response = await fetch('https://ddg.search2ai.online/searchNews', { method: 'POST', headers: { - "Content-Type": "application/json", - "newskey": process.env.NEWS_KEY || '' + "Content-Type": "application/json" }, body: JSON.stringify({ q: query, diff --git a/units/search.js b/units/search.js index 98abddc..d3bcc6f 100644 --- a/units/search.js +++ b/units/search.js @@ -9,6 +9,7 @@ async function search(query) { method: 'POST', headers: { "Content-Type": "application/json", + "Authorization": process.env.SEARCH1API_KEY ? `Bearer ${process.env.SEARCH1API_KEY}` : '', "google_cx": process.env.GOOGLE_CX || '', "google_key": process.env.GOOGLE_KEY || '', "serpapi_key": process.env.SERPAPI_KEY || '',