Skip to content

Commit e3dd224

Browse files
committed
Fix demo by PHPStan findings + pipeline
1 parent a4747cb commit e3dd224

File tree

9 files changed

+30
-3
lines changed

9 files changed

+30
-3
lines changed

.github/workflows/code-quality.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,10 @@ jobs:
6464
run: |
6565
cd examples/ && $COMPOSER_UP && ../link && $PHPSTAN
6666
67+
- name: Run PHPStan on demo
68+
run: |
69+
cd demo/ && $COMPOSER_UP && ../link && $PHPSTAN
70+
6771
- name: Run PHPStan on packages
6872
run: |
6973
source .github/workflows/.utils.sh

demo/src/Audio/Chat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public function say(string $base64audio): void
3939
$path = tempnam(sys_get_temp_dir(), 'audio-').'.wav';
4040
file_put_contents($path, base64_decode($base64audio));
4141

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

4444
$this->submitMessage($result->asText());
4545
}

demo/src/Blog/Command/StreamCommand.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\AI\Agent\AgentInterface;
1515
use Symfony\AI\Platform\Message\Message;
1616
use Symfony\AI\Platform\Message\MessageBag;
17+
use Symfony\AI\Platform\Result\StreamResult;
1718
use Symfony\Component\Console\Attribute\AsCommand;
1819
use Symfony\Component\Console\Style\SymfonyStyle;
1920

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

46+
\assert($result instanceof StreamResult);
47+
4548
foreach ($result->getContent() as $word) {
4649
$io->write($word);
4750
}

demo/src/Mcp/Prompts/CurrentTimePrompt.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
class CurrentTimePrompt
1717
{
18+
/**
19+
* @return array{role: 'user', content: string}[]
20+
*/
1821
#[McpPrompt(name: 'time-analysis')]
1922
public function getTimeAnalysisPrompt(): array
2023
{

demo/src/Mcp/ResourceTemplates/CurrentTimeResourceTemplate.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
class CurrentTimeResourceTemplate
1717
{
18+
/**
19+
* @return array{uri: string, mimeType: string, text: string}
20+
*/
1821
#[McpResourceTemplate(uriTemplate: 'time://{timezone}', name: 'time-by-timezone')]
1922
public function getTimeByTimezone(string $timezone): array
2023
{

demo/src/Mcp/Resources/CurrentTimeResource.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@
1515

1616
class CurrentTimeResource
1717
{
18+
/**
19+
* @return array{uri: string, mimeType: string, text: string}
20+
*/
1821
#[McpResource(uri: 'time://current', name: 'current-time-resource')]
1922
public function getCurrentTimeResource(): array
2023
{

demo/src/Video/TwigComponent.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public function submit(#[LiveArg] string $instruction, #[LiveArg] string $image)
4747
Message::ofUser($instruction, Image::fromDataUrl($image))
4848
);
4949

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

demo/tests/Blog/ChatTest.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
use PHPUnit\Framework\TestCase;
1616
use Symfony\AI\Agent\MockAgent;
1717
use Symfony\AI\Platform\Message\AssistantMessage;
18+
use Symfony\AI\Platform\Message\Content\Text;
1819
use Symfony\AI\Platform\Message\MessageBag;
1920
use Symfony\AI\Platform\Message\SystemMessage;
2021
use Symfony\AI\Platform\Message\UserMessage;
@@ -65,6 +66,7 @@ public function testSubmitMessageAddsUserMessageAndAgentResponse()
6566
// Check user message
6667
$userMessage = $messageList[1];
6768
$this->assertInstanceOf(UserMessage::class, $userMessage);
69+
$this->assertInstanceOf(Text::class, $userMessage->getContent()[0]);
6870
$this->assertSame('What is Symfony?', $userMessage->getContent()[0]->getText());
6971

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

171173
// Verify the conversation flow (with 5 messages)
172-
$this->assertStringContainsString('helpful assistant', $messages[0]->getContent()); // system
174+
$this->assertInstanceOf(SystemMessage::class, $messages[0]);
175+
$this->assertStringContainsString('helpful assistant', $messages[0]->getContent());
176+
$this->assertInstanceOf(UserMessage::class, $messages[1]);
177+
$this->assertCount(1, $messages[1]->getContent());
178+
$this->assertInstanceOf(Text::class, $messages[1]->getContent()[0]);
173179
$this->assertSame('What is Symfony?', $messages[1]->getContent()[0]->getText()); // user1
174180
$this->assertSame('Symfony is a PHP web framework for building web applications and APIs.', $messages[2]->getContent()); // assistant1
181+
$this->assertInstanceOf(UserMessage::class, $messages[3]);
182+
$this->assertCount(1, $messages[3]->getContent());
183+
$this->assertInstanceOf(Text::class, $messages[3]->getContent()[0]);
175184
$this->assertSame('Tell me more', $messages[3]->getContent()[0]->getText()); // user2
176185
// The 5th message appears to be the previous assistant response or another system message
177186
}

demo/tests/Blog/Command/StreamCommandTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,12 @@ public function getContent(): iterable
4141

4242
public function getMetadata(): Metadata
4343
{
44+
return new Metadata();
4445
}
4546

4647
public function getRawResult(): ?RawResultInterface
4748
{
49+
return null;
4850
}
4951

5052
public function setRawResult(RawResultInterface $rawResult): void

0 commit comments

Comments
 (0)