diff --git a/README-EN.md b/README-EN.md index e017e09..33b542c 100644 --- a/README-EN.md +++ b/README-EN.md @@ -129,6 +129,23 @@ This project consists of three core files, each with its own specific function: ``` #### 💻 Call the API (Default API Key: `123456`) +> **Hint**: If you are in an environment where you cannot directly access Google services, please set up a global HTTP/HTTPS proxy for your terminal first. +> +> - **Windows (CMD):** +> ```cmd +> set http_proxy=http://127.0.0.1:7890 +> set https_proxy=http://127.0.0.1:7890 +> ``` +> - **Windows (PowerShell):** +> ```powershell +> $env:http_proxy="http://127.0.0.1:7890" +> $env:https_proxy="http://127.0.0.1:7890" +> ``` +> - **macOS/Linux (Bash/Zsh):** +> ```bash +> export http_proxy=http://127.0.0.1:7890 +> export https_proxy=http://127.0.0.1:7890 +> ``` * **List Models** ```bash curl "http://localhost:3000/v1beta/models?key=123456" @@ -161,6 +178,7 @@ This project consists of three core files, each with its own specific function: ``` #### 💻 Call the API (as an OpenAI client) + * **List Models** ```bash curl http://localhost:8000/v1/models \ diff --git a/README.md b/README.md index 301e47a..b5f60f5 100644 --- a/README.md +++ b/README.md @@ -123,12 +123,29 @@ ```bash node gemini-api-server.js --oauth-creds-file "/path/to/your/oauth_creds.json" ``` -* **通过指定项目ID启动** (例如,用于多项目环境) +* **通过指定项目ID启动** (例如,用于多项目环境或必须指定项目ID的用户) ```bash node gemini-api-server.js --project-id your-gcp-project-id ``` #### 💻 调用 API (默认 API Key: `123456`) +> **提示**: 如果您在无法直接访问 Google 服务的环境中使用,请先为您的终端设置全局 HTTP/HTTPS 代理。 +> +> - **Windows (CMD):** +> ```cmd +> set http_proxy=http://127.0.0.1:7890 +> set https_proxy=http://127.0.0.1:7890 +> ``` +> - **Windows (PowerShell):** +> ```powershell +> $env:http_proxy="http://127.0.0.1:7890" +> $env:https_proxy="http://127.0.0.1:7890" +> ``` +> - **macOS/Linux (Bash/Zsh):** +> ```bash +> export http_proxy=http://127.0.0.1:7890 +> export https_proxy=http://127.0.0.1:7890 +> ``` * **列出模型** ```bash curl "http://localhost:3000/v1beta/models?key=123456" @@ -161,6 +178,7 @@ ``` #### 💻 调用 API (以 OpenAI 客户端方式) + * **列出模型** ```bash curl http://localhost:8000/v1/models \ diff --git a/gemini-core.js b/gemini-core.js index 2a82ba7..bddc159 100644 --- a/gemini-core.js +++ b/gemini-core.js @@ -294,11 +294,14 @@ export class GeminiApiService { async callApi(method, body, isRetry = false) { try { - const res = await this.authClient.request({ + const requestOptions = { url: `${CODE_ASSIST_ENDPOINT}/${CODE_ASSIST_API_VERSION}:${method}`, - method: "POST", headers: { "Content-Type": "application/json" }, - responseType: "json", body: JSON.stringify(body), - }); + method: "POST", + headers: { "Content-Type": "application/json" }, + responseType: "json", + body: JSON.stringify(body), + }; + const res = await this.authClient.request(requestOptions); return res.data; } catch (error) { if (error.response?.status === 401 && !isRetry) { @@ -312,11 +315,15 @@ export class GeminiApiService { async * streamApi(method, body, isRetry = false) { try { - const res = await this.authClient.request({ + const requestOptions = { url: `${CODE_ASSIST_ENDPOINT}/${CODE_ASSIST_API_VERSION}:${method}`, - method: "POST", params: { alt: "sse" }, headers: { "Content-Type": "application/json" }, - responseType: "stream", body: JSON.stringify(body), - }); + method: "POST", + params: { alt: "sse" }, + headers: { "Content-Type": "application/json" }, + responseType: "stream", + body: JSON.stringify(body), + }; + const res = await this.authClient.request(requestOptions); if (res.status !== 200) { let errorBody = ''; for await (const chunk of res.data) errorBody += chunk.toString();