@@ -47,20 +47,31 @@ public function __construct(
4747 */
4848 public function call (MessageBag $ messages , array $ options = []): ResponseInterface
4949 {
50- $ input = new Input ($ this ->llm , $ messages , $ options );
50+ $ llm = $ this ->llm ;
51+
52+ if (array_key_exists ('llm ' , $ options )) {
53+ if (!$ options ['llm ' ] instanceof LanguageModel) {
54+ throw new InvalidArgumentException (sprintf ('Option "llm" must be an instance of %s. ' , LanguageModel::class));
55+ }
56+
57+ $ llm = $ options ['llm ' ];
58+ unset($ options ['llm ' ]);
59+ }
60+
61+ $ input = new Input ($ llm , $ messages , $ options );
5162 array_map (fn (InputProcessor $ processor ) => $ processor ->processInput ($ input ), $ this ->inputProcessor );
5263
53- if ($ messages ->containsImage () && !$ this -> llm ->supportsImageInput ()) {
54- throw MissingModelSupport::forImageInput ($ this -> llm ::class);
64+ if ($ messages ->containsImage () && !$ llm ->supportsImageInput ()) {
65+ throw MissingModelSupport::forImageInput ($ llm ::class);
5566 }
5667
57- $ response = $ this ->platform ->request ($ this -> llm , $ messages , $ options = $ input ->getOptions ());
68+ $ response = $ this ->platform ->request ($ llm , $ messages , $ options = $ input ->getOptions ());
5869
5970 if ($ response instanceof AsyncResponse) {
6071 $ response = $ response ->unwrap ();
6172 }
6273
63- $ output = new Output ($ this -> llm , $ response , $ messages , $ options );
74+ $ output = new Output ($ llm , $ response , $ messages , $ options );
6475 array_map (fn (OutputProcessor $ processor ) => $ processor ->processOutput ($ output ), $ this ->outputProcessor );
6576
6677 return $ output ->response ;
0 commit comments