@@ -562,6 +562,42 @@ describe('VertexAI', () => {
562
562
const resp = await model . generateContent ( req ) ;
563
563
expect ( resp ) . toEqual ( expectedResult ) ;
564
564
} ) ;
565
+
566
+ it ( 'throws ClientError when functionResponse is not immedidately following functionCall case1' , async ( ) => {
567
+ const req : GenerateContentRequest = {
568
+ contents : [
569
+ { role : 'user' , parts : [ { text : 'What is the weater like in Boston?' } ] } ,
570
+ {
571
+ role : 'function' ,
572
+ parts : TEST_FUNCTION_RESPONSE_PART ,
573
+ } ,
574
+ ] ,
575
+ tools : TEST_TOOLS_WITH_FUNCTION_DECLARATION ,
576
+ } ;
577
+ const expectedErrorMessage =
578
+ '[VertexAI.ClientError]: Please ensure that function response turn comes immediately after a function call turn.' ;
579
+ await model . generateContent ( req ) . catch ( e => {
580
+ expect ( e . message ) . toEqual ( expectedErrorMessage ) ;
581
+ } ) ;
582
+ } ) ;
583
+
584
+ it ( 'throws ClientError when functionResponse is not immedidately following functionCall case2' , async ( ) => {
585
+ const req : GenerateContentRequest = {
586
+ contents : [
587
+ { role : 'user' , parts : [ { text : 'What is the weater like in Boston?' } ] } ,
588
+ {
589
+ role : 'function' ,
590
+ parts : TEST_FUNCTION_RESPONSE_PART ,
591
+ } ,
592
+ ] ,
593
+ tools : TEST_TOOLS_WITH_FUNCTION_DECLARATION ,
594
+ } ;
595
+ const expectedErrorMessage =
596
+ '[VertexAI.ClientError]: Please ensure that function response turn comes immediately after a function call turn.' ;
597
+ await model . generateContent ( req ) . catch ( e => {
598
+ expect ( e . message ) . toEqual ( expectedErrorMessage ) ;
599
+ } ) ;
600
+ } ) ;
565
601
} ) ;
566
602
describe ( 'generateContentStream' , ( ) => {
567
603
it ( 'returns a GenerateContentResponse when passed text content' , async ( ) => {
@@ -629,6 +665,41 @@ describe('VertexAI', () => {
629
665
const resp = await model . generateContentStream ( req ) ;
630
666
expect ( resp ) . toEqual ( expectedStreamResult ) ;
631
667
} ) ;
668
+ it ( 'throws ClientError when functionResponse is not immedidately following functionCall case1' , async ( ) => {
669
+ const req : GenerateContentRequest = {
670
+ contents : [
671
+ { role : 'user' , parts : [ { text : 'What is the weater like in Boston?' } ] } ,
672
+ {
673
+ role : 'function' ,
674
+ parts : TEST_FUNCTION_RESPONSE_PART ,
675
+ } ,
676
+ ] ,
677
+ tools : TEST_TOOLS_WITH_FUNCTION_DECLARATION ,
678
+ } ;
679
+ const expectedErrorMessage =
680
+ '[VertexAI.ClientError]: Please ensure that function response turn comes immediately after a function call turn.' ;
681
+ await model . generateContentStream ( req ) . catch ( e => {
682
+ expect ( e . message ) . toEqual ( expectedErrorMessage ) ;
683
+ } ) ;
684
+ } ) ;
685
+
686
+ it ( 'throws ClientError when functionResponse is not immedidately following functionCall case2' , async ( ) => {
687
+ const req : GenerateContentRequest = {
688
+ contents : [
689
+ { role : 'user' , parts : [ { text : 'What is the weater like in Boston?' } ] } ,
690
+ {
691
+ role : 'function' ,
692
+ parts : TEST_FUNCTION_RESPONSE_PART ,
693
+ } ,
694
+ ] ,
695
+ tools : TEST_TOOLS_WITH_FUNCTION_DECLARATION ,
696
+ } ;
697
+ const expectedErrorMessage =
698
+ '[VertexAI.ClientError]: Please ensure that function response turn comes immediately after a function call turn.' ;
699
+ await model . generateContentStream ( req ) . catch ( e => {
700
+ expect ( e . message ) . toEqual ( expectedErrorMessage ) ;
701
+ } ) ;
702
+ } ) ;
632
703
} ) ;
633
704
634
705
describe ( 'startChat' , ( ) => {
@@ -805,6 +876,26 @@ describe('ChatSession', () => {
805
876
expect ( response2 ) . toEqual ( expectedFollowUpResponse ) ;
806
877
expect ( chatSessionWithFunctionCall . history . length ) . toEqual ( 4 ) ;
807
878
} ) ;
879
+
880
+ it ( 'throw ClientError when request has no content' , async ( ) => {
881
+ const expectedErrorMessage =
882
+ '[VertexAI.ClientError]: No content is provided for sending chat message.' ;
883
+ await chatSessionWithNoArgs . sendMessage ( [ ] ) . catch ( e => {
884
+ expect ( e . message ) . toEqual ( expectedErrorMessage ) ;
885
+ } ) ;
886
+ } ) ;
887
+
888
+ it ( 'throw ClientError when request mix functionCall part with other types of part' , async ( ) => {
889
+ const chatRequest = [
890
+ 'what is the weather like in LA' ,
891
+ TEST_FUNCTION_RESPONSE_PART [ 0 ] ,
892
+ ] ;
893
+ const expectedErrorMessage =
894
+ '[VertexAI.ClientError]: Within a single message, FunctionResponse cannot be mixed with other type of part in the request for sending chat message.' ;
895
+ await chatSessionWithNoArgs . sendMessage ( chatRequest ) . catch ( e => {
896
+ expect ( e . message ) . toEqual ( expectedErrorMessage ) ;
897
+ } ) ;
898
+ } ) ;
808
899
} ) ;
809
900
810
901
describe ( 'sendMessageStream' , ( ) => {
@@ -889,6 +980,26 @@ describe('ChatSession', () => {
889
980
expect ( response2 ) . toEqual ( expectedFollowUpStreamResult ) ;
890
981
expect ( chatSessionWithFunctionCall . history . length ) . toEqual ( 4 ) ;
891
982
} ) ;
983
+
984
+ it ( 'throw ClientError when request has no content' , async ( ) => {
985
+ const expectedErrorMessage =
986
+ '[VertexAI.ClientError]: No content is provided for sending chat message.' ;
987
+ await chatSessionWithNoArgs . sendMessageStream ( [ ] ) . catch ( e => {
988
+ expect ( e . message ) . toEqual ( expectedErrorMessage ) ;
989
+ } ) ;
990
+ } ) ;
991
+
992
+ it ( 'throw ClientError when request mix functionCall part with other types of part' , async ( ) => {
993
+ const chatRequest = [
994
+ 'what is the weather like in LA' ,
995
+ TEST_FUNCTION_RESPONSE_PART [ 0 ] ,
996
+ ] ;
997
+ const expectedErrorMessage =
998
+ '[VertexAI.ClientError]: Within a single message, FunctionResponse cannot be mixed with other type of part in the request for sending chat message.' ;
999
+ await chatSessionWithNoArgs . sendMessageStream ( chatRequest ) . catch ( e => {
1000
+ expect ( e . message ) . toEqual ( expectedErrorMessage ) ;
1001
+ } ) ;
1002
+ } ) ;
892
1003
} ) ;
893
1004
} ) ;
894
1005
0 commit comments