Skip to content

Commit

Permalink
Merge pull request #19 from utopeadia/main
Browse files Browse the repository at this point in the history
增加searXNG支持
  • Loading branch information
fatwang2 authored Apr 25, 2024
2 parents f61a8d0 + 8922983 commit 57b84eb
Show file tree
Hide file tree
Showing 8 changed files with 696 additions and 521 deletions.
Binary file removed .DS_Store
Binary file not shown.
81 changes: 45 additions & 36 deletions README-EN.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
[简体中文](README.md) · **English**
[简体中文](README.md) · **English**

## User Communication

[Telegram Channel](https://sum4all.one/telegram)

## Buy me a coffee

<a href="https://www.buymeacoffee.com/fatwang2" target="_blank"><img src="https://cdn.buymeacoffee.com/buttons/v2/default-yellow.png" alt="Buy Me A Coffee" style="height: 60px !important;width: 217px !important;" ></a>

# Version Updates

- V0.2.5, 20240425, open source the code for the search api
- V0.2.4, 20240424, support for Groq in Cloudflare Worker
- V0.2.3, 20240423, support for Azure OpenAI in Cloudflare Worker. It also introduces the ability to use an authorization code and customize the user's request key.
Expand All @@ -17,6 +20,7 @@
For more historical updates, please see [Version History](https://github.com/fatwang2/search2ai/releases)

# S2A

Help your LLM API support networking, search, news, web page summarization, has supported OpenAI, Gemini, Moonshot, the big model will be based on your input to determine whether the network, not every time the network search, do not need to install any plug-ins, do not need to replace the key, directly in your commonly used OpenAI/Gemini three-way client replacement of custom You can directly replace the customized address in your usual OpenAI/Gemini three-way client, and also support self-deployment, which will not affect the use of other functions, such as drawing, voice, etc.

<table>
Expand All @@ -31,15 +35,17 @@ Help your LLM API support networking, search, news, web page summarization, has
</table>

# Features
| Model | Features | Stream | Deployments |
| -------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `OpenAI` | search, news, crawler | stream, unstream| Zeabur, Local deployment, Cloudflare Worker, Vercel|
| `Azure OpenAI` | search, news, crawler | stream, unstream| Cloudflare Worker|
| `Groq` | search, news, crawler | stream, unstream| Cloudflare Worker|
| `Gemini` | search | stream, unstream| Cloudflare Worker|
| `Moonshot` | search, news, crawler | unstream| Zeabur, Local deployment, Cloudflare Worker, Vercel|

| Model | Features | Stream | Deployments |
| ---------------- | --------------------- | ---------------- | --------------------------------------------------- |
| `OpenAI` | search, news, crawler | stream, unstream | Zeabur, Local deployment, Cloudflare Worker, Vercel |
| `Azure OpenAI` | search, news, crawler | stream, unstream | Cloudflare Worker |
| `Groq` | search, news, crawler | stream, unstream | Cloudflare Worker |
| `Gemini` | search | stream, unstream | Cloudflare Worker |
| `Moonshot` | search, news, crawler | unstream | Zeabur, Local deployment, Cloudflare Worker, Vercel |

# Usage

**Replace the custom domain in any client with the following address**

<table>
Expand All @@ -49,6 +55,7 @@ Help your LLM API support networking, search, news, web page summarization, has
</table>

# Deployment

**Zeabur**

Click the button for one-click deployment, switched on your own environment variables
Expand All @@ -60,30 +67,33 @@ 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)

**Local Deployment**

1. Clone the repository locally

```
git clone https://github.com/fatwang2/search2ai
```
2. Copy .env.template as .env, configure environment variables

2. Copy .env.template as .env, configure environment variables
3. Enter the api directory, run the program, and display the log in real-time

```
cd api && nohup node index.js > output.log 2>&1 & tail -f output.log
```

4. Port 3014, the complete address after concatenation is as follows, can be configured according to the client's requirements for the apibase address (if https is required, need to use nginx for reverse proxy, many tutorials online)

```
http://localhost:3014/v1/chat/completions
```

**Cloudflare worker**
1. Copy the code of [search2openai.js](search2openai.js), or [search2gemini.js](search2gemini.js), or [search2groq.js](search2groq.js), no modifications needed! Deploy in cloudflare's worker, after going online, the worker's address can be used as your interface call's custom domain address, note the concatenation, worker address only represents the part before v1

1. Copy the code of [search2openai.js](search2openai.js), or [search2gemini.js](search2gemini.js), or [search2groq.js](search2groq.js), no modifications needed! Deploy in cloudflare's worker, after going online, the worker's address can be used as your interface call's custom domain address, note the concatenation, worker address only represents the part before v1
2. Configure variables in the worker(only openai)
![Effect Example](pictures/worker.png)

![Effect Example](pictures/worker.png)
3. Configure triggers - custom domain in the worker, direct access to the worker's address in China might have issues, need to replace with custom domain
![Alt text](pictures/域名.png)
![Alt text](pictures/域名.png)

**Vercel**

Expand All @@ -96,33 +106,32 @@ One-click deployment
To ensure updates, you can also first fork this project and then deploy it on Vercel yourself

# Environment Variables

This project provides some additional configuration options, which can be set through environment variables:

| Environment Variable | Required | Description | Example |
| -------------------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------- |
| `SEARCH_SERVICE` | Yes | Your search service. The key of the service you choose needs to be configured. Supports search1api, google, bing, serpapi, serper, duckduckgo. | `search1api, google, bing, serpapi, serper, duckduckgo` |
| `APIBASE` | No | Third-party proxy address. | `https://api.openai.com, https://api.moonshot.cn, https://api.groq.com/openai` |
| `MAX_RESULTS` | No | Number of search results. | `10` |
| `CRAWL_RESULTS` | No | The number of deep searches (retrieve the main text of the webpage after searching). Currently only supports search1api, deep search will be slow. | `1` |
| `SEARCH1API_KEY` | Conditional | Required if search1api is selected. My own fast and cheap search service. Apply at https://search21api.com. | `xxx` |
| `BING_KEY` | Conditional | Required if Bing search is selected. Please search for the tutorial yourself. Apply at https://search2ai.online/bing. | `xxx` |
| `GOOGLE_CX` | Conditional | Required if Google search is selected. Search engine ID. Please search for the tutorial yourself. Apply at https://search2ai.online/googlecx. | `xxx` |
| `GOOGLE_KEY` | Conditional | Required if Google search is selected. API key. Apply at https://search2ai.online/googlekey. | `xxx` |
| `SERPAPI_KEY` | Conditional | Required if serpapi is selected. Free 100 times/month. Register at https://search2ai.online/serpapi. | `xxx` |
| `SERPER_KEY` | Conditional | Required if serper is selected. Free 2500 times for 6 months. Register at https://search2ai.online/serper. | `xxx` |
| `OPENAI_TYPE` | No | OpenAI provider source, default is openai | `openai, azure` |
| `RESOURCE_NAME` | Conditional | Required if azure is selected | `xxxx` |
| `DEPLOY_NAME` | Conditional | Required if azure is selected | `gpt-35-turbo` |
| `API_VERSION` | Conditional | Required if azure is selected | `2024-02-15-preview` |
| `AZURE_API_KEY` | Conditional | Required if azure is selected | `xxxx` |
| `AUTH_KEYS` | No | If you want users to define a separate authorization code as a key when making requests, you need to fill this in. Required if azure is selected | `000,1111,2222` |
| `OPENAI_API_KEY` | No | If you want users to define a separate authorization code as a key when requesting openai, you need to fill this in | `sk-xxx` |
| Environment Variable | Required | Description | Example |
| -------------------- | ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- |
| `SEARCH_SERVICE` | Yes | Your search service. The key of the service you choose needs to be configured. Supports search1api, google, bing, serpapi, serper, duckduckgo. | `search1api, google, bing, serpapi, serper, duckduckgo` |
| `APIBASE` | No | Third-party proxy address. | `https://api.openai.com, https://api.moonshot.cn, https://api.groq.com/openai` |
| `MAX_RESULTS` | No | Number of search results. | `10` |
| `CRAWL_RESULTS` | No | The number of deep searches (retrieve the main text of the webpage after searching). Currently only supports search1api, deep search will be slow. | `1` |
| `SEARCH1API_KEY` | Conditional | Required if search1api is selected. My own fast and cheap search service. Apply at https://search21api.com. | `xxx` |
| `BING_KEY` | Conditional | Required if Bing search is selected. Please search for the tutorial yourself. Apply at https://search2ai.online/bing. | `xxx` |
| `GOOGLE_CX` | Conditional | Required if Google search is selected. Search engine ID. Please search for the tutorial yourself. Apply at https://search2ai.online/googlecx. | `xxx` |
| `GOOGLE_KEY` | Conditional | Required if Google search is selected. API key. Apply at https://search2ai.online/googlekey. | `xxx` |
| `SERPAPI_KEY` | Conditional | Required if serpapi is selected. Free 100 times/month. Register at https://search2ai.online/serpapi. | `xxx` |
| `SERPER_KEY` | Conditional | Required if serper is selected. Free 2500 times for 6 months. Register at https://search2ai.online/serper. | `xxx` |
| `SEARXNG_BASE_URL` | Conditional | Required if searXNG is selected. Fill in the domain name of the self-built searXNG service, e.g. https://search.xxx.xxx. (Must contain https/http without a / at the end.) | `xxx` |
| `OPENAI_TYPE` | No | OpenAI provider source, default is openai | `openai, azure` |
| `RESOURCE_NAME` | Conditional | Required if azure is selected | `xxxx` |
| `DEPLOY_NAME` | Conditional | Required if azure is selected | `gpt-35-turbo` |
| `API_VERSION` | Conditional | Required if azure is selected | `2024-02-15-preview` |
| `AZURE_API_KEY` | Conditional | Required if azure is selected | `xxxx` |
| `AUTH_KEYS` | No | If you want users to define a separate authorization code as a key when making requests, you need to fill this in. Required if azure is selected | `000,1111,2222` |
| `OPENAI_API_KEY` | No | If you want users to define a separate authorization code as a key when requesting openai, you need to fill this in | `sk-xxx` |

# Future Iterations
- Support SearXNG

- Fix streaming output issues in Vercel project
- Improve the speed of streaming output
- Support more vertical searches



Loading

0 comments on commit 57b84eb

Please sign in to comment.