@@ -17,15 +17,12 @@ import {
1717} from '@ai-sdk/provider-utils' ;
1818import { z } from 'zod' ;
1919import { convertToOpenAIChatMessages } from './convert-to-openai-chat-messages' ;
20- import { mapOpenAIFinishReason } from './map-openai -finish-reason' ;
20+ import { mapLangtailFinishReason } from './map-langtail -finish-reason' ;
2121import { LangtailChatSettings } from './langtail-chat-settings' ;
2222import { openaiErrorDataSchema , openaiFailedResponseHandler } from './openai-error' ;
2323import { mapOpenAIChatLogProbsOutput } from './map-openai-chat-logprobs' ;
2424import { LangtailPrompts } from '../Langtail' ;
25- import { ChatCompletionCreateParamsBase } from 'openai/resources/chat/completions' ;
26- import { FunctionParameters } from 'openai/resources' ;
2725import type { PromptSlug , Environment , Version , LangtailEnvironment } from '../types' ;
28- import { ILangtailExtraProps } from '../schemas' ;
2926import { getResponseMetadata } from './get-response-metadata' ;
3027import { prepareTools } from './openai-prepare-tools' ;
3128
@@ -305,7 +302,7 @@ export class LangtailChatLanguageModel<P extends PromptSlug = PromptSlug, E exte
305302 toolName : toolCall . function . name ,
306303 args : toolCall . function . arguments ! ,
307304 } ) ) ,
308- finishReason : mapOpenAIFinishReason ( choice . finish_reason ) ,
305+ finishReason : mapLangtailFinishReason ( choice . finish_reason , Boolean ( choice . message . tool_calls ) ) ,
309306 usage : {
310307 promptTokens : response . usage ?. prompt_tokens ?? NaN ,
311308 completionTokens : response . usage ?. completion_tokens ?? NaN ,
@@ -428,7 +425,7 @@ export class LangtailChatLanguageModel<P extends PromptSlug = PromptSlug, E exte
428425 const choice = value . choices [ 0 ] ;
429426
430427 if ( choice ?. finish_reason != null ) {
431- finishReason = mapOpenAIFinishReason ( choice . finish_reason ) ;
428+ finishReason = mapLangtailFinishReason ( choice . finish_reason , Boolean ( choice . delta ?. tool_calls ) ) ;
432429 }
433430
434431 if ( choice ?. delta == null ) {
0 commit comments