diff --git a/.env.template b/.env.template index acfc08bc4..e9166ce30 100644 --- a/.env.template +++ b/.env.template @@ -15,7 +15,7 @@ GOOGLE_API_KEY= # (optional) # Default: https://generativelanguage.googleapis.com/ # Googel Gemini Pro API url without pathname, set if you want to customize Google Gemini Pro API url. -GOOGLE_BASE_URL= +GEMINI_BASE_URL= # Override openai api request base url. (optional) # Default: https://api.openai.com diff --git a/README.md b/README.md index 0364803ec..e810e65c8 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ - [GoogleCustomSearch](https://api.js.langchain.com/classes/langchain_tools.GoogleCustomSearch.html) - 环境变量: - - `GOOGLE_API_KEY` + - ~~`GOOGLE_API_KEY`~~ `GOOGLE_SEARCH_API_KEY` - `GOOGLE_CSE_ID` - 申请参考:[说明](https://stackoverflow.com/questions/37083058/programmatically-searching-google-in-python-using-custom-search) @@ -238,7 +238,7 @@ OpenAI 接口代理 URL,如果你手动配置了 openai 接口代理,请填 Google Gemini Pro Api Key. -### `GOOGLE_BASE_URL` (可选) +### ~~ `GOOGLE_BASE_URL` (可选)~~ `GEMINI_BASE_URL` (可选) Google Gemini Pro Api Url. diff --git a/README_CN.md b/README_CN.md index c02db0e3c..973d8e768 100644 --- a/README_CN.md +++ b/README_CN.md @@ -110,7 +110,7 @@ Azure Api 版本,你可以在这里找到:[Azure 文档](https://learn.micro Google Gemini Pro 密钥. -### `GOOGLE_BASE_URL` (optional) +### ~~`GOOGLE_BASE_URL` (optional)~~ `GEMINI_BASE_URL` (optional) Google Gemini Pro Api Url. diff --git a/app/api/google/[...path]/route.ts b/app/api/google/[...path]/route.ts index 54aca26fa..da968b056 100644 --- a/app/api/google/[...path]/route.ts +++ b/app/api/google/[...path]/route.ts @@ -1,7 +1,7 @@ import { NextRequest, NextResponse } from "next/server"; import { auth } from "../../auth"; import { getServerSideConfig } from "@/app/config/server"; -import { GOOGLE_BASE_URL, ModelProvider } from "@/app/constant"; +import { GEMINI_BASE_URL, ModelProvider } from "@/app/constant"; async function handle( req: NextRequest, @@ -17,7 +17,7 @@ async function handle( const serverConfig = getServerSideConfig(); - let baseUrl = serverConfig.googleUrl || GOOGLE_BASE_URL; + let baseUrl = serverConfig.googleUrl || GEMINI_BASE_URL; if (!baseUrl.startsWith("http")) { baseUrl = `https://${baseUrl}`; diff --git a/app/api/langchain/tool/agent/agentapi.ts b/app/api/langchain/tool/agent/agentapi.ts index 7edf7201d..89884ae70 100644 --- a/app/api/langchain/tool/agent/agentapi.ts +++ b/app/api/langchain/tool/agent/agentapi.ts @@ -38,6 +38,7 @@ import { AIMessage, } from "@langchain/core/messages"; import { MultimodalContent } from "@/app/client/api"; +import { GoogleCustomSearch } from "@/app/api/langchain-tools/langchian-tool-index"; export interface RequestMessage { role: string; @@ -284,8 +285,11 @@ export class AgentApi { func: async (input: string) => serpAPITool.call(input), }); } - if (process.env.GOOGLE_CSE_ID && process.env.GOOGLE_API_KEY) { - let googleCustomSearchTool = new langchainTools["GoogleCustomSearch"](); + if (process.env.GOOGLE_CSE_ID && process.env.GOOGLE_SEARCH_API_KEY) { + let googleCustomSearchTool = new GoogleCustomSearch({ + apiKey: process.env.GOOGLE_SEARCH_API_KEY, + googleCSEId: process.env.GOOGLE_CSE_ID, + }); searchTool = new DynamicTool({ name: "google_custom_search", description: googleCustomSearchTool.description, diff --git a/app/config/server.ts b/app/config/server.ts index 6ae0fcdef..43745913f 100644 --- a/app/config/server.ts +++ b/app/config/server.ts @@ -117,7 +117,7 @@ export const getServerSideConfig = () => { isGoogle, googleApiKey: getApiKey(process.env.GOOGLE_API_KEY), - googleUrl: process.env.GEMINI_BASE_URL ?? process.env.GOOGLE_URL, + googleUrl: process.env.GOOGLE_URL, isAnthropic, anthropicApiKey: getApiKey(process.env.ANTHROPIC_API_KEY), diff --git a/app/constant.ts b/app/constant.ts index 827def8c5..6cf8d36dd 100644 --- a/app/constant.ts +++ b/app/constant.ts @@ -10,7 +10,6 @@ export const RUNTIME_CONFIG_DOM = "danger-runtime-config"; export const DEFAULT_API_HOST = "https://api.nextchat.dev"; export const OPENAI_BASE_URL = "https://api.openai.com"; -export const GOOGLE_BASE_URL = "https://generativelanguage.googleapis.com"; export const GEMINI_BASE_URL = "https://generativelanguage.googleapis.com/"; export const ANTHROPIC_BASE_URL = "https://api.anthropic.com";