@@ -667,7 +667,6 @@ describe('Bedrock', () => {
667667 } ) ;
668668
669669 const response = await client . send ( command ) ;
670- console . log ( 'response' , response ) ;
671670
672671 let collectedText = '' ;
673672 if ( ! response . body ) return ;
@@ -741,7 +740,6 @@ describe('Bedrock', () => {
741740 }
742741 }
743742 }
744-
745743 expect ( collectedText ) . toBe (
746744 "Hello! I'm doing well, thank you for asking."
747745 ) ;
@@ -813,6 +811,152 @@ describe('Bedrock', () => {
813811 [ ATTR_GEN_AI_RESPONSE_FINISH_REASONS ] : [ 'max_tokens' ] ,
814812 } ) ;
815813 } ) ;
814+
815+ it ( 'adds mistral ai model attributes to span' , async ( ) => {
816+ const modelId = 'mistral.mistral-small-2402-v1:0' ;
817+
818+ const prompt = '\n\nHuman: Hello, How are you today? \n\nAssistant:' ;
819+ const nativeRequest : any = {
820+ prompt : prompt ,
821+ max_tokens : 20 ,
822+ temperature : 0.8 ,
823+ top_p : 1 ,
824+ stop : [ '|' ] ,
825+ } ;
826+ const command = new InvokeModelWithResponseStreamCommand ( {
827+ modelId,
828+ body : JSON . stringify ( nativeRequest ) ,
829+ } ) ;
830+
831+ const response = await client . send ( command ) ;
832+
833+ let collectedText = '' ;
834+ if ( ! response . body ) return ;
835+ for await ( const chunk of response . body ) {
836+ if ( chunk ?. chunk ?. bytes instanceof Uint8Array ) {
837+ const parsed = JSON . parse ( decodeChunk ( chunk ) ) ;
838+
839+ if ( parsed . outputs [ 0 ] . text ) {
840+ collectedText += parsed . outputs [ 0 ] . text ;
841+ }
842+ }
843+ }
844+ expect ( collectedText ) . toBe (
845+ " I'm an AI, so I don't have feelings, but I'm functioning well"
846+ ) ;
847+
848+ const invokeModelSpans : ReadableSpan [ ] =
849+ getInvokeModelWithResponseStreamSpans ( ) ;
850+
851+ expect ( invokeModelSpans . length ) . toBe ( 1 ) ;
852+ expect ( invokeModelSpans [ 0 ] . attributes ) . toMatchObject ( {
853+ [ ATTR_GEN_AI_SYSTEM ] : GEN_AI_SYSTEM_VALUE_AWS_BEDROCK ,
854+ [ ATTR_GEN_AI_REQUEST_MODEL ] : modelId ,
855+ [ ATTR_GEN_AI_REQUEST_MAX_TOKENS ] : 20 ,
856+ [ ATTR_GEN_AI_REQUEST_TEMPERATURE ] : 0.8 ,
857+ [ ATTR_GEN_AI_REQUEST_TOP_P ] : 1 ,
858+ [ ATTR_GEN_AI_REQUEST_STOP_SEQUENCES ] : [ '|' ] ,
859+ [ ATTR_GEN_AI_USAGE_INPUT_TOKENS ] : 8 ,
860+ [ ATTR_GEN_AI_USAGE_OUTPUT_TOKENS ] : 1 ,
861+ [ ATTR_GEN_AI_RESPONSE_FINISH_REASONS ] : [ 'length' ] ,
862+ } ) ;
863+ } ) ;
864+
865+ it ( 'adds cohere command r model attributes to span' , async ( ) => {
866+ const modelId = 'cohere.command-r-v1:0' ;
867+ const prompt = 'Say this is a test' ;
868+ const nativeRequest : any = {
869+ message : prompt ,
870+ max_tokens : 10 ,
871+ temperature : 0.8 ,
872+ p : 0.99 ,
873+ stop_sequences : [ '|' ] ,
874+ } ;
875+
876+ const command = new InvokeModelWithResponseStreamCommand ( {
877+ modelId,
878+ body : JSON . stringify ( nativeRequest ) ,
879+ } ) ;
880+
881+ const response = await client . send ( command ) ;
882+
883+ let collectedText = '' ;
884+ if ( ! response . body ) return ;
885+ for await ( const chunk of response . body ) {
886+ if ( chunk ?. chunk ?. bytes instanceof Uint8Array ) {
887+ const parsed = JSON . parse ( decodeChunk ( chunk ) ) ;
888+ if ( parsed . text ) {
889+ collectedText += parsed . text ;
890+ }
891+ }
892+ }
893+ expect ( collectedText ) . toBe ( "This is indeed a test. Hopefully, it's" ) ;
894+
895+ const invokeModelSpans : ReadableSpan [ ] =
896+ getInvokeModelWithResponseStreamSpans ( ) ;
897+
898+ expect ( invokeModelSpans . length ) . toBe ( 1 ) ;
899+ expect ( invokeModelSpans [ 0 ] . attributes ) . toMatchObject ( {
900+ [ ATTR_GEN_AI_SYSTEM ] : GEN_AI_SYSTEM_VALUE_AWS_BEDROCK ,
901+ [ ATTR_GEN_AI_REQUEST_MODEL ] : modelId ,
902+ [ ATTR_GEN_AI_REQUEST_MAX_TOKENS ] : 10 ,
903+ [ ATTR_GEN_AI_REQUEST_TEMPERATURE ] : 0.8 ,
904+ [ ATTR_GEN_AI_REQUEST_TOP_P ] : 0.99 ,
905+ [ ATTR_GEN_AI_REQUEST_STOP_SEQUENCES ] : [ '|' ] ,
906+ [ ATTR_GEN_AI_USAGE_INPUT_TOKENS ] : 3 ,
907+ [ ATTR_GEN_AI_USAGE_OUTPUT_TOKENS ] : 1 ,
908+ [ ATTR_GEN_AI_RESPONSE_FINISH_REASONS ] : [ 'MAX_TOKENS' ] ,
909+ } ) ;
910+ } ) ;
911+
912+ it ( 'adds cohere command model attributes to span' , async ( ) => {
913+ const modelId = 'cohere.command-light-text-v14' ;
914+ const prompt = 'Say this is a test' ;
915+ const nativeRequest : any = {
916+ prompt : prompt ,
917+ max_tokens : 10 ,
918+ temperature : 0.8 ,
919+ p : 1 ,
920+ stop_sequences : [ '|' ] ,
921+ } ;
922+
923+ const command = new InvokeModelWithResponseStreamCommand ( {
924+ modelId,
925+ body : JSON . stringify ( nativeRequest ) ,
926+ } ) ;
927+
928+ const response = await client . send ( command ) ;
929+
930+ let collectedText = '' ;
931+ if ( ! response . body ) return ;
932+ for await ( const chunk of response . body ) {
933+ if ( chunk ?. chunk ?. bytes instanceof Uint8Array ) {
934+ const parsed = JSON . parse ( decodeChunk ( chunk ) ) ;
935+ if ( parsed . generations [ 0 ] . text ) {
936+ collectedText += parsed . generations [ 0 ] . text ;
937+ }
938+ }
939+ }
940+ expect ( collectedText ) . toBe (
941+ ' Okay, I will follow your instructions and this will'
942+ ) ;
943+
944+ const invokeModelSpans : ReadableSpan [ ] =
945+ getInvokeModelWithResponseStreamSpans ( ) ;
946+
947+ expect ( invokeModelSpans . length ) . toBe ( 1 ) ;
948+ expect ( invokeModelSpans [ 0 ] . attributes ) . toMatchObject ( {
949+ [ ATTR_GEN_AI_SYSTEM ] : GEN_AI_SYSTEM_VALUE_AWS_BEDROCK ,
950+ [ ATTR_GEN_AI_REQUEST_MODEL ] : modelId ,
951+ [ ATTR_GEN_AI_REQUEST_MAX_TOKENS ] : 10 ,
952+ [ ATTR_GEN_AI_REQUEST_TEMPERATURE ] : 0.8 ,
953+ [ ATTR_GEN_AI_REQUEST_TOP_P ] : 1 ,
954+ [ ATTR_GEN_AI_REQUEST_STOP_SEQUENCES ] : [ '|' ] ,
955+ [ ATTR_GEN_AI_USAGE_INPUT_TOKENS ] : 3 ,
956+ [ ATTR_GEN_AI_USAGE_OUTPUT_TOKENS ] : 9 ,
957+ [ ATTR_GEN_AI_RESPONSE_FINISH_REASONS ] : [ 'MAX_TOKENS' ] ,
958+ } ) ;
959+ } ) ;
816960 } ) ;
817961
818962 function getInvokeModelWithResponseStreamSpans ( ) : ReadableSpan [ ] {
0 commit comments