@@ -517,8 +517,8 @@ async def model_astream(context: str) -> List[BaseMessageChunk]:
517
517
518
518
def test_output_matches_prompt_keys () -> None :
519
519
"""
520
- Validate that when response_mime_type="application/json" is specified,
521
- the output is a valid JSON format and contains the expected structure
520
+ Validate that when response_mime_type="application/json" is specified,
521
+ the output is a valid JSON format and contains the expected structure
522
522
based on the prompt.
523
523
"""
524
524
@@ -554,8 +554,9 @@ def test_output_matches_prompt_keys() -> None:
554
554
pytest .fail (f"Response is not valid JSON: { e } " )
555
555
556
556
list_key = prompt_key_names ["list_key" ]
557
- assert list_key in response_data , \
558
- f"Expected key '{ list_key } ' is missing in the response."
557
+ assert (
558
+ list_key in response_data
559
+ ), f"Expected key '{ list_key } ' is missing in the response."
559
560
grocery_items = response_data [list_key ]
560
561
assert isinstance (grocery_items , list ), f"'{ list_key } ' should be a list."
561
562
@@ -569,21 +570,22 @@ def test_output_matches_prompt_keys() -> None:
569
570
570
571
print ("Response matches the key names specified in the prompt." )
571
572
573
+
572
574
def test_validate_response_mime_type_and_schema () -> None :
573
575
"""
574
576
Test that `response_mime_type` and `response_schema` are validated correctly.
575
577
Ensure valid combinations of `response_mime_type` and `response_schema` pass,
576
578
and invalid ones raise appropriate errors.
577
579
"""
578
580
579
- valid_model = ChatGoogleGenerativeAI (
581
+ llm = ChatGoogleGenerativeAI (
580
582
model = "gemini-1.5-pro" ,
581
583
response_mime_type = "application/json" ,
582
584
response_schema = {"type" : "list" , "items" : {"type" : "object" }}, # Example schema
583
585
)
584
586
585
587
try :
586
- valid_model . validate_environment ( )
588
+ llm . invoke ( "Hello" )
587
589
except ValueError as e :
588
590
pytest .fail (f"Validation failed unexpectedly with valid parameters: { e } " )
589
591
@@ -592,14 +594,14 @@ def test_validate_response_mime_type_and_schema() -> None:
592
594
model = "gemini-1.5-pro" ,
593
595
response_mime_type = "invalid/type" ,
594
596
response_schema = {"type" : "list" , "items" : {"type" : "object" }},
595
- ).validate_environment ( )
597
+ ).invoke ( "Hello" )
596
598
597
599
try :
598
600
ChatGoogleGenerativeAI (
599
601
model = "gemini-1.5-pro" ,
600
602
response_mime_type = "application/json" ,
601
- ).validate_environment ( )
603
+ ).invoke ( "Hello" )
602
604
except ValueError as e :
603
605
pytest .fail (
604
606
f"Validation failed unexpectedly with a valid MIME type and no schema: { e } "
605
- )
607
+ )
0 commit comments