@@ -28,6 +28,7 @@ use(chaiAsPromised);
28
28
29
29
const FAKE_CONTENTS = [ { role : "user" , parts : [ { text : "some text" } ] } ] ;
30
30
const FAKE_CACHE_NAME = "cachedContents/hash1234" ;
31
+ const SYSTEM_INSTRUCTION = "You are a fish" ;
31
32
const fakeResponseJson : ( ) => Promise < { } > = ( ) =>
32
33
Promise . resolve ( { name : FAKE_CACHE_NAME } ) ;
33
34
const model = "models/gemini-1.5-pro-001" ;
@@ -124,6 +125,12 @@ describe("GoogleAICacheManager", () => {
124
125
expect ( makeRequestStub . args [ 0 ] [ 0 ] . toString ( ) ) . to . match (
125
126
/ ^ h t t p : \/ \/ m y s i t e \. c o m / ,
126
127
) ;
128
+ expect ( typeof makeRequestStub . args [ 0 ] [ 2 ] ) . to . eq ( "string" ) ;
129
+ const body = JSON . parse ( makeRequestStub . args [ 0 ] [ 2 ] as string ) ;
130
+ expect ( body . contents [ 0 ] . parts [ 0 ] . text ) . to . eq (
131
+ FAKE_CONTENTS [ 0 ] . parts [ 0 ] . text ,
132
+ ) ;
133
+ expect ( body . contents [ 0 ] . role ) . to . eq ( FAKE_CONTENTS [ 0 ] . role ) ;
127
134
} ) ;
128
135
it ( "passes update request info" , async ( ) => {
129
136
const makeRequestStub = stub ( request , "makeServerRequest" ) . resolves ( {
@@ -294,4 +301,31 @@ describe("GoogleAICacheManager", () => {
294
301
const cacheManager = new GoogleAICacheManager ( "apiKey" ) ;
295
302
await expect ( cacheManager . delete ( "" ) ) . to . be . rejectedWith ( "Invalid name" ) ;
296
303
} ) ;
304
+ it ( "passes system instructions" , async ( ) => {
305
+ const makeRequestStub = stub ( request , "makeServerRequest" ) . resolves ( {
306
+ ok : true ,
307
+ json : fakeResponseJson ,
308
+ } as Response ) ;
309
+ const cacheManager = new GoogleAICacheManager ( "apiKey" , {
310
+ apiVersion : "v3000" ,
311
+ baseUrl : "http://mysite.com" ,
312
+ } ) ;
313
+ await cacheManager . create ( {
314
+ model,
315
+ contents : FAKE_CONTENTS ,
316
+ systemInstruction : SYSTEM_INSTRUCTION ,
317
+ } ) ;
318
+ expect ( makeRequestStub . args [ 0 ] [ 0 ] . task ) . to . equal ( RpcTask . CREATE ) ;
319
+ expect ( makeRequestStub . args [ 0 ] [ 1 ] ) . to . be . instanceOf ( Headers ) ;
320
+ expect ( makeRequestStub . args [ 0 ] [ 0 ] . toString ( ) ) . to . include (
321
+ "v3000/cachedContents" ,
322
+ ) ;
323
+ expect ( makeRequestStub . args [ 0 ] [ 0 ] . toString ( ) ) . to . match (
324
+ / ^ h t t p : \/ \/ m y s i t e \. c o m / ,
325
+ ) ;
326
+ expect ( typeof makeRequestStub . args [ 0 ] [ 2 ] ) . to . eq ( "string" ) ;
327
+ const body = JSON . parse ( makeRequestStub . args [ 0 ] [ 2 ] as string ) ;
328
+ expect ( body . systemInstruction . parts [ 0 ] . text ) . to . eq ( SYSTEM_INSTRUCTION ) ;
329
+ expect ( body . systemInstruction . role ) . to . eq ( "system" ) ;
330
+ } ) ;
297
331
} ) ;
0 commit comments