@@ -156,11 +156,11 @@ const getMessageContent = (message: Message) => {
156
156
const inputContent : ContentType [ ] | string | undefined =
157
157
message . content_blocks ?? message . content ;
158
158
// if message is a string, return a single element array with the text
159
- if ( typeof inputContent === 'string' ) {
159
+ if ( typeof inputContent === 'string' && inputContent . trim ( ) ) {
160
160
out . push ( {
161
161
text : inputContent ,
162
162
} ) ;
163
- } else if ( inputContent ) {
163
+ } else if ( inputContent && Array . isArray ( inputContent ) ) {
164
164
inputContent . forEach ( ( item ) => {
165
165
if ( item . type === 'text' ) {
166
166
out . push ( {
@@ -285,7 +285,9 @@ export const BedrockConverseChatCompleteConfig: ProviderConfig = {
285
285
required : false ,
286
286
transform : ( params : BedrockChatCompletionsParams ) => {
287
287
if ( ! params . messages ) return ;
288
- const systemMessages = params . messages . reduce (
288
+ const systemMessages : Array <
289
+ { text : string } | { cachePoint : { type : string } }
290
+ > = params . messages . reduce (
289
291
(
290
292
acc : Array < { text : string } | { cachePoint : { type : string } } > ,
291
293
msg
@@ -326,7 +328,7 @@ export const BedrockConverseChatCompleteConfig: ProviderConfig = {
326
328
}
327
329
} ) ;
328
330
const toolConfig = {
329
- tools : tools ,
331
+ tools,
330
332
} ;
331
333
let toolChoice = undefined ;
332
334
if ( params . tool_choice ) {
@@ -556,7 +558,7 @@ export const BedrockChatCompleteResponseTransform: (
556
558
usage : {
557
559
prompt_tokens : response . usage . inputTokens ,
558
560
completion_tokens : response . usage . outputTokens ,
559
- total_tokens : response . usage . totalTokens ,
561
+ total_tokens : response . usage . totalTokens , // contains the cache usage as well
560
562
...( shouldSendCacheUsage && {
561
563
cache_read_input_tokens : response . usage . cacheReadInputTokens ,
562
564
cache_creation_input_tokens : response . usage . cacheWriteInputTokens ,
@@ -871,7 +873,7 @@ export const BedrockCohereChatCompleteConfig: ProviderConfig = {
871
873
required : true ,
872
874
transform : ( params : Params ) => {
873
875
let prompt : string = '' ;
874
- if ( ! ! params . messages ) {
876
+ if ( params . messages ) {
875
877
let messages : Message [ ] = params . messages ;
876
878
messages . forEach ( ( msg , index ) => {
877
879
if ( index === 0 && SYSTEM_MESSAGE_ROLES . includes ( msg . role ) ) {
@@ -1073,7 +1075,7 @@ export const BedrockAI21ChatCompleteConfig: ProviderConfig = {
1073
1075
required : true ,
1074
1076
transform : ( params : Params ) => {
1075
1077
let prompt : string = '' ;
1076
- if ( ! ! params . messages ) {
1078
+ if ( params . messages ) {
1077
1079
let messages : Message [ ] = params . messages ;
1078
1080
messages . forEach ( ( msg , index ) => {
1079
1081
if ( index === 0 && SYSTEM_MESSAGE_ROLES . includes ( msg . role ) ) {
0 commit comments