mirror of
https://github.com/fosrl/pangolin.git
synced 2026-08-15 08:49:59 +02:00
Handle the list of models without allow/block
This commit is contained in:
@@ -26,7 +26,7 @@ export type BlueprintAiProviderInput = {
|
|||||||
provider: string;
|
provider: string;
|
||||||
accessMode: AccessMode;
|
accessMode: AccessMode;
|
||||||
enabled: boolean;
|
enabled: boolean;
|
||||||
models: BlueprintAiModelInput[];
|
models: string[];
|
||||||
};
|
};
|
||||||
|
|
||||||
async function resolveProviderNiceIds(
|
async function resolveProviderNiceIds(
|
||||||
@@ -99,12 +99,12 @@ async function resolveModelKeys(
|
|||||||
for (const provider of providers) {
|
for (const provider of providers) {
|
||||||
const providerId = providerIdByNiceId.get(provider.provider)!;
|
const providerId = providerIdByNiceId.get(provider.provider)!;
|
||||||
for (const m of provider.models) {
|
for (const m of provider.models) {
|
||||||
const modelId = byProviderAndKey.get(`${providerId}::${m.model}`);
|
const modelId = byProviderAndKey.get(`${providerId}::${m}`);
|
||||||
if (modelId === undefined) {
|
if (modelId === undefined) {
|
||||||
missing.push(`${provider.provider}/${m.model}`);
|
missing.push(`${provider.provider}/${m}`);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
modelIdByEntryKey.set(`${provider.provider}::${m.model}`, modelId);
|
modelIdByEntryKey.set(`${provider.provider}::${m}`, modelId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -117,7 +117,7 @@ async function resolveModelKeys(
|
|||||||
|
|
||||||
async function validateModelEntries(input: {
|
async function validateModelEntries(input: {
|
||||||
orgId: string;
|
orgId: string;
|
||||||
entries: { modelId: number; listType: ModelListType }[];
|
entries: { modelId: number }[];
|
||||||
selectProviderIds: number[];
|
selectProviderIds: number[];
|
||||||
trx: Transaction;
|
trx: Transaction;
|
||||||
}): Promise<void> {
|
}): Promise<void> {
|
||||||
@@ -157,13 +157,10 @@ async function validateModelEntries(input: {
|
|||||||
`Model ${entry.modelId} does not exist or does not belong to a select-mode attached provider`
|
`Model ${entry.modelId} does not exist or does not belong to a select-mode attached provider`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
if (catalog.listType !== entry.listType) {
|
|
||||||
throw new Error(
|
|
||||||
`Model ${entry.modelId} must use list-type "${catalog.listType}" to match the provider catalog entry`
|
|
||||||
);
|
|
||||||
}
|
|
||||||
if (!catalog.enabled) {
|
if (!catalog.enabled) {
|
||||||
throw new Error(`Model ${entry.modelId} is disabled on its provider`);
|
throw new Error(
|
||||||
|
`Model ${entry.modelId} is disabled on its provider`
|
||||||
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -238,8 +235,7 @@ export async function syncInferenceAiConfig(
|
|||||||
|
|
||||||
const modelEntries = input.providers.flatMap((p) =>
|
const modelEntries = input.providers.flatMap((p) =>
|
||||||
p.models.map((m) => ({
|
p.models.map((m) => ({
|
||||||
modelId: modelIdByEntryKey.get(`${p.provider}::${m.model}`)!,
|
modelId: modelIdByEntryKey.get(`${p.provider}::${m}`)!
|
||||||
listType: m.listType
|
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
|
|
||||||
@@ -262,8 +258,7 @@ export async function syncInferenceAiConfig(
|
|||||||
await trx.insert(resourceAiModels).values(
|
await trx.insert(resourceAiModels).values(
|
||||||
modelEntries.map((m) => ({
|
modelEntries.map((m) => ({
|
||||||
resourceId: input.resourceId,
|
resourceId: input.resourceId,
|
||||||
modelId: m.modelId,
|
modelId: m.modelId
|
||||||
listType: m.listType
|
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@@ -277,8 +272,7 @@ export async function syncInferenceAiConfig(
|
|||||||
await trx.insert(siteResourceAiModels).values(
|
await trx.insert(siteResourceAiModels).values(
|
||||||
modelEntries.map((m) => ({
|
modelEntries.map((m) => ({
|
||||||
siteResourceId: input.siteResourceId,
|
siteResourceId: input.siteResourceId,
|
||||||
modelId: m.modelId,
|
modelId: m.modelId
|
||||||
listType: m.listType
|
|
||||||
}))
|
}))
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -363,10 +363,7 @@ export async function updatePrivateResources(
|
|||||||
provider: p.provider,
|
provider: p.provider,
|
||||||
accessMode: p["access-mode"],
|
accessMode: p["access-mode"],
|
||||||
enabled: p.enabled,
|
enabled: p.enabled,
|
||||||
models: p.models.map((m) => ({
|
models: p.models
|
||||||
model: m.model,
|
|
||||||
listType: m["list-type"]
|
|
||||||
}))
|
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -672,10 +669,7 @@ export async function updatePrivateResources(
|
|||||||
provider: p.provider,
|
provider: p.provider,
|
||||||
accessMode: p["access-mode"],
|
accessMode: p["access-mode"],
|
||||||
enabled: p.enabled,
|
enabled: p.enabled,
|
||||||
models: p.models.map((m) => ({
|
models: p.models
|
||||||
model: m.model,
|
|
||||||
listType: m["list-type"]
|
|
||||||
}))
|
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -708,10 +708,7 @@ export async function updatePublicResources(
|
|||||||
provider: p.provider,
|
provider: p.provider,
|
||||||
accessMode: p["access-mode"],
|
accessMode: p["access-mode"],
|
||||||
enabled: p.enabled,
|
enabled: p.enabled,
|
||||||
models: p.models.map((m) => ({
|
models: p.models
|
||||||
model: m.model,
|
|
||||||
listType: m["list-type"]
|
|
||||||
}))
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
});
|
});
|
||||||
@@ -1288,10 +1285,7 @@ export async function updatePublicResources(
|
|||||||
provider: p.provider,
|
provider: p.provider,
|
||||||
accessMode: p["access-mode"],
|
accessMode: p["access-mode"],
|
||||||
enabled: p.enabled,
|
enabled: p.enabled,
|
||||||
models: p.models.map((m) => ({
|
models: p.models
|
||||||
model: m.model,
|
|
||||||
listType: m["list-type"]
|
|
||||||
}))
|
|
||||||
}))
|
}))
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -188,11 +188,6 @@ export const HeaderSchema = z.object({
|
|||||||
value: z.string().min(1)
|
value: z.string().min(1)
|
||||||
});
|
});
|
||||||
|
|
||||||
export const AiProviderModelEntrySchema = z.object({
|
|
||||||
model: z.string().min(1),
|
|
||||||
"list-type": z.enum(["allow", "block"])
|
|
||||||
});
|
|
||||||
|
|
||||||
export const AiProviderAttachmentSchema = z
|
export const AiProviderAttachmentSchema = z
|
||||||
.object({
|
.object({
|
||||||
provider: z.string().min(1),
|
provider: z.string().min(1),
|
||||||
@@ -201,7 +196,7 @@ export const AiProviderAttachmentSchema = z
|
|||||||
.optional()
|
.optional()
|
||||||
.default("inherit"),
|
.default("inherit"),
|
||||||
enabled: z.boolean().optional().default(true),
|
enabled: z.boolean().optional().default(true),
|
||||||
models: z.array(AiProviderModelEntrySchema).optional().default([])
|
models: z.array(z.string()).optional().default([])
|
||||||
})
|
})
|
||||||
.refine(
|
.refine(
|
||||||
(provider) => {
|
(provider) => {
|
||||||
@@ -598,7 +593,10 @@ export const PrivateResourceSchema = z
|
|||||||
machines: z.array(z.string()).optional().default([]),
|
machines: z.array(z.string()).optional().default([]),
|
||||||
labels: z.array(z.string().min(1)).optional().default([]),
|
labels: z.array(z.string().min(1)).optional().default([]),
|
||||||
"auth-daemon": AuthDaemonSchema.optional(),
|
"auth-daemon": AuthDaemonSchema.optional(),
|
||||||
"ai-providers": z.array(AiProviderAttachmentSchema).optional().default([]),
|
"ai-providers": z
|
||||||
|
.array(AiProviderAttachmentSchema)
|
||||||
|
.optional()
|
||||||
|
.default([]),
|
||||||
"ai-budget": AiBudgetListSchemaWithDefault
|
"ai-budget": AiBudgetListSchemaWithDefault
|
||||||
})
|
})
|
||||||
.refine(
|
.refine(
|
||||||
@@ -608,7 +606,11 @@ export const PrivateResourceSchema = z
|
|||||||
data.mode === "ssh" &&
|
data.mode === "ssh" &&
|
||||||
(data["auth-daemon"] === undefined ||
|
(data["auth-daemon"] === undefined ||
|
||||||
data["auth-daemon"].mode === "native");
|
data["auth-daemon"].mode === "native");
|
||||||
if (data.mode !== "inference" && !isNativeSSH && !data.destination) {
|
if (
|
||||||
|
data.mode !== "inference" &&
|
||||||
|
!isNativeSSH &&
|
||||||
|
!data.destination
|
||||||
|
) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user