@@ -41,16 +41,17 @@ import {constants} from '../src/util';
41
41
42
42
const PROJECT = 'test_project' ;
43
43
const LOCATION = 'test_location' ;
44
+ const TEST_CHAT_MESSSAGE_TEXT = 'How are you doing today?' ;
44
45
const TEST_USER_CHAT_MESSAGE = [
45
- { role : constants . USER_ROLE , parts : [ { text : 'How are you doing today?' } ] } ,
46
+ { role : constants . USER_ROLE , parts : [ { text : TEST_CHAT_MESSSAGE_TEXT } ] } ,
46
47
] ;
47
48
const TEST_TOKEN = 'testtoken' ;
48
49
49
50
const TEST_USER_CHAT_MESSAGE_WITH_GCS_FILE = [
50
51
{
51
52
role : constants . USER_ROLE ,
52
53
parts : [
53
- { text : 'How are you doing today?' } ,
54
+ { text : TEST_CHAT_MESSSAGE_TEXT } ,
54
55
{
55
56
file_data : {
56
57
file_uri : 'gs://test_bucket/test_image.jpeg' ,
@@ -65,7 +66,7 @@ const TEST_USER_CHAT_MESSAGE_WITH_INVALID_GCS_FILE = [
65
66
{
66
67
role : constants . USER_ROLE ,
67
68
parts : [
68
- { text : 'How are you doing today?' } ,
69
+ { text : TEST_CHAT_MESSSAGE_TEXT } ,
69
70
{ file_data : { file_uri : 'test_image.jpeg' , mime_type : 'image/jpeg' } } ,
70
71
] ,
71
72
} ,
@@ -234,6 +235,16 @@ describe('VertexAI', () => {
234
235
const resp = await model . generateContent ( req ) ;
235
236
expect ( resp ) . toEqual ( expectedResult ) ;
236
237
} ) ;
238
+ it ( 'returns a GenerateContentResponse when passed a string' , async ( ) => {
239
+ const expectedResult : GenerateContentResult = {
240
+ response : TEST_MODEL_RESPONSE ,
241
+ } ;
242
+ spyOn ( StreamFunctions , 'processStream' ) . and . returnValue (
243
+ expectedStreamResult
244
+ ) ;
245
+ const resp = await model . generateContent ( TEST_CHAT_MESSSAGE_TEXT ) ;
246
+ expect ( resp ) . toEqual ( expectedResult ) ;
247
+ } ) ;
237
248
} ) ;
238
249
239
250
describe ( 'generateContent' , ( ) => {
@@ -450,6 +461,15 @@ describe('VertexAI', () => {
450
461
const resp = await model . generateContentStream ( req ) ;
451
462
expect ( resp ) . toEqual ( expectedResult ) ;
452
463
} ) ;
464
+ it ( 'returns a GenerateContentResponse when passed a string' , async ( ) => {
465
+ const expectedResult : StreamGenerateContentResult = {
466
+ response : Promise . resolve ( TEST_MODEL_RESPONSE ) ,
467
+ stream : testGenerator ( ) ,
468
+ } ;
469
+ spyOn ( StreamFunctions , 'processStream' ) . and . returnValue ( expectedResult ) ;
470
+ const resp = await model . generateContentStream ( TEST_CHAT_MESSSAGE_TEXT ) ;
471
+ expect ( resp ) . toEqual ( expectedResult ) ;
472
+ } ) ;
453
473
} ) ;
454
474
455
475
describe ( 'generateContentStream' , ( ) => {
0 commit comments