Spaces:
Paused
Paused
Download src/lib/server/api/utils/resolveModel.ts from Mike0021/chat-ui-agent-demo: direct link, hf CLI and curl.
- Browser
- Download file 713 Bytes
-
https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/server/api/utils/resolveModel.ts
- Command line
-
hf download hf://spaces/Mike0021/chat-ui-agent-demo/src/lib/server/api/utils/resolveModel.ts
-
curl -L -o resolveModel.ts https://huggingface.co/spaces/Mike0021/chat-ui-agent-demo/resolve/main/src/lib/server/api/utils/resolveModel.ts
713 Bytes
| import { error } from "@sveltejs/kit"; | |
| /** | |
| * Resolve a model by namespace and optional model name. | |
| * Looks up in the models registry and returns the model, or throws 404 if not found or unlisted. | |
| */ | |
| export async function resolveModel(namespace: string, model?: string) { | |
| let modelId = namespace; | |
| if (model) { | |
| modelId += "/" + model; | |
| } | |
| try { | |
| const { models } = await import("$lib/server/models"); | |
| const found = models.find((m) => m.id === modelId); | |
| if (!found || found.unlisted) { | |
| error(404, "Model not found"); | |
| } | |
| return found; | |
| } catch (e) { | |
| // Re-throw SvelteKit HttpErrors | |
| if (e && typeof e === "object" && "status" in e) { | |
| throw e; | |
| } | |
| error(500, "Models not available"); | |
| } | |
| } | |