fix(ai): store provider model metadata as jsonb objects
This commit is contained in:
parent
5decd202a1
commit
e1e7e0ccd4
@ -66,6 +66,10 @@ function stableHash(value: unknown) {
|
||||
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[]) {
|
||||
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}
|
||||
order by "createdAt" limit 1
|
||||
`;
|
||||
const values = {
|
||||
description: preset.description,
|
||||
capabilities: JSON.stringify(preset.capabilities),
|
||||
defaultParams: JSON.stringify(preset.defaultParams),
|
||||
imageGenConfig: preset.imageGenConfig ? JSON.stringify(preset.imageGenConfig) : null,
|
||||
};
|
||||
const capabilitiesJson = tx.json(toJsonValue(preset.capabilities));
|
||||
const defaultParamsJson = tx.json(toJsonValue(preset.defaultParams));
|
||||
const imageGenConfigJson = preset.imageGenConfig
|
||||
? tx.json(toJsonValue(preset.imageGenConfig))
|
||||
: null;
|
||||
if (existing[0]) {
|
||||
await tx`
|
||||
update "AiModel" set
|
||||
"displayName" = ${preset.displayName}, description = ${values.description},
|
||||
"displayName" = ${preset.displayName}, description = ${preset.description},
|
||||
"supportsVision" = ${preset.supportsVision}, "supportsImageGen" = ${preset.supportsImageGen},
|
||||
"isEnabled" = true, "isHidden" = ${preset.isHidden}, "sortOrder" = ${preset.sortOrder},
|
||||
capabilities = ${values.capabilities}::jsonb, "defaultParams" = ${values.defaultParams}::jsonb,
|
||||
"imageGenConfig" = ${values.imageGenConfig}::jsonb, "updatedAt" = now()
|
||||
capabilities = ${capabilitiesJson}, "defaultParams" = ${defaultParamsJson},
|
||||
"imageGenConfig" = ${imageGenConfigJson}, "updatedAt" = now()
|
||||
where id = ${existing[0].id}::uuid
|
||||
`;
|
||||
modelDbIds.set(preset.modelId, existing[0].id);
|
||||
@ -314,10 +317,10 @@ async function main() {
|
||||
"supportsImageGen", "isEnabled", "isHidden", "sortOrder", capabilities,
|
||||
"defaultParams", "imageGenConfig", "isDefault", "isDefaultTextEditModel"
|
||||
) 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.sortOrder}, ${values.capabilities}::jsonb, ${values.defaultParams}::jsonb,
|
||||
${values.imageGenConfig}::jsonb, false, false
|
||||
${preset.sortOrder}, ${capabilitiesJson}, ${defaultParamsJson},
|
||||
${imageGenConfigJson}, false, false
|
||||
) returning id
|
||||
`;
|
||||
if (!created) throw new Error(`Failed to create VIP98K model ${preset.modelId}`);
|
||||
@ -441,7 +444,14 @@ async function main() {
|
||||
);
|
||||
const invalidVipModels = remainingModels.filter((model) => {
|
||||
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();
|
||||
if (["video", "model-3d", "world", "chat"].includes(kind)) {
|
||||
return model.supportsImageGen;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user