Skip to content

Commit d7ad010

Browse files
authored
fix: text generator message steps (#154)
1 parent cd4c230 commit d7ad010

File tree

3 files changed

+20
-4
lines changed

3 files changed

+20
-4
lines changed

Diff for: src/Structured/Generator.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,10 @@ public function __construct(protected Provider $provider)
2424

2525
public function generate(Request $request): Response
2626
{
27-
$response = $this->sendProviderRequest($request);
28-
2927
$this->messages = $request->messages;
3028

29+
$response = $this->sendProviderRequest($request);
30+
3131
$this->responseBuilder->addStep(new Step(
3232
text: $response->text,
3333
object: $this->decodeObject($response->text),

Diff for: tests/Structured/GeneratorTest.php

+10-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ public function toArray(): array
172172
});
173173
});
174174

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 {
176176
Prism::fake([
177177
new ProviderResponse(
178178
text: json_encode(['I am a string']),
@@ -192,6 +192,7 @@ public function toArray(): array
192192
$response = $request->generate();
193193

194194
expect($response)->toBeInstanceOf(Response::class);
195+
expect($response->steps[0]->messages)->toHaveCount(3);
195196

196197
/** @var SystemMessage */
197198
$system_message = $response->steps[0]->messages[0];
@@ -206,4 +207,12 @@ public function toArray(): array
206207
expect($user_message)->toBeInstanceOf(UserMessage::class)
207208
->and($user_message->text())
208209
->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+
209218
});

Diff for: tests/Text/GeneratorTest.php

+8-1
Original file line numberDiff line numberDiff line change
@@ -307,7 +307,7 @@
307307
);
308308
});
309309

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 {
311311
$request = (new PendingRequest)
312312
->using('test-provider', 'test-model')
313313
->withSystemPrompt('System Prompt')
@@ -330,4 +330,11 @@
330330
expect($user_message)->toBeInstanceOf(UserMessage::class)
331331
->and($user_message->text())
332332
->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!");
333340
});

0 commit comments

Comments
 (0)