adds feature to prevent GPT-4 model selection (default off)

This commit is contained in:
nai-degen 2023-07-06 16:09:30 -05:00
parent 561c063d90
commit 71882b18ae
3 changed files with 15 additions and 3 deletions

View File

@ -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() {

View File

@ -89,7 +89,7 @@ type ServiceInfo = {
function getOpenAIInfo() {
const info: { [model: string]: Partial<ServiceInfo> } = {};
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}`);
}
}

View File

@ -128,11 +128,17 @@ export class OpenAIKeyProvider implements KeyProvider<OpenAIKey> {
);
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