@@ -397,3 +397,124 @@ class TestModel(BaseModel):
397397 assert result_config .tools is not None
398398 assert result_config .tool_config is not None
399399 assert result_config .system_instruction is not None
400+
401+
402+ def test_update_genai_kwargs_config_dict_labels ():
403+ """Test that labels is merged when config is provided as a dict (issue #1759)."""
404+ kwargs = {"config" : {"labels" : {"env" : "prod" , "team" : "ml" }}}
405+ base_config : dict [str , object ] = {}
406+
407+ result = update_genai_kwargs (kwargs , base_config )
408+
409+ assert result ["labels" ] == {"env" : "prod" , "team" : "ml" }
410+
411+
412+ def test_update_genai_kwargs_config_dict_cached_content ():
413+ """Test that cached_content is merged when config is provided as a dict."""
414+ kwargs = {"config" : {"cached_content" : "caches/dict123" }}
415+ base_config : dict [str , object ] = {}
416+
417+ result = update_genai_kwargs (kwargs , base_config )
418+
419+ assert result ["cached_content" ] == "caches/dict123"
420+
421+
422+ def test_update_genai_kwargs_config_dict_thinking_config ():
423+ """Test that thinking_config is merged when config is provided as a dict."""
424+ thinking_config = {"thinking_budget" : 1234 }
425+ kwargs = {"config" : {"thinking_config" : thinking_config }}
426+ base_config : dict [str , object ] = {}
427+
428+ result = update_genai_kwargs (kwargs , base_config )
429+
430+ assert result ["thinking_config" ] == thinking_config
431+
432+
433+ def test_handle_genai_structured_outputs_preserves_labels_from_config_dict ():
434+ """Test that labels are preserved when config is provided as a dict (issue #1759)."""
435+ from pydantic import BaseModel
436+
437+ from instructor .providers .gemini .utils import handle_genai_structured_outputs
438+
439+ class TestModel (BaseModel ):
440+ name : str
441+
442+ new_kwargs = {
443+ "messages" : [{"role" : "user" , "content" : "Hello" }],
444+ "config" : {"labels" : {"tenant" : "acme" , "cost-center" : "123" }},
445+ }
446+
447+ _ , result_kwargs = handle_genai_structured_outputs (TestModel , new_kwargs )
448+
449+ result_config = result_kwargs ["config" ]
450+ assert result_config .labels == {"tenant" : "acme" , "cost-center" : "123" }
451+
452+
453+ def test_handle_genai_tools_preserves_labels_from_config_dict ():
454+ """Test that labels are preserved in tools mode when config is a dict (issue #1759)."""
455+ from pydantic import BaseModel
456+
457+ from instructor .providers .gemini .utils import handle_genai_tools
458+
459+ class TestModel (BaseModel ):
460+ name : str
461+
462+ new_kwargs = {
463+ "messages" : [{"role" : "user" , "content" : "Hello" }],
464+ "config" : {"labels" : {"tenant" : "acme" , "cost-center" : "123" }},
465+ }
466+
467+ _ , result_kwargs = handle_genai_tools (TestModel , new_kwargs )
468+
469+ result_config = result_kwargs ["config" ]
470+ assert result_config .labels == {"tenant" : "acme" , "cost-center" : "123" }
471+
472+
473+ def test_handle_genai_structured_outputs_skips_system_instruction_with_cached_content_dict ():
474+ """Test cached_content dict config disables system_instruction in structured outputs."""
475+ from pydantic import BaseModel
476+
477+ from instructor .providers .gemini .utils import handle_genai_structured_outputs
478+
479+ class TestModel (BaseModel ):
480+ name : str
481+
482+ new_kwargs = {
483+ "messages" : [
484+ {"role" : "system" , "content" : "You are a helpful assistant." },
485+ {"role" : "user" , "content" : "Hello" },
486+ ],
487+ "config" : {"cached_content" : "caches/dict-cache-1" },
488+ }
489+
490+ _ , result_kwargs = handle_genai_structured_outputs (TestModel , new_kwargs )
491+
492+ result_config = result_kwargs ["config" ]
493+ assert result_config .cached_content == "caches/dict-cache-1"
494+ assert result_config .system_instruction is None
495+
496+
497+ def test_handle_genai_tools_skips_tools_and_system_instruction_with_cached_content_dict ():
498+ """Test cached_content dict config disables tools/tool_config/system_instruction in tools mode."""
499+ from pydantic import BaseModel
500+
501+ from instructor .providers .gemini .utils import handle_genai_tools
502+
503+ class TestModel (BaseModel ):
504+ name : str
505+
506+ new_kwargs = {
507+ "messages" : [
508+ {"role" : "system" , "content" : "You are a helpful assistant." },
509+ {"role" : "user" , "content" : "Hello" },
510+ ],
511+ "config" : {"cached_content" : "caches/dict-cache-2" },
512+ }
513+
514+ _ , result_kwargs = handle_genai_tools (TestModel , new_kwargs )
515+
516+ result_config = result_kwargs ["config" ]
517+ assert result_config .cached_content == "caches/dict-cache-2"
518+ assert result_config .system_instruction is None
519+ assert result_config .tools is None
520+ assert result_config .tool_config is None
0 commit comments