adds unique openaiOrgs to infopage
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user