File size: 5,081 Bytes
676fc08 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 |
import { completePath } from "@/utils/url";
// AI provider API base url
const GOOGLE_GENERATIVE_AI_API_BASE_URL =
process.env.GOOGLE_GENERATIVE_AI_API_BASE_URL ||
"https://generativelanguage.googleapis.com";
const OPENROUTER_API_BASE_URL =
process.env.OPENROUTER_API_BASE_URL || "https://openrouter.ai/api";
const OPENAI_API_BASE_URL =
process.env.OPENAI_API_BASE_URL || "https://api.openai.com";
const ANTHROPIC_API_BASE_URL =
process.env.ANTHROPIC_API_BASE_URL || "https://api.anthropic.com";
const DEEPSEEK_API_BASE_URL =
process.env.DEEPSEEK_API_BASE_URL || "https://api.deepseek.com";
const XAI_API_BASE_URL = process.env.XAI_API_BASE_URL || "https://api.x.ai";
const MISTRAL_API_BASE_URL =
process.env.MISTRAL_API_BASE_URL || "https://api.mistral.ai";
const AZURE_API_BASE_URL = `https://${process.env.AZURE_RESOURCE_NAME}.openai.azure.com/openai/deployments`;
const OPENAI_COMPATIBLE_API_BASE_URL =
process.env.OPENAI_COMPATIBLE_API_BASE_URL || "";
const POLLINATIONS_API_BASE_URL =
process.env.POLLINATIONS_API_BASE_URL ||
"https://text.pollinations.ai/openai";
const OLLAMA_API_BASE_URL =
process.env.OLLAMA_API_BASE_URL || "http://0.0.0.0:11434";
// Search provider API base url
const TAVILY_API_BASE_URL =
process.env.TAVILY_API_BASE_URL || "https://api.tavily.com";
const FIRECRAWL_API_BASE_URL =
process.env.FIRECRAWL_API_BASE_URL || "https://api.firecrawl.dev";
const EXA_API_BASE_URL = process.env.EXA_API_BASE_URL || "https://api.exa.ai";
const BOCHA_API_BASE_URL =
process.env.BOCHA_API_BASE_URL || "https://api.bochaai.com";
const SEARXNG_API_BASE_URL =
process.env.SEARXNG_API_BASE_URL || "http://0.0.0.0:8080";
const GOOGLE_GENERATIVE_AI_API_KEY =
process.env.GOOGLE_GENERATIVE_AI_API_KEY || "";
const OPENROUTER_API_KEY = process.env.OPENROUTER_API_KEY || "";
const OPENAI_API_KEY = process.env.OPENAI_API_KEY || "";
const ANTHROPIC_API_KEY = process.env.ANTHROPIC_API_KEY || "";
const DEEPSEEK_API_KEY = process.env.DEEPSEEK_API_KEY || "";
const XAI_API_KEY = process.env.XAI_API_KEY || "";
const MISTRAL_API_KEY = process.env.MISTRAL_API_KEY || "";
const AZURE_API_KEY = process.env.AZURE_API_KEY || "";
const OPENAI_COMPATIBLE_API_KEY = process.env.OPENAI_COMPATIBLE_API_KEY || "";
// Search provider API key
const TAVILY_API_KEY = process.env.TAVILY_API_KEY || "";
const FIRECRAWL_API_KEY = process.env.FIRECRAWL_API_KEY || "";
const EXA_API_KEY = process.env.EXA_API_KEY || "";
const BOCHA_API_KEY = process.env.BOCHA_API_KEY || "";
export function getAIProviderBaseURL(provider: string) {
switch (provider) {
case "google":
return completePath(GOOGLE_GENERATIVE_AI_API_BASE_URL, "/v1beta");
case "openai":
return completePath(OPENAI_API_BASE_URL, "/v1");
case "anthropic":
return completePath(ANTHROPIC_API_BASE_URL, "/v1");
case "deepseek":
return completePath(DEEPSEEK_API_BASE_URL, "/v1");
case "xai":
return completePath(XAI_API_BASE_URL, "/v1");
case "mistral":
return completePath(MISTRAL_API_BASE_URL, "/v1");
case "azure":
return AZURE_API_BASE_URL;
case "openrouter":
return completePath(OPENROUTER_API_BASE_URL, "/api/v1");
case "openaicompatible":
return completePath(OPENAI_COMPATIBLE_API_BASE_URL, "/v1");
case "pollinations":
return completePath(POLLINATIONS_API_BASE_URL, "/v1");
case "ollama":
return completePath(OLLAMA_API_BASE_URL, "/api");
default:
throw new Error("Unsupported Provider: " + provider);
}
}
export function getAIProviderApiKey(provider: string) {
switch (provider) {
case "google":
return GOOGLE_GENERATIVE_AI_API_KEY;
case "openai":
return OPENAI_API_KEY;
case "anthropic":
return ANTHROPIC_API_KEY;
case "deepseek":
return DEEPSEEK_API_KEY;
case "xai":
return XAI_API_KEY;
case "mistral":
return MISTRAL_API_KEY;
case "azure":
return AZURE_API_KEY;
case "openrouter":
return OPENROUTER_API_KEY;
case "openaicompatible":
return OPENAI_COMPATIBLE_API_KEY;
case "pollinations":
case "ollama":
return "";
default:
throw new Error("Unsupported Provider: " + provider);
}
}
export function getSearchProviderBaseURL(provider: string) {
switch (provider) {
case "tavily":
return TAVILY_API_BASE_URL;
case "firecrawl":
return FIRECRAWL_API_BASE_URL;
case "exa":
return EXA_API_BASE_URL;
case "bocha":
return BOCHA_API_BASE_URL;
case "searxng":
return SEARXNG_API_BASE_URL;
case "model":
return "";
default:
throw new Error("Unsupported Provider: " + provider);
}
}
export function getSearchProviderApiKey(provider: string) {
switch (provider) {
case "tavily":
return TAVILY_API_KEY;
case "firecrawl":
return FIRECRAWL_API_KEY;
case "exa":
return EXA_API_KEY;
case "bocha":
return BOCHA_API_KEY;
case "searxng":
case "model":
return "";
default:
throw new Error("Unsupported Provider: " + provider);
}
}
|