File tree 3 files changed +20
-4
lines changed
3 files changed +20
-4
lines changed Original file line number Diff line number Diff line change @@ -24,10 +24,10 @@ public function __construct(protected Provider $provider)
24
24
25
25
public function generate (Request $ request ): Response
26
26
{
27
- $ response = $ this ->sendProviderRequest ($ request );
28
-
29
27
$ this ->messages = $ request ->messages ;
30
28
29
+ $ response = $ this ->sendProviderRequest ($ request );
30
+
31
31
$ this ->responseBuilder ->addStep (new Step (
32
32
text: $ response ->text ,
33
33
object: $ this ->decodeObject ($ response ->text ),
Original file line number Diff line number Diff line change @@ -172,7 +172,7 @@ public function toArray(): array
172
172
});
173
173
});
174
174
175
- test ('it adds system message and user message to first step ' , function (): void {
175
+ test ('it adds system message user message and assistant message response to first step ' , function (): void {
176
176
Prism::fake ([
177
177
new ProviderResponse (
178
178
text: json_encode (['I am a string ' ]),
@@ -192,6 +192,7 @@ public function toArray(): array
192
192
$ response = $ request ->generate ();
193
193
194
194
expect ($ response )->toBeInstanceOf (Response::class);
195
+ expect ($ response ->steps [0 ]->messages )->toHaveCount (3 );
195
196
196
197
/** @var SystemMessage */
197
198
$ system_message = $ response ->steps [0 ]->messages [0 ];
@@ -206,4 +207,12 @@ public function toArray(): array
206
207
expect ($ user_message )->toBeInstanceOf (UserMessage::class)
207
208
->and ($ user_message ->text ())
208
209
->toBe ('User Prompt ' );
210
+
211
+ /** @var AssistantMessage */
212
+ $ assistant_message = $ response ->steps [0 ]->messages [2 ];
213
+
214
+ expect ($ assistant_message )->toBeInstanceOf (AssistantMessage::class)
215
+ ->and ($ assistant_message ->content )
216
+ ->toBe (json_encode (['I am a string ' ]));
217
+
209
218
});
Original file line number Diff line number Diff line change 307
307
);
308
308
});
309
309
310
- test ('it adds the system message and user message to first step ' , function (): void {
310
+ test ('it adds the system message user message and assistant response to first step ' , function (): void {
311
311
$ request = (new PendingRequest )
312
312
->using ('test-provider ' , 'test-model ' )
313
313
->withSystemPrompt ('System Prompt ' )
330
330
expect ($ user_message )->toBeInstanceOf (UserMessage::class)
331
331
->and ($ user_message ->text ())
332
332
->toBe ('User Prompt ' );
333
+
334
+ /** @var AssistantMessage */
335
+ $ assistant_message = $ response ->steps [0 ]->messages [2 ];
336
+
337
+ expect ($ assistant_message )->toBeInstanceOf (AssistantMessage::class)
338
+ ->and ($ assistant_message ->content )
339
+ ->toBe ("I'm nyx! " );
333
340
});
You can’t perform that action at this time.
0 commit comments