1
1
import {
2
2
BEDROCK ,
3
3
documentMimeTypes ,
4
- fileExtensionMimeTypeMap ,
5
4
imagesMimeTypes ,
5
+ fileExtensionMimeTypeMap ,
6
6
} from '../../globals' ;
7
7
import {
8
8
Message ,
@@ -62,7 +62,7 @@ export interface BedrockChatCompletionsParams extends Params {
62
62
}
63
63
64
64
export interface BedrockConverseAnthropicChatCompletionsParams
65
- extends Omit < BedrockChatCompletionsParams , 'anthropic_beta' > {
65
+ extends BedrockChatCompletionsParams {
66
66
anthropic_version ?: string ;
67
67
user ?: string ;
68
68
thinking ?: {
@@ -477,9 +477,6 @@ export const BedrockChatCompleteResponseTransform: (
477
477
}
478
478
479
479
if ( 'output' in response ) {
480
- const cacheReadInputTokens = response . usage ?. cacheReadInputTokens || 0 ;
481
- const cacheWriteInputTokens = response . usage ?. cacheWriteInputTokens || 0 ;
482
-
483
480
let content : string = '' ;
484
481
content = response . output . message . content
485
482
. filter ( ( item ) => item . text )
@@ -489,6 +486,9 @@ export const BedrockChatCompleteResponseTransform: (
489
486
? transformContentBlocks ( response . output . message . content )
490
487
: undefined ;
491
488
489
+ const cacheReadInputTokens = response . usage ?. cacheReadInputTokens || 0 ;
490
+ const cacheWriteInputTokens = response . usage ?. cacheWriteInputTokens || 0 ;
491
+
492
492
const responseObj : ChatCompletionResponse = {
493
493
id : Date . now ( ) . toString ( ) ,
494
494
object : 'chat.completion' ,
@@ -571,7 +571,6 @@ export const BedrockChatCompleteStreamChunkTransform: (
571
571
streamState . currentToolCallIndex = - 1 ;
572
572
}
573
573
574
- // final chunk
575
574
if ( parsedChunk . usage ) {
576
575
const cacheReadInputTokens = parsedChunk . usage ?. cacheReadInputTokens || 0 ;
577
576
const cacheWriteInputTokens = parsedChunk . usage ?. cacheWriteInputTokens || 0 ;
@@ -605,9 +604,8 @@ export const BedrockChatCompleteStreamChunkTransform: (
605
604
} ,
606
605
// we only want to be sending this for anthropic models and this is not openai compliant
607
606
...( ( cacheReadInputTokens > 0 || cacheWriteInputTokens > 0 ) && {
608
- cache_read_input_tokens : parsedChunk . usage . cacheReadInputTokens ,
609
- cache_creation_input_tokens :
610
- parsedChunk . usage . cacheWriteInputTokens ,
607
+ cache_read_input_tokens : cacheReadInputTokens ,
608
+ cache_creation_input_tokens : cacheWriteInputTokens ,
611
609
} ) ,
612
610
} ,
613
611
} ) } \n\n`,
0 commit comments