ai
Version:
AI SDK by Vercel - build apps like ChatGPT, Claude, Gemini, and more with a single interface for any model using the Vercel AI Gateway or go direct to OpenAI, Anthropic, Google, or any other model provider.
58 lines (53 loc) • 1.32 kB
text/typescript
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,
};
}