Skip to content

Commit b618197

Browse files
committed
tweaks
1 parent aa58144 commit b618197

File tree

3 files changed

+17
-8
lines changed

3 files changed

+17
-8
lines changed

src/LLM/Drivers/OpenAIChat.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,9 @@ protected function mapResponse(CreateResponse $response): ChatResult
115115
->map(function (CreateResponseChoice $choice) use ($toolCalls, $finishReason, $usage, $response): ChatGeneration {
116116
$generation = new ChatGeneration(
117117
message: new AssistantMessage(
118-
content: $choice->message->content,
118+
content: [
119+
new TextContent($choice->message->content),
120+
],
119121
toolCalls: $toolCalls,
120122
metadata: new ResponseMetadata(
121123
id: $response->id,

tests/Unit/LLM/Drivers/OpenAIChatTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
use Cortex\LLM\Data\Messages\UserMessage;
2020
use Cortex\Tasks\Enums\StructuredOutputMode;
2121
use Cortex\LLM\Data\Messages\AssistantMessage;
22+
use Cortex\LLM\Data\Messages\Content\TextContent;
2223
use OpenAI\Responses\Chat\CreateResponse as ChatCreateResponse;
2324
use OpenAI\Responses\Chat\CreateStreamedResponse as ChatCreateStreamedResponse;
2425

@@ -44,7 +45,7 @@
4445
->and($result->rawResponse)->toBeArray()->not->toBeEmpty()
4546
->and($result->generations)->toHaveCount(1)
4647
->and($result->generation->message)->toBeInstanceOf(AssistantMessage::class)
47-
->and($result->generation->message->content)->toBe('I am doing well, thank you for asking!');
48+
->and($result->generation->message->text())->toBe('I am doing well, thank you for asking!');
4849
});
4950

5051
test('it can stream', function (): void {
@@ -152,8 +153,11 @@
152153
new UserMessage('Tell me about a person'),
153154
]);
154155

155-
expect($result->generation->message->content)
156-
->toBe('{"name":"John Doe","age":30}');
156+
expect($result->generation->message->text())
157+
->toBe('{"name":"John Doe","age":30}')
158+
->and($result->generation->message->content())
159+
->toBeArray()
160+
->toContainOnlyInstancesOf(TextContent::class);
157161

158162
expect($result->generation->parsedOutput)->toBe([
159163
'name' => 'John Doe',
@@ -373,8 +377,11 @@ enum Sentiment: string
373377
new UserMessage('Tell me a joke'),
374378
]);
375379

376-
expect($result->generation->message->content)
377-
->toBe('{"setup":"Why did the scarecrow win an award?","punchline":"Because he was outstanding in his field!"}');
380+
expect($result->generation->message->text())
381+
->toBe('{"setup":"Why did the scarecrow win an award?","punchline":"Because he was outstanding in his field!"}')
382+
->and($result->generation->message->content())
383+
->toBeArray()
384+
->toContainOnlyInstancesOf(TextContent::class);
378385
});
379386

380387
test('it can set temperature and max tokens', function (): void {

tests/Unit/Prompts/Templates/ChatPromptTemplateTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333

3434
expect($messages)->toBeInstanceOf(MessageCollection::class);
3535
expect($messages)->toHaveCount(1);
36-
expect($messages[0]->content())->toBe('Hello, my name is John!');
36+
expect($messages[0]->text())->toBe('Hello, my name is John!');
3737
});
3838

3939
test('it can format a chat prompt template with multiple variables and messages', function (): void {
@@ -190,7 +190,7 @@
190190
]);
191191

192192
expect($result)->toBeInstanceOf(ChatResult::class);
193-
expect($result->generation->message->content)->toBe("Hello John! It's nice to meet you.");
193+
expect($result->generation->message->text())->toBe("Hello John! It's nice to meet you.");
194194

195195
/** @var \OpenAI\Testing\ClientFake $client */
196196
$client = $llm->getClient();

0 commit comments

Comments
 (0)