Spaces:
Paused
Paused
File size: 1,841 Bytes
fae625a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 | import type { ProcessedModel } from "$lib/server/models";
import type { GETModelResponse, GETModelsResponse } from "$lib/server/api/types";
// API responses must never serialize a model object directly: the raw
// ProcessedModel carries server-only configuration (an `endpoints` array that
// can hold per-model API keys for self-hosted deployments, prompt render
// functions, etc.). Every field that leaves the server is listed explicitly.
export function serializeModelSummary(model: ProcessedModel): GETModelsResponse[number] {
return {
id: model.id,
name: model.name,
websiteUrl: model.websiteUrl,
modelUrl: model.modelUrl,
datasetName: model.datasetName,
datasetUrl: model.datasetUrl,
displayName: model.displayName,
description: model.description,
logoUrl: model.logoUrl,
promptExamples: model.promptExamples,
preprompt: model.preprompt,
multimodal: model.multimodal,
multimodalAcceptedMimetypes: model.multimodalAcceptedMimetypes,
supportsTools: (model as unknown as { supportsTools?: boolean }).supportsTools ?? false,
supportsReasoning:
(model as unknown as { supportsReasoning?: boolean }).supportsReasoning ?? false,
supportsArtifacts:
(model as unknown as { supportsArtifacts?: boolean }).supportsArtifacts ?? false,
unlisted: model.unlisted,
hasInferenceAPI: model.hasInferenceAPI,
isRouter: model.isRouter,
};
}
// Detail shape for GET /models/[namespace]([/model]): the summary plus the
// heavyweight fields (providers is ~60KB across all models) that only the
// per-model settings page needs, fetched on demand.
export function serializeModelDetail(model: ProcessedModel): GETModelResponse {
return {
...serializeModelSummary(model),
providers: model.providers as unknown as Array<{ provider: string } & Record<string, unknown>>,
parameters: model.parameters,
};
}
|