@@ -642,6 +642,99 @@ public function testUsingModel(): void
642
642
$ this ->assertSame ($ model , $ actualModel );
643
643
}
644
644
645
+ /**
646
+ * Tests usingModelConfig method.
647
+ *
648
+ * @return void
649
+ */
650
+ public function testUsingModelConfig (): void
651
+ {
652
+ $ builder = new PromptBuilder ($ this ->registry );
653
+
654
+ // Set some initial config values on the builder
655
+ $ builder ->usingSystemInstruction ('Builder instruction ' )
656
+ ->usingMaxTokens (500 )
657
+ ->usingTemperature (0.5 );
658
+
659
+ // Create a config to merge
660
+ $ config = new ModelConfig ();
661
+ $ config ->setSystemInstruction ('Config instruction ' );
662
+ $ config ->setMaxTokens (1000 );
663
+ $ config ->setTopP (0.9 );
664
+ $ config ->setTopK (40 );
665
+
666
+ $ result = $ builder ->usingModelConfig ($ config );
667
+
668
+ // Assert fluent interface
669
+ $ this ->assertSame ($ builder , $ result );
670
+
671
+ // Get the merged config
672
+ $ reflection = new \ReflectionClass ($ builder );
673
+ $ configProperty = $ reflection ->getProperty ('modelConfig ' );
674
+ $ configProperty ->setAccessible (true );
675
+
676
+ /** @var ModelConfig $mergedConfig */
677
+ $ mergedConfig = $ configProperty ->getValue ($ builder );
678
+
679
+ // Assert builder values take precedence
680
+ $ this ->assertEquals ('Builder instruction ' , $ mergedConfig ->getSystemInstruction ());
681
+ $ this ->assertEquals (500 , $ mergedConfig ->getMaxTokens ());
682
+ $ this ->assertEquals (0.5 , $ mergedConfig ->getTemperature ());
683
+
684
+ // Assert config values are used when builder doesn't have them
685
+ $ this ->assertEquals (0.9 , $ mergedConfig ->getTopP ());
686
+ $ this ->assertEquals (40 , $ mergedConfig ->getTopK ());
687
+ }
688
+
689
+ /**
690
+ * Tests usingModelConfig with custom options.
691
+ *
692
+ * @return void
693
+ */
694
+ public function testUsingModelConfigWithCustomOptions (): void
695
+ {
696
+ $ builder = new PromptBuilder ($ this ->registry );
697
+
698
+ // Create a config with custom options
699
+ $ config = new ModelConfig ();
700
+ $ config ->setCustomOption ('stopSequences ' , ['CONFIG_STOP ' ]);
701
+ $ config ->setCustomOption ('otherOption ' , 'value ' );
702
+
703
+ $ builder ->usingModelConfig ($ config );
704
+
705
+ // Get the merged config
706
+ $ reflection = new \ReflectionClass ($ builder );
707
+ $ configProperty = $ reflection ->getProperty ('modelConfig ' );
708
+ $ configProperty ->setAccessible (true );
709
+
710
+ /** @var ModelConfig $mergedConfig */
711
+ $ mergedConfig = $ configProperty ->getValue ($ builder );
712
+ $ customOptions = $ mergedConfig ->getCustomOptions ();
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
+ $ builder ->usingStopSequences ('STOP ' );
723
+
724
+ // Get the config again
725
+ $ mergedConfig = $ configProperty ->getValue ($ builder );
726
+ $ customOptions = $ mergedConfig ->getCustomOptions ();
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
+
645
738
/**
646
739
* Tests usingProvider method.
647
740
*
0 commit comments