import { InvalidArgumentError } from '../error/invalid-argument-error'; import type { LanguageModelCallOptions } from './language-model-call-options'; /** * Validates model call options and returns a new object with normalized values. */ export function prepareLanguageModelCallOptions({ maxOutputTokens, temperature, topP, topK, presencePenalty, frequencyPenalty, seed, stopSequences, reasoning, }: LanguageModelCallOptions): LanguageModelCallOptions { if (maxOutputTokens != null) { if (!Number.isInteger(maxOutputTokens)) { throw new InvalidArgumentError({ parameter: 'maxOutputTokens', value: maxOutputTokens, message: 'maxOutputTokens must be an integer', }); } if (maxOutputTokens < 1) { throw new InvalidArgumentError({ parameter: 'maxOutputTokens', value: maxOutputTokens, message: 'maxOutputTokens must be >= 1', }); } } if (seed != null) { if (!Number.isInteger(seed)) { throw new InvalidArgumentError({ parameter: 'seed', value: seed, message: 'seed must be an integer', }); } } return { maxOutputTokens, temperature, topP, topK, presencePenalty, frequencyPenalty, stopSequences, seed, reasoning, }; }