Spaces:
Runtime error
Runtime error
Download src/lib/server/modelEndpoint.ts from BetterAPI/BetterChat: direct link, hf CLI and curl.
- Browser
- Download file 639 Bytes
-
https://huggingface.co/spaces/BetterAPI/BetterChat/resolve/0592f207c0819df96caa4eb96d1dd79bee3392ad/src/lib/server/modelEndpoint.ts
- Command line
-
hf download hf://spaces/BetterAPI/BetterChat@0592f207c0819df96caa4eb96d1dd79bee3392ad/src/lib/server/modelEndpoint.ts
-
curl -L -o modelEndpoint.ts https://huggingface.co/spaces/BetterAPI/BetterChat/resolve/0592f207c0819df96caa4eb96d1dd79bee3392ad/src/lib/server/modelEndpoint.ts
639 Bytes
| import { MODEL_ENDPOINTS } from "$env/static/private"; | |
| import { sum } from "$lib/utils/sum"; | |
| const endpoints: Array<{ endpoint: string; authorization: string; weight: number }> = | |
| JSON.parse(MODEL_ENDPOINTS); | |
| const totalWeight = sum(endpoints.map((e) => e.weight)); | |
| /** | |
| * Find a random load-balanced endpoint | |
| */ | |
| export function modelEndpoint(): { endpoint: string; authorization: string; weight: number } { | |
| let random = Math.random() * totalWeight; | |
| for (const endpoint of endpoints) { | |
| if (random < endpoint.weight) { | |
| return endpoint; | |
| } | |
| random -= endpoint.weight; | |
| } | |
| throw new Error("Invalid config, no endpoint found"); | |
| } | |