adds unique openaiOrgs to infopage

This commit is contained in:
nai-degen
2023-08-30 12:42:28 -05:00
parent 8d557c844e
commit 85aeeb2c05
2 changed files with 10 additions and 2 deletions
+8
View File
@@ -46,6 +46,7 @@ function cacheInfoPageHtml(baseUrl: string) {
...(config.modelRateLimit ? { proomptersNow: getUniqueIps() } : {}),
openaiKeys,
anthropicKeys,
...(openaiKeys ? { openaiOrgs: getUniqueOpenAIOrgs(keys) } : {}),
...(openaiKeys ? getOpenAIInfo() : {}),
...(anthropicKeys ? getAnthropicInfo() : {}),
config: listConfig(),
@@ -76,6 +77,13 @@ function cacheInfoPageHtml(baseUrl: string) {
return pageBody;
}
function getUniqueOpenAIOrgs(keys: ReturnType<typeof keyPool.list>) {
const orgIds = new Set(
keys.filter((k) => k.service === "openai").map((k: any) => k.organizationId)
);
return orgIds.size;
}
type ServiceInfo = {
activeKeys: number;
trialKeys?: number;
+2 -2
View File
@@ -217,6 +217,8 @@ export class OpenAIKeyChecker {
opts
);
const organizations = data.data;
const defaultOrg = organizations.find(({ is_default }) => is_default);
this.updateKey(key.hash, { organizationId: defaultOrg?.id });
if (organizations.length <= 1) return undefined;
this.log.info(
@@ -224,11 +226,9 @@ export class OpenAIKeyChecker {
"Key is associated with multiple organizations; cloning key for each organization."
);
const defaultOrg = organizations.find(({ is_default }) => is_default);
const ids = organizations
.filter(({ is_default }) => !is_default)
.map(({ id }) => id);
this.updateKey(key.hash, { organizationId: defaultOrg?.id });
this.cloneKey(key.hash, ids);
}