@@ -11,7 +11,7 @@ import {
11
11
import {
12
12
ContentBlock ,
13
13
MessagesResponse ,
14
- STOP_REASON ,
14
+ ANTHROPIC_STOP_REASON ,
15
15
} from '../../types/messagesResponse' ;
16
16
import { RawContentBlockDeltaEvent } from '../../types/MessagesStreamResponse' ;
17
17
import {
@@ -22,7 +22,10 @@ import {
22
22
ANTHROPIC_MESSAGE_STOP_EVENT ,
23
23
} from '../anthropic-base/constants' ;
24
24
import { ErrorResponse , ProviderConfig } from '../types' ;
25
- import { generateInvalidProviderResponseError } from '../utils' ;
25
+ import {
26
+ generateInvalidProviderResponseError ,
27
+ transformToAnthropicStopReason ,
28
+ } from '../utils' ;
26
29
import { BedrockErrorResponseTransform } from './chatComplete' ;
27
30
import { BedrockErrorResponse } from './embed' ;
28
31
import {
@@ -185,7 +188,6 @@ const appendToolResultBlock = (
185
188
text : item . text ,
186
189
} ) ;
187
190
} else if ( item . type === 'image' ) {
188
- // TODO: test this
189
191
appendImageBlock ( transformedToolResultContent , item ) ;
190
192
}
191
193
}
@@ -419,8 +421,7 @@ export const BedrockMessagesResponseTransform = (
419
421
type : 'message' ,
420
422
role : 'assistant' ,
421
423
content : transformedContent ,
422
- // TODO: pull changes from stop reason transformation PR
423
- stop_reason : response . stopReason as STOP_REASON ,
424
+ stop_reason : transformToAnthropicStopReason ( response . stopReason ) ,
424
425
usage : {
425
426
cache_read_input_tokens : response . usage . cacheReadInputTokens ,
426
427
cache_creation_input_tokens : response . usage . cacheWriteInputTokens ,
@@ -535,15 +536,16 @@ export const BedrockConverseMessagesStreamChunkTransform = (
535
536
parsedChunk . usage . cacheReadInputTokens ;
536
537
messageDeltaEvent . usage . cache_creation_input_tokens =
537
538
parsedChunk . usage . cacheWriteInputTokens ;
538
- messageDeltaEvent . delta . stop_reason = streamState . stopReason || '' ;
539
+ messageDeltaEvent . delta . stop_reason = transformToAnthropicStopReason (
540
+ streamState . stopReason
541
+ ) ;
539
542
const contentBlockStopEvent = { ...ANTHROPIC_CONTENT_BLOCK_STOP_EVENT } ;
540
543
contentBlockStopEvent . index = streamState . currentContentBlockIndex ;
541
544
let returnChunk = `event: content_block_stop\ndata: ${ JSON . stringify ( contentBlockStopEvent ) } \n\n` ;
542
545
returnChunk += `event: message_delta\ndata: ${ JSON . stringify ( messageDeltaEvent ) } \n\n` ;
543
546
returnChunk += `event: message_stop\ndata: ${ JSON . stringify ( ANTHROPIC_MESSAGE_STOP_EVENT ) } \n\n` ;
544
547
return returnChunk ;
545
548
}
546
- // console.log(JSON.stringify(parsedChunk, null, 2));
547
549
} ;
548
550
549
551
function getMessageStartEvent ( fallbackId : string , gatewayRequest : Params < any > ) {
0 commit comments