Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions demo/tests/Blog/ChatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ public function testLoadMessagesReturnsDefaultSystemMessage()

$systemMessage = $messages->getMessages()[0];
$this->assertInstanceOf(SystemMessage::class, $systemMessage);
$this->assertStringContainsString('helpful assistant', $systemMessage->content);
$this->assertStringContainsString('similarity_search', $systemMessage->content);
$this->assertStringContainsString('helpful assistant', $systemMessage->getContent());
$this->assertStringContainsString('similarity_search', $systemMessage->getContent());
}

public function testSubmitMessageAddsUserMessageAndAgentResponse()
Expand All @@ -65,12 +65,12 @@ public function testSubmitMessageAddsUserMessageAndAgentResponse()
// Check user message
$userMessage = $messageList[1];
$this->assertInstanceOf(UserMessage::class, $userMessage);
$this->assertSame('What is Symfony?', $userMessage->content[0]->text);
$this->assertSame('What is Symfony?', $userMessage->getContent()[0]->getText());

// Check assistant message
$assistantMessage = $messageList[2];
$this->assertInstanceOf(AssistantMessage::class, $assistantMessage);
$this->assertSame('Symfony is a PHP web framework for building web applications and APIs.', $assistantMessage->content);
$this->assertSame('Symfony is a PHP web framework for building web applications and APIs.', $assistantMessage->getContent());
}

public function testSubmitMessageWithUnknownQueryUsesDefaultResponse()
Expand All @@ -91,7 +91,7 @@ public function testSubmitMessageWithUnknownQueryUsesDefaultResponse()

// Check assistant used default response
$assistantMessage = $messageList[2];
$this->assertSame('I can help you with Symfony-related questions!', $assistantMessage->content);
$this->assertSame('I can help you with Symfony-related questions!', $assistantMessage->getContent());
}

public function testMultipleMessagesAreTrackedCorrectly()
Expand Down Expand Up @@ -169,10 +169,10 @@ public function testAgentReceivesFullConversationHistory()
$this->assertCount(5, $messages);

// Verify the conversation flow (with 5 messages)
$this->assertStringContainsString('helpful assistant', $messages[0]->content); // system
$this->assertSame('What is Symfony?', $messages[1]->content[0]->text); // user1
$this->assertSame('Symfony is a PHP web framework for building web applications and APIs.', $messages[2]->content); // assistant1
$this->assertSame('Tell me more', $messages[3]->content[0]->text); // user2
$this->assertStringContainsString('helpful assistant', $messages[0]->getContent()); // system
$this->assertSame('What is Symfony?', $messages[1]->getContent()[0]->getText()); // user1
$this->assertSame('Symfony is a PHP web framework for building web applications and APIs.', $messages[2]->getContent()); // assistant1
$this->assertSame('Tell me more', $messages[3]->getContent()[0]->getText()); // user2
// The 5th message appears to be the previous assistant response or another system message
}

Expand Down
2 changes: 1 addition & 1 deletion examples/chat/persistent-chat-cache.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,4 @@
$chat->submit(Message::ofUser('My name is Christopher.'));
$message = $chat->submit(Message::ofUser('What is my name?'));

echo $message->content.\PHP_EOL;
echo $message->getContent().\PHP_EOL;
2 changes: 1 addition & 1 deletion examples/chat/persistent-chat-session.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,4 @@
$chat->submit(Message::ofUser('My name is Christopher.'));
$message = $chat->submit(Message::ofUser('What is my name?'));

echo $message->content.\PHP_EOL;
echo $message->getContent().\PHP_EOL;
2 changes: 1 addition & 1 deletion examples/chat/persistent-chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@
$chat->submit(Message::ofUser('My name is Christopher.'));
$message = $chat->submit(Message::ofUser('What is my name?'));

echo $message->content.\PHP_EOL;
echo $message->getContent().\PHP_EOL;
4 changes: 2 additions & 2 deletions src/agent/src/Memory/EmbeddingProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public function load(Input $input): array
}

$userMessageTextContent = array_filter(
$userMessage->content,
$userMessage->getContent(),
static fn (ContentInterface $content): bool => $content instanceof Text,
);

Expand All @@ -53,7 +53,7 @@ public function load(Input $input): array

$userMessageTextContent = array_shift($userMessageTextContent);

$vectors = $this->platform->invoke($this->model->getName(), $userMessageTextContent->text)->asVectors();
$vectors = $this->platform->invoke($this->model->getName(), $userMessageTextContent->getText())->asVectors();
$foundEmbeddingContent = $this->vectorStore->query($vectors[0]);
if (0 === \count($foundEmbeddingContent)) {
return [];
Expand Down
2 changes: 1 addition & 1 deletion src/agent/src/Memory/MemoryInputProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ public function processInput(Input $input): void
return;
}

$systemMessage = $input->getMessageBag()->getSystemMessage()->content ?? '';
$systemMessage = $input->getMessageBag()->getSystemMessage()?->getContent() ?? '';

$combinedMessage = self::MEMORY_PROMPT_MESSAGE.$memory;
if ('' !== $systemMessage) {
Expand Down
4 changes: 2 additions & 2 deletions src/agent/src/MockAgent.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,9 @@ public function call(MessageBag $messages, array $options = []): ResultInterface
$content = '';

if ($lastMessage instanceof UserMessage) {
foreach ($lastMessage->content as $messageContent) {
foreach ($lastMessage->getContent() as $messageContent) {
if ($messageContent instanceof Text) {
$content .= $messageContent->text;
$content .= $messageContent->getText();
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/agent/src/Toolbox/AgentProcessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private function handleToolCallsCallback(Output $output): \Closure
return function (ToolCallResult $result, ?AssistantMessage $streamedAssistantResponse = null) use ($output): ResultInterface {
$messages = $this->keepToolMessages ? $output->getMessageBag() : clone $output->getMessageBag();

if (null !== $streamedAssistantResponse && '' !== $streamedAssistantResponse->content) {
if (null !== $streamedAssistantResponse && '' !== $streamedAssistantResponse->getContent()) {
$messages->add($streamedAssistantResponse);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public function testProcessInputAddsSystemMessageWhenNoneExists()
$this->assertCount(2, $messages);
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
$this->assertInstanceOf(UserMessage::class, $messages[1]);
$this->assertSame('This is a system prompt', $messages[0]->content);
$this->assertSame('This is a system prompt', $messages[0]->getContent());
}

public function testProcessInputDoesNotAddSystemMessageWhenOneExists()
Expand All @@ -59,7 +59,7 @@ public function testProcessInputDoesNotAddSystemMessageWhenOneExists()
$this->assertCount(2, $messages);
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
$this->assertInstanceOf(UserMessage::class, $messages[1]);
$this->assertSame('This is already a system prompt', $messages[0]->content);
$this->assertSame('This is already a system prompt', $messages[0]->getContent());
}

public function testDoesNotIncludeToolsIfToolboxIsEmpty()
Expand All @@ -86,7 +86,7 @@ public function execute(ToolCall $toolCall): mixed
$this->assertCount(2, $messages);
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
$this->assertInstanceOf(UserMessage::class, $messages[1]);
$this->assertSame('This is a system prompt', $messages[0]->content);
$this->assertSame('This is a system prompt', $messages[0]->getContent());
}

public function testIncludeToolDefinitions()
Expand Down Expand Up @@ -138,7 +138,7 @@ public function execute(ToolCall $toolCall): mixed
## tool_required_params
A tool with required parameters
or not
PROMPT, $messages[0]->content);
PROMPT, $messages[0]->getContent());
}

public function testWithStringableSystemPrompt()
Expand Down Expand Up @@ -176,7 +176,7 @@ public function execute(ToolCall $toolCall): mixed

## tool_no_params
A tool without parameters
PROMPT, $messages[0]->content);
PROMPT, $messages[0]->getContent());
}

public function testWithTranslatedSystemPrompt()
Expand All @@ -190,7 +190,7 @@ public function testWithTranslatedSystemPrompt()
$this->assertCount(2, $messages);
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
$this->assertInstanceOf(UserMessage::class, $messages[1]);
$this->assertSame('This is a cool translated system prompt', $messages[0]->content);
$this->assertSame('This is a cool translated system prompt', $messages[0]->getContent());
}

public function testWithTranslationDomainSystemPrompt()
Expand All @@ -207,7 +207,7 @@ public function testWithTranslationDomainSystemPrompt()
$messages = $input->getMessageBag()->getMessages();
$this->assertCount(1, $messages);
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
$this->assertSame('This is a cool translated system prompt with a translation domain', $messages[0]->content);
$this->assertSame('This is a cool translated system prompt with a translation domain', $messages[0]->getContent());
}

public function testWithMissingTranslator()
Expand Down Expand Up @@ -237,7 +237,7 @@ public function testProcessInputWithFile()
$this->assertCount(2, $messages);
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
$this->assertInstanceOf(UserMessage::class, $messages[1]);
$this->assertSame('This is a system prompt from a file', $messages[0]->content);
$this->assertSame('This is a system prompt from a file', $messages[0]->getContent());
} finally {
unlink($tempFile);
}
Expand All @@ -258,7 +258,7 @@ public function testProcessInputWithMultilineFile()
$messages = $input->getMessageBag()->getMessages();
$this->assertCount(2, $messages);
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
$this->assertSame("Line 1\nLine 2\nLine 3", $messages[0]->content);
$this->assertSame("Line 1\nLine 2\nLine 3", $messages[0]->getContent());
} finally {
unlink($tempFile);
}
Expand Down
8 changes: 4 additions & 4 deletions src/agent/tests/Memory/MemoryInputProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function testItIsAddingMemoryToSystemPrompt()

You are a helpful and kind assistant.
MARKDOWN,
$input->getMessageBag()->getSystemMessage()->content,
$input->getMessageBag()->getSystemMessage()->getContent(),
);
}

Expand All @@ -108,7 +108,7 @@ public function testItIsAddingMemoryToSystemPromptEvenItIsEmpty()

First memory content
MARKDOWN,
$input->getMessageBag()->getSystemMessage()->content,
$input->getMessageBag()->getSystemMessage()->getContent(),
);
}

Expand All @@ -135,7 +135,7 @@ public function testItIsAddingMultipleMemoryFromSingleProviderToSystemPrompt()
First memory content
Second memory content
MARKDOWN,
$input->getMessageBag()->getSystemMessage()->content,
$input->getMessageBag()->getSystemMessage()->getContent(),
);
}

Expand All @@ -151,6 +151,6 @@ public function testItIsNotAddingAnythingIfMemoryWasEmpty()
$memoryInputProcessor->processInput($input = new Input('gpt-4', new MessageBag(), []));

$this->assertArrayNotHasKey('use_memory', $input->getOptions());
$this->assertNull($input->getMessageBag()->getSystemMessage()?->content);
$this->assertNull($input->getMessageBag()->getSystemMessage()?->getContent());
}
}
2 changes: 1 addition & 1 deletion src/ai-bundle/src/Command/AgentCallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int

if (!$systemPromptDisplayed && null !== ($systemMessage = $messages->getSystemMessage())) {
$io->section('System Prompt');
$io->block($systemMessage->content, null, 'fg=gray', ' ', true);
$io->block($systemMessage->getContent(), null, 'fg=gray', ' ', true);
$systemPromptDisplayed = true;
}

Expand Down
3 changes: 2 additions & 1 deletion src/chat/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@
],
"require": {
"php": ">=8.2",
"symfony/ai-agent": "@dev"
"symfony/ai-agent": "@dev",
"symfony/ai-platform": "@dev"
},
"require-dev": {
"phpstan/phpstan": "^2.0",
Expand Down
4 changes: 2 additions & 2 deletions src/chat/tests/Bridge/Local/InMemoryStoreTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ public function testLoadReturnsStoredMessages()
$this->assertCount(1, $loadedMessages);
$messages = $loadedMessages->getMessages();
$this->assertInstanceOf(UserMessage::class, $messages[0]);
$this->assertInstanceOf(Text::class, $messages[0]->content[0]);
$this->assertSame('Test message', $messages[0]->content[0]->text);
$this->assertInstanceOf(Text::class, $messages[0]->getContent()[0]);
$this->assertSame('Test message', $messages[0]->getContent()[0]->getText());
}

public function testDropClearsMessages()
Expand Down
6 changes: 3 additions & 3 deletions src/chat/tests/ChatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public function testItSubmitsUserMessageAndReturnsAssistantMessage()
$result = $this->chat->submit($userMessage);

$this->assertInstanceOf(AssistantMessage::class, $result);
$this->assertSame($assistantContent, $result->content);
$this->assertSame($assistantContent, $result->getContent());
$this->assertCount(2, $this->store->load());
}

Expand All @@ -87,7 +87,7 @@ public function testItAppendsMessagesToExistingConversation()
$result = $this->chat->submit($newUserMessage);

$this->assertInstanceOf(AssistantMessage::class, $result);
$this->assertSame($newAssistantContent, $result->content);
$this->assertSame($newAssistantContent, $result->getContent());
$this->assertCount(2, $this->store->load());
}

Expand All @@ -110,7 +110,7 @@ public function testItHandlesEmptyMessageStore()
$result = $this->chat->submit($userMessage);

$this->assertInstanceOf(AssistantMessage::class, $result);
$this->assertSame($assistantContent, $result->content);
$this->assertSame($assistantContent, $result->getContent());
$this->assertCount(2, $this->store->load());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
'name' => $toolCall->getName(),
'input' => [] !== $toolCall->getArguments() ? $toolCall->getArguments() : new \stdClass(),
];
}, $data->toolCalls) : $data->content,
}, $data->getToolCalls()) : $data->getContent(),
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
'type' => 'document',
'source' => [
'type' => 'url',
'url' => $data->url,
'url' => $data->getUrl(),
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
'type' => 'image',
'source' => [
'type' => 'url',
'url' => $data->url,
'url' => $data->getUrl(),
],
];
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
];

if (null !== $system = $data->getSystemMessage()) {
$array['system'] = $system->content;
$array['system'] = $system->getContent();
}

if (isset($context[Contract::CONTEXT_MODEL]) && $context[Contract::CONTEXT_MODEL] instanceof Model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ public function normalize(mixed $data, ?string $format = null, array $context =
'content' => [
[
'type' => 'tool_result',
'tool_use_id' => $data->toolCall->getId(),
'content' => $data->content,
'tool_use_id' => $data->getToolCall()->getId(),
'content' => $data->getContent(),
],
],
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@ public function normalize(mixed $data, ?string $format = null, array $context =
'input' => [] !== $toolCall->getArguments() ? $toolCall->getArguments() : new \stdClass(),
],
];
}, $data->toolCalls),
}, $data->getToolCalls()),
];
}

return [
'role' => 'assistant',
'content' => [['text' => $data->content]],
'content' => [['text' => $data->getContent()]],
];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public function normalize(mixed $data, ?string $format = null, array $context =
$array = [];

if ($data->getSystemMessage()) {
$array['system'][]['text'] = $data->getSystemMessage()->content;
$array['system'][]['text'] = $data->getSystemMessage()->getContent();
}

$array['messages'] = $this->normalizer->normalize($data->withoutSystemMessage()->getMessages(), $format, $context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ public function normalize(mixed $data, ?string $format = null, array $context =
'content' => [
[
'toolResult' => [
'toolUseId' => $data->toolCall->getId(),
'content' => [['json' => $data->content]],
'toolUseId' => $data->getToolCall()->getId(),
'content' => [['json' => $data->getContent()]],
],
],
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,10 @@ public function normalize(mixed $data, ?string $format = null, array $context =
{
$array = ['role' => $data->getRole()->value];

foreach ($data->content as $value) {
foreach ($data->getContent() as $value) {
$contentPart = [];
if ($value instanceof Text) {
$contentPart['text'] = $value->text;
$contentPart['text'] = $value->getText();
} elseif ($value instanceof Image) {
$contentPart['image']['format'] = u($value->getFormat())->replace('image/', '')->replace('jpg', 'jpeg')->toString();
$contentPart['image']['source']['bytes'] = $value->asBase64();
Expand Down
Loading