@@ -642,6 +642,99 @@ public function testUsingModel(): void
642642        $ this assertSame ($ model$ actualModel
643643    }
644644
645+     /** 
646+      * Tests usingModelConfig method. 
647+      * 
648+      * @return void 
649+      */ 
650+     public  function  testUsingModelConfig (): void 
651+     {
652+         $ buildernew  PromptBuilder ($ this registry );
653+ 
654+         // Set some initial config values on the builder 
655+         $ builderusingSystemInstruction ('Builder instruction ' )
656+                 ->usingMaxTokens (500 )
657+                 ->usingTemperature (0.5 );
658+ 
659+         // Create a config to merge 
660+         $ confignew  ModelConfig ();
661+         $ configsetSystemInstruction ('Config instruction ' );
662+         $ configsetMaxTokens (1000 );
663+         $ configsetTopP (0.9 );
664+         $ configsetTopK (40 );
665+ 
666+         $ result$ builderusingModelConfig ($ config
667+ 
668+         // Assert fluent interface 
669+         $ this assertSame ($ builder$ result
670+ 
671+         // Get the merged config 
672+         $ reflectionnew  \ReflectionClass ($ builder
673+         $ configProperty$ reflectiongetProperty ('modelConfig ' );
674+         $ configPropertysetAccessible (true );
675+ 
676+         /** @var ModelConfig $mergedConfig */ 
677+         $ mergedConfig$ configPropertygetValue ($ builder
678+ 
679+         // Assert builder values take precedence 
680+         $ this assertEquals ('Builder instruction ' , $ mergedConfiggetSystemInstruction ());
681+         $ this assertEquals (500 , $ mergedConfiggetMaxTokens ());
682+         $ this assertEquals (0.5 , $ mergedConfiggetTemperature ());
683+ 
684+         // Assert config values are used when builder doesn't have them 
685+         $ this assertEquals (0.9 , $ mergedConfiggetTopP ());
686+         $ this assertEquals (40 , $ mergedConfiggetTopK ());
687+     }
688+ 
689+     /** 
690+      * Tests usingModelConfig with custom options. 
691+      * 
692+      * @return void 
693+      */ 
694+     public  function  testUsingModelConfigWithCustomOptions (): void 
695+     {
696+         $ buildernew  PromptBuilder ($ this registry );
697+ 
698+         // Create a config with custom options 
699+         $ confignew  ModelConfig ();
700+         $ configsetCustomOption ('stopSequences ' , ['CONFIG_STOP ' ]);
701+         $ configsetCustomOption ('otherOption ' , 'value ' );
702+ 
703+         $ builderusingModelConfig ($ config
704+ 
705+         // Get the merged config 
706+         $ reflectionnew  \ReflectionClass ($ builder
707+         $ configProperty$ reflectiongetProperty ('modelConfig ' );
708+         $ configPropertysetAccessible (true );
709+ 
710+         /** @var ModelConfig $mergedConfig */ 
711+         $ mergedConfig$ configPropertygetValue ($ builder
712+         $ customOptions$ mergedConfiggetCustomOptions ();
713+ 
714+         // Assert config custom options are preserved 
715+         $ this assertArrayHasKey ('stopSequences ' , $ customOptions
716+         $ this assertIsArray ($ customOptions'stopSequences ' ]);
717+         $ this assertEquals (['CONFIG_STOP ' ], $ customOptions'stopSequences ' ]);
718+         $ this assertArrayHasKey ('otherOption ' , $ customOptions
719+         $ this assertEquals ('value ' , $ customOptions'otherOption ' ]);
720+ 
721+         // Now set a builder value that overrides one of the custom options 
722+         $ builderusingStopSequences ('STOP ' );
723+ 
724+         // Get the config again 
725+         $ mergedConfig$ configPropertygetValue ($ builder
726+         $ customOptions$ mergedConfiggetCustomOptions ();
727+ 
728+         // Assert builder's stop sequences override the config's 
729+         $ this assertArrayHasKey ('stopSequences ' , $ customOptions
730+         $ this assertIsArray ($ customOptions'stopSequences ' ]);
731+         $ this assertEquals (['STOP ' ], $ customOptions'stopSequences ' ]);
732+ 
733+         // Assert other custom options are still preserved 
734+         $ this assertArrayHasKey ('otherOption ' , $ customOptions
735+         $ this assertEquals ('value ' , $ customOptions'otherOption ' ]);
736+     }
737+ 
645738    /** 
646739     * Tests usingProvider method. 
647740     * 
0 commit comments