@ai-sdk/google
Version:
The **[Google Generative AI provider](https://ai-sdk.dev/providers/ai-sdk-providers/google-generative-ai)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the [Google Generative AI](https://ai.google/discover/generativeai/)
30 lines (28 loc) • 735 B
text/typescript
import type { LanguageModelV3FinishReason } from '@ai-sdk/provider';
export function mapGoogleGenerativeAIFinishReason({
finishReason,
hasToolCalls,
}: {
finishReason: string | null | undefined;
hasToolCalls: boolean;
}): LanguageModelV3FinishReason['unified'] {
switch (finishReason) {
case 'STOP':
return hasToolCalls ? 'tool-calls' : 'stop';
case 'MAX_TOKENS':
return 'length';
case 'IMAGE_SAFETY':
case 'RECITATION':
case 'SAFETY':
case 'BLOCKLIST':
case 'PROHIBITED_CONTENT':
case 'SPII':
return 'content-filter';
case 'MALFORMED_FUNCTION_CALL':
return 'error';
case 'FINISH_REASON_UNSPECIFIED':
case 'OTHER':
default:
return 'other';
}
}