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
4 changes: 4 additions & 0 deletions .github/workflows/code-quality.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ jobs:
run: |
cd examples/ && $COMPOSER_UP && ../link && $PHPSTAN

- name: Run PHPStan on demo
run: |
cd demo/ && $COMPOSER_UP && ../link && $PHPSTAN

- name: Run PHPStan on packages
run: |
source .github/workflows/.utils.sh
Expand Down
2 changes: 1 addition & 1 deletion demo/src/Audio/Chat.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public function say(string $base64audio): void
$path = tempnam(sys_get_temp_dir(), 'audio-').'.wav';
file_put_contents($path, base64_decode($base64audio));

$result = $this->platform->invoke(new Whisper(), Audio::fromFile($path));
$result = $this->platform->invoke('whisper-1', Audio::fromFile($path));

$this->submitMessage($result->asText());
}
Expand Down
2 changes: 1 addition & 1 deletion demo/src/Blog/Command/QueryCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function __invoke(SymfonyStyle $io): int

$vector = $this->vectorizer->vectorize($search);
$queryResponse = $collection->query(
queryEmbeddings: [$vector->getData()],
queryEmbeddings: [$vector->getData()], /** @phpstan-ignore-line until https://github.com/symfony/ai/issues/768 */
nResults: 4,
);

Expand Down
3 changes: 3 additions & 0 deletions demo/src/Blog/Command/StreamCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
use Symfony\AI\Agent\AgentInterface;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Platform\Result\StreamResult;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Style\SymfonyStyle;

Expand Down Expand Up @@ -42,6 +43,8 @@ public function __invoke(SymfonyStyle $io): int
$io->section('Agent Response:');
$result = $this->blogAgent->call($messages, ['stream' => true]);

\assert($result instanceof StreamResult);

foreach ($result->getContent() as $word) {
$io->write($word);
}
Expand Down
3 changes: 3 additions & 0 deletions demo/src/Mcp/Prompts/CurrentTimePrompt.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

class CurrentTimePrompt
{
/**
* @return array{role: 'user', content: string}[]
*/
#[McpPrompt(name: 'time-analysis')]
public function getTimeAnalysisPrompt(): array
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

class CurrentTimeResourceTemplate
{
/**
* @return array{uri: string, mimeType: string, text: string}
*/
#[McpResourceTemplate(uriTemplate: 'time://{timezone}', name: 'time-by-timezone')]
public function getTimeByTimezone(string $timezone): array
{
Expand Down
3 changes: 3 additions & 0 deletions demo/src/Mcp/Resources/CurrentTimeResource.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

class CurrentTimeResource
{
/**
* @return array{uri: string, mimeType: string, text: string}
*/
#[McpResource(uri: 'time://current', name: 'current-time-resource')]
public function getCurrentTimeResource(): array
{
Expand Down
2 changes: 1 addition & 1 deletion demo/src/Video/TwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function submit(#[LiveArg] string $instruction, #[LiveArg] string $image)
Message::ofUser($instruction, Image::fromDataUrl($image))
);

$result = $this->platform->invoke(new Gpt(Gpt::GPT_4O_MINI), $messageBag, [
$result = $this->platform->invoke('gpt-4o-mini', $messageBag, [
'max_tokens' => 100,
]);

Expand Down
11 changes: 10 additions & 1 deletion demo/tests/Blog/ChatTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
use PHPUnit\Framework\TestCase;
use Symfony\AI\Agent\MockAgent;
use Symfony\AI\Platform\Message\AssistantMessage;
use Symfony\AI\Platform\Message\Content\Text;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Platform\Message\SystemMessage;
use Symfony\AI\Platform\Message\UserMessage;
Expand Down Expand Up @@ -65,6 +66,7 @@ public function testSubmitMessageAddsUserMessageAndAgentResponse()
// Check user message
$userMessage = $messageList[1];
$this->assertInstanceOf(UserMessage::class, $userMessage);
$this->assertInstanceOf(Text::class, $userMessage->getContent()[0]);
$this->assertSame('What is Symfony?', $userMessage->getContent()[0]->getText());

// Check assistant message
Expand Down Expand Up @@ -169,9 +171,16 @@ public function testAgentReceivesFullConversationHistory()
$this->assertCount(5, $messages);

// Verify the conversation flow (with 5 messages)
$this->assertStringContainsString('helpful assistant', $messages[0]->getContent()); // system
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
$this->assertStringContainsString('helpful assistant', $messages[0]->getContent());
$this->assertInstanceOf(UserMessage::class, $messages[1]);
$this->assertCount(1, $messages[1]->getContent());
$this->assertInstanceOf(Text::class, $messages[1]->getContent()[0]);
$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->assertInstanceOf(UserMessage::class, $messages[3]);
$this->assertCount(1, $messages[3]->getContent());
$this->assertInstanceOf(Text::class, $messages[3]->getContent()[0]);
$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: 2 additions & 0 deletions demo/tests/Blog/Command/StreamCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,12 @@ public function getContent(): iterable

public function getMetadata(): Metadata
{
return new Metadata();
}

public function getRawResult(): ?RawResultInterface
{
return null;
}

public function setRawResult(RawResultInterface $rawResult): void
Expand Down