|
| 1 | +import type { ListModelsResult, ModelMetadata } from "./list-common"; |
| 2 | +import { DEFAULT_RESULT } from "./list-common"; |
| 3 | + |
| 4 | +export const CLOUDFLARE_WORKERS_AI_MODELS = [ |
| 5 | + "@cf/moonshotai/kimi-k2.6", |
| 6 | + "@cf/zai-org/glm-4.7-flash", |
| 7 | + "@cf/openai/gpt-oss-120b", |
| 8 | + "@cf/meta/llama-4-scout-17b-16e-instruct", |
| 9 | + "@cf/google/gemma-4-26b-a4b-it", |
| 10 | + "@cf/nvidia/nemotron-3-120b-a12b", |
| 11 | + "@cf/openai/gpt-oss-20b", |
| 12 | + "@cf/qwen/qwen3-30b-a3b-fp8", |
| 13 | + "@cf/mistralai/mistral-small-3.1-24b-instruct", |
| 14 | + "@cf/meta/llama-3.3-70b-instruct-fp8-fast", |
| 15 | +] as const; |
| 16 | + |
| 17 | +const VISION_MODELS = new Set<string>([ |
| 18 | + "@cf/moonshotai/kimi-k2.6", |
| 19 | + "@cf/meta/llama-4-scout-17b-16e-instruct", |
| 20 | + "@cf/google/gemma-4-26b-a4b-it", |
| 21 | +]); |
| 22 | + |
| 23 | +function isCloudflareWorkersAIModel( |
| 24 | + model: string, |
| 25 | +): model is (typeof CLOUDFLARE_WORKERS_AI_MODELS)[number] { |
| 26 | + return (CLOUDFLARE_WORKERS_AI_MODELS as readonly string[]).includes(model); |
| 27 | +} |
| 28 | + |
| 29 | +export function getCloudflareWorkersAIModelMetadata( |
| 30 | + model: string | undefined, |
| 31 | +): ModelMetadata | undefined { |
| 32 | + if (!model || !isCloudflareWorkersAIModel(model)) { |
| 33 | + return undefined; |
| 34 | + } |
| 35 | + |
| 36 | + return { |
| 37 | + input_modalities: VISION_MODELS.has(model) ? ["text", "image"] : ["text"], |
| 38 | + }; |
| 39 | +} |
| 40 | + |
| 41 | +export function createStaticCloudflareWorkersAIModelResult(): ListModelsResult { |
| 42 | + const metadata: Record<string, ModelMetadata> = {}; |
| 43 | + |
| 44 | + for (const model of CLOUDFLARE_WORKERS_AI_MODELS) { |
| 45 | + metadata[model] = getCloudflareWorkersAIModelMetadata(model)!; |
| 46 | + } |
| 47 | + |
| 48 | + return { |
| 49 | + models: [...CLOUDFLARE_WORKERS_AI_MODELS], |
| 50 | + ignored: [], |
| 51 | + metadata, |
| 52 | + }; |
| 53 | +} |
| 54 | + |
| 55 | +export async function listCloudflareWorkersAIModels( |
| 56 | + baseUrl: string, |
| 57 | + _apiKey: string, |
| 58 | +): Promise<ListModelsResult> { |
| 59 | + if (!baseUrl) { |
| 60 | + return DEFAULT_RESULT; |
| 61 | + } |
| 62 | + |
| 63 | + return createStaticCloudflareWorkersAIModelResult(); |
| 64 | +} |
0 commit comments