diff --git a/src/config.ts b/src/config.ts index 9d168b0..9fa76a2 100644 --- a/src/config.ts +++ b/src/config.ts @@ -119,6 +119,11 @@ type Config = { * Desination URL to redirect blocked requests to, for non-JSON requests. */ blockRedirect?: string; + /** + * Whether the proxy should disallow requests for GPT-4 models in order to + * prevent excessive spend. Applies only to OpenAI. + */ + turboOnly?: boolean; }; // To change configs, create a file called .env in the root directory. @@ -162,6 +167,7 @@ export const config: Config = { "You must be over the age of majority in your country to use this service." ), blockRedirect: getEnvWithDefault("BLOCK_REDIRECT", "https://www.9gag.com"), + turboOnly: getEnvWithDefault("TURBO_ONLY", false), } as const; function migrateConfigs() { diff --git a/src/info-page.ts b/src/info-page.ts index ab5e00a..f7f44b8 100644 --- a/src/info-page.ts +++ b/src/info-page.ts @@ -89,7 +89,7 @@ type ServiceInfo = { function getOpenAIInfo() { const info: { [model: string]: Partial } = {}; const keys = keyPool.list().filter((k) => k.service === "openai"); - const hasGpt4 = keys.some((k) => k.isGpt4); + const hasGpt4 = keys.some((k) => k.isGpt4) && !config.turboOnly; if (keyPool.anyUnchecked()) { const uncheckedKeys = keys.filter((k) => !k.lastChecked); @@ -197,7 +197,7 @@ Logs are anonymous and do not contain IP addresses or timestamps. [You can see t const turboWait = getQueueInformation("turbo").estimatedQueueTime; const gpt4Wait = getQueueInformation("gpt-4").estimatedQueueTime; waits.push(`**Turbo:** ${turboWait}`); - if (keyPool.list().some((k) => k.isGpt4)) { + if (keyPool.list().some((k) => k.isGpt4) && !config.turboOnly) { waits.push(`**GPT-4:** ${gpt4Wait}`); } } diff --git a/src/key-management/openai/provider.ts b/src/key-management/openai/provider.ts index 49c225a..53657eb 100644 --- a/src/key-management/openai/provider.ts +++ b/src/key-management/openai/provider.ts @@ -128,11 +128,17 @@ export class OpenAIKeyProvider implements KeyProvider { ); if (availableKeys.length === 0) { let message = needGpt4 - ? "No GPT-4 keys available. Try selecting a non-GPT-4 model." + ? "No GPT-4 keys available. Try selecting a Turbo model." : "No active OpenAI keys available."; throw new Error(message); } + if (needGpt4 && config.turboOnly) { + throw new Error( + "Proxy operator has disabled GPT-4 to reduce quota usage. Try selecting a Turbo model." + ); + } + // Select a key, from highest priority to lowest priority: // 1. Keys which are not rate limited // a. We ignore rate limits from over a minute ago