gemini -exp whitelist
This commit is contained in:
@@ -29,6 +29,15 @@ type Config = {
|
|||||||
* same but the APIs are different. Vertex is the GCP product for enterprise.
|
* same but the APIs are different. Vertex is the GCP product for enterprise.
|
||||||
**/
|
**/
|
||||||
googleAIKey?: string;
|
googleAIKey?: string;
|
||||||
|
/**
|
||||||
|
* Comma-delimited list of Google AI experimental model names that are
|
||||||
|
* allowed to bypass the experimental model block. By default, all models
|
||||||
|
* containing "exp" are blocked, but specific models listed here will be
|
||||||
|
* permitted.
|
||||||
|
*
|
||||||
|
* @example "gemini-2.0-flash-exp,gemini-exp-1206"
|
||||||
|
*/
|
||||||
|
allowedExpModels?: string;
|
||||||
/**
|
/**
|
||||||
* Comma-delimited list of Mistral AI API keys.
|
* Comma-delimited list of Mistral AI API keys.
|
||||||
*/
|
*/
|
||||||
@@ -450,6 +459,7 @@ export const config: Config = {
|
|||||||
anthropicKey: getEnvWithDefault("ANTHROPIC_KEY", ""),
|
anthropicKey: getEnvWithDefault("ANTHROPIC_KEY", ""),
|
||||||
qwenKey: getEnvWithDefault("QWEN_KEY", ""),
|
qwenKey: getEnvWithDefault("QWEN_KEY", ""),
|
||||||
googleAIKey: getEnvWithDefault("GOOGLE_AI_KEY", ""),
|
googleAIKey: getEnvWithDefault("GOOGLE_AI_KEY", ""),
|
||||||
|
allowedExpModels: getEnvWithDefault("ALLOWED_EXP_MODELS", ""),
|
||||||
mistralAIKey: getEnvWithDefault("MISTRAL_AI_KEY", ""),
|
mistralAIKey: getEnvWithDefault("MISTRAL_AI_KEY", ""),
|
||||||
deepseekKey: getEnvWithDefault("DEEPSEEK_KEY", ""),
|
deepseekKey: getEnvWithDefault("DEEPSEEK_KEY", ""),
|
||||||
xaiKey: getEnvWithDefault("XAI_KEY", ""),
|
xaiKey: getEnvWithDefault("XAI_KEY", ""),
|
||||||
|
|||||||
@@ -235,12 +235,29 @@ function maybeReassignModel(req: Request) {
|
|||||||
* This function is intended to be used as a RequestPreprocessor.
|
* This function is intended to be used as a RequestPreprocessor.
|
||||||
* It throws an error if an experimental model is detected, which should be
|
* It throws an error if an experimental model is detected, which should be
|
||||||
* caught by the proxy's onError handler.
|
* caught by the proxy's onError handler.
|
||||||
|
*
|
||||||
|
* Models can be allowed through the ALLOWED_EXP_MODELS environment variable.
|
||||||
*/
|
*/
|
||||||
function checkAndBlockExperimentalModels(req: Request) { // Changed signature
|
function checkAndBlockExperimentalModels(req: Request) { // Changed signature
|
||||||
const modelId = req.body.model as string | undefined;
|
const modelId = req.body.model as string | undefined;
|
||||||
|
|
||||||
// Check if the model ID contains "exp" (case-insensitive)
|
// Check if the model ID contains "exp" (case-insensitive)
|
||||||
if (modelId && modelId.toLowerCase().includes("exp")) {
|
if (modelId && modelId.toLowerCase().includes("exp")) {
|
||||||
|
// Check if this specific model is in the allowlist
|
||||||
|
const allowedModels = config.allowedExpModels
|
||||||
|
?.split(",")
|
||||||
|
.map(model => model.trim())
|
||||||
|
.filter(model => model.length > 0) || [];
|
||||||
|
|
||||||
|
const isAllowed = allowedModels.some(allowedModel =>
|
||||||
|
modelId.toLowerCase() === allowedModel.toLowerCase()
|
||||||
|
);
|
||||||
|
|
||||||
|
if (isAllowed) {
|
||||||
|
req.log.info({ modelId }, "Allowing experimental Google AI model via allowlist.");
|
||||||
|
return; // Allow the request to proceed
|
||||||
|
}
|
||||||
|
|
||||||
req.log.warn({ modelId }, "Blocking request to experimental Google AI model.");
|
req.log.warn({ modelId }, "Blocking request to experimental Google AI model.");
|
||||||
const err: any = new Error("Experimental models are too unstable to be supported in proxy code. Please use preview models instead.");
|
const err: any = new Error("Experimental models are too unstable to be supported in proxy code. Please use preview models instead.");
|
||||||
err.statusCode = 400;
|
err.statusCode = 400;
|
||||||
|
|||||||
Reference in New Issue
Block a user