@ai-sdk/openai
Version:
The **[OpenAI provider](https://ai-sdk.dev/providers/ai-sdk-providers/openai)** for the [AI SDK](https://ai-sdk.dev/docs) contains language model support for the OpenAI chat and completion APIs and embedding model support for the OpenAI embeddings API.
23 lines (21 loc) • 663 B
text/typescript
import type { LanguageModelV4FinishReason } from '@ai-sdk/provider';
export function mapOpenAIResponseFinishReason({
finishReason,
hasFunctionCall,
}: {
finishReason: string | null | undefined;
// flag that checks if there have been client-side tool calls (not executed by openai)
hasFunctionCall: boolean;
}): LanguageModelV4FinishReason['unified'] {
switch (finishReason) {
case undefined:
case null:
return hasFunctionCall ? 'tool-calls' : 'stop';
case 'max_output_tokens':
return 'length';
case 'content_filter':
return 'content-filter';
default:
return hasFunctionCall ? 'tool-calls' : 'other';
}
}