Sign inSign up

spectrpro/gemini-vpn

By spectrpro

•Updated about 1 year ago

https://github.com/spectre-pro/gemini-vpn

Image
0

2.3K

spectrpro/gemini-vpn repository overview

⁠Gemini VPN Proxy

This project provides a simple Node.js proxy server for the Google Generative Language API (Gemini API). It allows you to route your API requests through a local proxy, which can be useful for various purposes such as debugging, logging, or bypassing certain network restrictions.

⁠Features

  • API Proxy: Forwards requests to https://generativelanguage.googleapis.com.
  • HTTP Method Support: Handles all standard HTTP methods (GET, POST, PUT, DELETE, etc.).
  • Body Parsing: Supports JSON, URL-encoded, plain text, and raw binary request bodies.
  • Header Forwarding: Copies most original request headers to the target API, with necessary adjustments for proxying (e.g., Host header).
  • Streamed Responses: Efficiently streams responses from the target API back to the client.
  • Docker Support: Easily deployable using Docker.

⁠Getting Started

You can pull the pre-built Docker image from Docker Hub:

docker pull spectrpro/gemini-vpn

After pulling, you can run the proxy server:

docker run -d -p 34562:34562 --name gemini-vpn spectrpro/gemini-vpn

The proxy will be accessible at http://localhost:34562.

⁠Building and Running with Docker

If you prefer to build the Docker image yourself:

  1. Clone the repository:
    git clone https://github.com/spectre-pro/gemini-vpn.git
    cd gemini-vpn
    
  2. Build the Docker image:
    docker build -t spectrpro/gemini-vpn .
    
  3. Run the Docker container:
    docker run -d -p 34562:34562 --name gemini-vpn spectrpro/gemini-vpn
    
⁠Running Locally (Node.js)
  1. Clone the repository:
    git clone https://github.com/spectre-pro/gemini-vpn.git
    cd gemini-vpn
    
  2. Install dependencies:
    npm install
    
  3. Start the server:
    node src/main.js
    
    The server will run on http://localhost:34562 by default.

⁠Configuration

The proxy server can be configured using environment variables:

  • PORT: The port on which the proxy server will listen. Defaults to 34562.
    • Example: PORT=8080 node src/main.js
  • TARGET_API_URL: The base URL of the target API. Defaults to https://generativelanguage.googleapis.com.
    • Example: TARGET_API_URL=https://api.example.com node src/main.js

⁠Usage Example

Once the proxy is running, you can direct your Gemini API requests to http://localhost:34562 instead of https://generativelanguage.googleapis.com.

For example, if you would normally make a request like this:

POST https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent
Content-Type: application/json
{
  "contents": [
    {
      "parts": [
        {"text": "Hello, Gemini!"}
      ]
    }
  ]
}

You would now make it to your proxy:

POST http://localhost:34562/v1beta/models/gemini-pro:generateContent
Content-Type: application/json
{
  "contents": [
    {
      "parts": [
        {"text": "Hello, Gemini!"}
      ]
    }
  ]
}

The proxy will forward this request to https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent and return the response.

⁠License

This project is licensed under the LICENSE⁠ file.

⁠Gemini VPN 代理伺服器

此專案提供一個簡單的 Node.js 代理伺服器,用於 Google Generative Language API (Gemini API)。它允許您透過本地代理路由您的 API 請求,這對於偵錯、日誌記錄或繞過某些網路限制等各種目的都非常有用。

⁠功能

  • API 代理: 將請求轉發到 https://generativelanguage.googleapis.com。
  • HTTP 方法支援: 處理所有標準 HTTP 方法 (GET, POST, PUT, DELETE 等)。
  • 請求體解析: 支援 JSON、URL 編碼、純文字和原始二進位請求體。
  • 標頭轉發: 將大多數原始請求標頭複製到目標 API,並進行必要的代理調整 (例如,Host 標頭)。
  • 串流回應: 有效率地將目標 API 的回應串流回客戶端。
  • Docker 支援: 易於使用 Docker 部署。

⁠快速開始

⁠使用 Docker (推薦)

您可以從 Docker Hub 拉取預建的 Docker 映像:

docker pull spectrpro/gemini-vpn

拉取後,您可以運行代理伺服器:

docker run -d -p 34562:34562 --name gemini-vpn spectrpro/gemini-vpn

代理伺服器將在 http://localhost:34562 上可訪問。

⁠使用 Docker 建置和運行

如果您更喜歡自己建置 Docker 映像:

  1. 克隆儲存庫:
    git clone https://github.com/spectre-pro/gemini-vpn.git
    cd gemini-vpn
    
  2. 建置 Docker 映像:
    docker build -t spectrpro/gemini-vpn .
    
  3. 運行 Docker 容器:
    docker run -d -p 34562:34562 --name gemini-vpn spectrpro/gemini-vpn
    
⁠本地運行 (Node.js)
  1. 克隆儲存庫:
    git clone https://github.com/spectre-pro/gemini-vpn.git
    cd gemini-vpn
    
  2. 安裝依賴項:
    npm install
    
  3. 啟動伺服器:
    node src/main.js
    
    伺服器將預設在 http://localhost:34562 上運行。

⁠配置

代理伺服器可以使用環境變數進行配置:

  • PORT: 代理伺服器將監聽的埠號。預設為 34562。
    • 範例:PORT=8080 node src/main.js
  • TARGET_API_URL: 目標 API 的基本 URL。預設為 https://generativelanguage.googleapis.com。
    • 範例:TARGET_API_URL=https://api.example.com node src/main.js

⁠使用範例

代理伺服器運行後,您可以將 Gemini API 請求導向 http://localhost:34562,而不是 https://generativelanguage.googleapis.com。

例如,如果您通常會發出這樣的請求:

POST https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent
Content-Type: application/json
{
  "contents": [
    {
      "parts": [
        {"text": "Hello, Gemini!"}
      ]
    }
  ]
}

您現在將其發送到您的代理:

POST http://localhost:34562/v1beta/models/gemini-pro:generateContent
Content-Type: application/json
{
  "contents": [
    {
      "parts": [
        {"text": "Hello, Gemini!"}
      ]
    }
  ]
}

代理伺服器會將此請求轉發到 https://generativelanguage.googleapis.com/v1beta/models/gemini-pro:generateContent 並返回回應。

⁠許可證

此專案根據 LICENSE⁠ 文件獲得許可。

Tag summary

Content type

Image

Digest

sha256:6424a9e14…

Size

58.6 MB

Last updated

about 1 year ago

docker pull spectrpro/gemini-vpn