@@ -204,25 +204,45 @@ def test_nonstreaming_generate_content(
204204 assert invoke_span ["data" ][SPANDATA .GEN_AI_REQUEST_MAX_TOKENS ] == 100
205205
206206
207- # Vibed test cases
207+ # Threatened bot to generate as many cases as possible
208208@pytest .mark .parametrize (
209209 "system_instructions,expected_texts" ,
210210 [
211- ("You are a helpful assistant" , "You are a helpful assistant" ),
211+ ("You are a helpful assistant" , [ "You are a helpful assistant" ] ),
212212 (
213213 ["You are a translator" , "Translate to French" ],
214214 ["You are a translator" , "Translate to French" ],
215215 ),
216216 (
217217 Content (role = "user" , parts = [Part (text = "You are a helpful assistant" )]),
218- "You are a helpful assistant" ,
218+ ["You are a helpful assistant" ],
219+ ),
220+ (
221+ Content (
222+ role = "user" ,
223+ parts = [
224+ Part (text = "You are a translator" ),
225+ Part (text = "Translate to French" ),
226+ ],
227+ ),
228+ ["You are a translator" , "Translate to French" ],
219229 ),
220230 (
221231 {"parts" : [{"text" : "You are a helpful assistant" }], "role" : "user" },
222- "You are a helpful assistant" ,
232+ [ "You are a helpful assistant" ] ,
223233 ),
224- (Part (text = "You are a helpful assistant" ), "You are a helpful assistant" ),
225- ({"text" : "You are a helpful assistant" }, "You are a helpful assistant" ),
234+ (
235+ {
236+ "parts" : [
237+ {"text" : "You are a translator" },
238+ {"text" : "Translate to French" },
239+ ],
240+ "role" : "user" ,
241+ },
242+ ["You are a translator" , "Translate to French" ],
243+ ),
244+ (Part (text = "You are a helpful assistant" ), ["You are a helpful assistant" ]),
245+ ({"text" : "You are a helpful assistant" }, ["You are a helpful assistant" ]),
226246 (
227247 [Part (text = "You are a translator" ), Part (text = "Translate to French" )],
228248 ["You are a translator" , "Translate to French" ],
@@ -232,14 +252,44 @@ def test_nonstreaming_generate_content(
232252 ["You are a translator" , "Translate to French" ],
233253 ),
234254 (
235- Content (
236- role = "user" ,
237- parts = [
238- Part (text = "You are a translator" ),
239- Part (text = "Translate to French" ),
255+ [Part (text = "First instruction" ), {"text" : "Second instruction" }],
256+ ["First instruction" , "Second instruction" ],
257+ ),
258+ (
259+ {
260+ "parts" : [
261+ Part (text = "First instruction" ),
262+ {"text" : "Second instruction" },
240263 ],
241- ),
242- ["You are a translator" , "Translate to French" ],
264+ "role" : "user" ,
265+ },
266+ ["First instruction" , "Second instruction" ],
267+ ),
268+ (None , None ),
269+ ("" , []),
270+ ({}, []),
271+ ({"parts" : []}, []),
272+ (Content (role = "user" , parts = []), []),
273+ (
274+ {
275+ "parts" : [
276+ {"text" : "Text part" },
277+ {"file_data" : {"file_uri" : "gs://bucket/file.pdf" }},
278+ ],
279+ "role" : "user" ,
280+ },
281+ ["Text part" ],
282+ ),
283+ (
284+ {
285+ "parts" : [
286+ {"text" : "First" },
287+ Part (text = "Second" ),
288+ {"text" : "Third" },
289+ ],
290+ "role" : "user" ,
291+ },
292+ ["First" , "Second" , "Third" ],
243293 ),
244294 ],
245295)
@@ -270,6 +320,10 @@ def test_generate_content_with_system_instruction(
270320 (event ,) = events
271321 invoke_span = event ["spans" ][0 ]
272322
323+ if expected_texts is None :
324+ assert SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS not in invoke_span ["data" ]
325+ return
326+
273327 # (PII is enabled and include_prompts is True in this test)
274328 system_instructions = json .loads (
275329 invoke_span ["data" ][SPANDATA .GEN_AI_SYSTEM_INSTRUCTIONS ]
0 commit comments