MCPcopy Create free account
hub / github.com/TanStack/ai / generateModelConstant

Function generateModelConstant

scripts/sync-provider-models.ts:343–408  ·  view source on GitHub ↗
(
  model: OpenRouterModel,
  prefix: string,
  config: ProviderConfig,
)

Source from the content-addressed store, hash-verified

341// ---------------------------------------------------------------------------
342
343function generateModelConstant(
344 model: OpenRouterModel,
345 prefix: string,
346 config: ProviderConfig,
347): string {
348 const constName = toConstName(prefix, model.id)
349 const strippedId = stripPrefix(prefix, model.id)
350
351 const inputNormal = convertPrice(model.pricing.prompt)
352 const inputCached = convertPrice(model.pricing.input_cache_read)
353 const outputNormal = convertPrice(model.pricing.completion)
354
355 // Use actual input modalities from OpenRouter data, filtered to what this provider supports
356 const inputModalities = mapInputModalities(
357 model.architecture.input_modalities,
358 ).filter((m) => config.validInputModalities.includes(m))
359 const inputModalitiesStr = inputModalities.map((m) => `'${m}'`).join(', ')
360
361 const lines: Array<string> = []
362 lines.push(`const ${constName} = {`)
363
364 // name field
365 lines.push(` name: '${strippedId}',`)
366
367 // id field (Anthropic has both name and id, set to same value for new models)
368 if (config.hasBothNameAndId) {
369 lines.push(` id: '${strippedId}',`)
370 }
371
372 // context / max_input_tokens
373 if (model.context_length > 0) {
374 lines.push(
375 ` ${config.contextField}: ${formatNumber(model.context_length)},`,
376 )
377 }
378
379 // max_output_tokens
380 if (model.top_provider.max_completion_tokens) {
381 lines.push(
382 ` max_output_tokens: ${formatNumber(model.top_provider.max_completion_tokens)},`,
383 )
384 }
385
386 // supports block (actual input modalities + reference capabilities)
387 lines.push(` supports: {`)
388 lines.push(` input: [${inputModalitiesStr}],`)
389 lines.push(config.referenceSupportsBody)
390 lines.push(` },`)
391
392 // pricing
393 lines.push(` pricing: {`)
394 lines.push(` input: {`)
395 lines.push(` normal: ${inputNormal},`)
396 if (inputCached > 0) {
397 lines.push(` cached: ${inputCached},`)
398 }
399 lines.push(` },`)
400 lines.push(` output: {`)

Callers 1

mainFunction · 0.85

Calls 6

toConstNameFunction · 0.85
stripPrefixFunction · 0.85
convertPriceFunction · 0.85
mapInputModalitiesFunction · 0.85
formatNumberFunction · 0.85
pushMethod · 0.45

Tested by

no test coverage detected