fix(ai): store provider model metadata as jsonb objects
This commit is contained in:
parent
7a837c2180
commit
e2f8a253a7
@ -66,6 +66,10 @@ function stableHash(value: unknown) {
|
|||||||
return createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
return createHash("sha256").update(JSON.stringify(value)).digest("hex");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function toJsonValue(value: unknown): postgres.JSONValue {
|
||||||
|
return JSON.parse(JSON.stringify(value)) as postgres.JSONValue;
|
||||||
|
}
|
||||||
|
|
||||||
function sortById<T extends { id: string }>(rows: T[]) {
|
function sortById<T extends { id: string }>(rows: T[]) {
|
||||||
return [...rows].sort((left, right) => left.id.localeCompare(right.id));
|
return [...rows].sort((left, right) => left.id.localeCompare(right.id));
|
||||||
}
|
}
|
||||||
@ -290,20 +294,19 @@ async function main() {
|
|||||||
where "providerId" = ${targetProviderId}::uuid and "modelId" = ${preset.modelId}
|
where "providerId" = ${targetProviderId}::uuid and "modelId" = ${preset.modelId}
|
||||||
order by "createdAt" limit 1
|
order by "createdAt" limit 1
|
||||||
`;
|
`;
|
||||||
const values = {
|
const capabilitiesJson = tx.json(toJsonValue(preset.capabilities));
|
||||||
description: preset.description,
|
const defaultParamsJson = tx.json(toJsonValue(preset.defaultParams));
|
||||||
capabilities: JSON.stringify(preset.capabilities),
|
const imageGenConfigJson = preset.imageGenConfig
|
||||||
defaultParams: JSON.stringify(preset.defaultParams),
|
? tx.json(toJsonValue(preset.imageGenConfig))
|
||||||
imageGenConfig: preset.imageGenConfig ? JSON.stringify(preset.imageGenConfig) : null,
|
: null;
|
||||||
};
|
|
||||||
if (existing[0]) {
|
if (existing[0]) {
|
||||||
await tx`
|
await tx`
|
||||||
update "AiModel" set
|
update "AiModel" set
|
||||||
"displayName" = ${preset.displayName}, description = ${values.description},
|
"displayName" = ${preset.displayName}, description = ${preset.description},
|
||||||
"supportsVision" = ${preset.supportsVision}, "supportsImageGen" = ${preset.supportsImageGen},
|
"supportsVision" = ${preset.supportsVision}, "supportsImageGen" = ${preset.supportsImageGen},
|
||||||
"isEnabled" = true, "isHidden" = ${preset.isHidden}, "sortOrder" = ${preset.sortOrder},
|
"isEnabled" = true, "isHidden" = ${preset.isHidden}, "sortOrder" = ${preset.sortOrder},
|
||||||
capabilities = ${values.capabilities}::jsonb, "defaultParams" = ${values.defaultParams}::jsonb,
|
capabilities = ${capabilitiesJson}, "defaultParams" = ${defaultParamsJson},
|
||||||
"imageGenConfig" = ${values.imageGenConfig}::jsonb, "updatedAt" = now()
|
"imageGenConfig" = ${imageGenConfigJson}, "updatedAt" = now()
|
||||||
where id = ${existing[0].id}::uuid
|
where id = ${existing[0].id}::uuid
|
||||||
`;
|
`;
|
||||||
modelDbIds.set(preset.modelId, existing[0].id);
|
modelDbIds.set(preset.modelId, existing[0].id);
|
||||||
@ -314,10 +317,10 @@ async function main() {
|
|||||||
"supportsImageGen", "isEnabled", "isHidden", "sortOrder", capabilities,
|
"supportsImageGen", "isEnabled", "isHidden", "sortOrder", capabilities,
|
||||||
"defaultParams", "imageGenConfig", "isDefault", "isDefaultTextEditModel"
|
"defaultParams", "imageGenConfig", "isDefault", "isDefaultTextEditModel"
|
||||||
) values (
|
) values (
|
||||||
${targetProviderId}::uuid, ${preset.modelId}, ${preset.displayName}, ${values.description},
|
${targetProviderId}::uuid, ${preset.modelId}, ${preset.displayName}, ${preset.description},
|
||||||
${preset.supportsVision}, ${preset.supportsImageGen}, true, ${preset.isHidden},
|
${preset.supportsVision}, ${preset.supportsImageGen}, true, ${preset.isHidden},
|
||||||
${preset.sortOrder}, ${values.capabilities}::jsonb, ${values.defaultParams}::jsonb,
|
${preset.sortOrder}, ${capabilitiesJson}, ${defaultParamsJson},
|
||||||
${values.imageGenConfig}::jsonb, false, false
|
${imageGenConfigJson}, false, false
|
||||||
) returning id
|
) returning id
|
||||||
`;
|
`;
|
||||||
if (!created) throw new Error(`Failed to create VIP98K model ${preset.modelId}`);
|
if (!created) throw new Error(`Failed to create VIP98K model ${preset.modelId}`);
|
||||||
@ -441,7 +444,14 @@ async function main() {
|
|||||||
);
|
);
|
||||||
const invalidVipModels = remainingModels.filter((model) => {
|
const invalidVipModels = remainingModels.filter((model) => {
|
||||||
if (!vipProviderIds.has(model.providerId)) return false;
|
if (!vipProviderIds.has(model.providerId)) return false;
|
||||||
const capabilities = model.capabilities as Record<string, unknown> | null;
|
if (
|
||||||
|
!model.capabilities ||
|
||||||
|
typeof model.capabilities !== "object" ||
|
||||||
|
Array.isArray(model.capabilities)
|
||||||
|
) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
const capabilities = model.capabilities as Record<string, unknown>;
|
||||||
const kind = String(capabilities?.kind || "").trim().toLowerCase();
|
const kind = String(capabilities?.kind || "").trim().toLowerCase();
|
||||||
if (["video", "model-3d", "world", "chat"].includes(kind)) {
|
if (["video", "model-3d", "world", "chat"].includes(kind)) {
|
||||||
return model.supportsImageGen;
|
return model.supportsImageGen;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user