mirror of
https://github.com/ChatGPTNextWeb/ChatGPT-Next-Web.git
synced 2025-11-13 12:43:42 +08:00
feat: support google multiple keys
This commit is contained in:
@@ -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}`;
|
||||
|
||||
@@ -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,
|
||||
|
||||
@@ -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),
|
||||
|
||||
@@ -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";
|
||||
|
||||
|
||||
Reference in New Issue
Block a user