Skip to content
Open
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
16 changes: 16 additions & 0 deletions demo/config/packages/ai.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,22 @@ ai:
- 'Symfony\AI\Store\Document\Transformer\TextTrimTransformer'
vectorizer: 'ai.vectorizer.openai'
store: 'ai.store.chroma_db.symfonycon'
message_store:
cache:
audio:
service: 'cache.app'
wikipedia: ~
youtube: ~
chat:
audio:
agent: 'audio'
message_store: 'cache.audio'
wikipedia:
agent: 'wikipedia'
message_store: 'cache.wikipedia'
youtube:
agent: 'youtube'
message_store: 'cache.youtube'
Comment on lines +71 to +86
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we make it more concise here?

Suggested change
message_store:
cache:
audio:
service: 'cache.app'
wikipedia: ~
youtube: ~
chat:
audio:
agent: 'audio'
message_store: 'cache.audio'
wikipedia:
agent: 'wikipedia'
message_store: 'cache.wikipedia'
youtube:
agent: 'youtube'
message_store: 'cache.youtube'
chat:
audio:
agent: 'audio'
type: 'cache'
service: 'cache.app'
wikipedia:
agent: 'wikipedia'
youtube:
agent: 'youtube'


services:
_defaults:
Expand Down
75 changes: 0 additions & 75 deletions demo/src/Audio/Chat.php

This file was deleted.

30 changes: 26 additions & 4 deletions demo/src/Audio/TwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,16 @@

namespace App\Audio;

use Symfony\AI\Agent\AgentInterface;
use Symfony\AI\Agent\Chat\MessageStoreInterface;
use Symfony\AI\Agent\ChatInterface;
use Symfony\AI\Platform\Bridge\OpenAi\Whisper;
use Symfony\AI\Platform\Message\Content\Audio;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageInterface;
use Symfony\AI\Platform\PlatformInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\Component\HttpFoundation\RequestStack;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveAction;
use Symfony\UX\LiveComponent\Attribute\LiveArg;
Expand All @@ -23,7 +32,14 @@ final class TwigComponent
use DefaultActionTrait;

public function __construct(
private readonly Chat $chat,
private readonly PlatformInterface $platform,
private readonly RequestStack $requestStack,
#[Autowire(service: 'ai.agent.audio')]
private readonly AgentInterface $agent,
#[Autowire(service: 'ai.chat.audio')]
private readonly ChatInterface $chat,
#[Autowire(service: 'ai.message_store.cache.audio')]
private readonly MessageStoreInterface $messageStore,
) {
}

Expand All @@ -32,18 +48,24 @@ public function __construct(
*/
public function getMessages(): array
{
return $this->chat->loadMessages()->withoutSystemMessage()->getMessages();
return $this->chat->getCurrentMessageBag()->withoutSystemMessage()->getMessages();
}

#[LiveAction]
public function submit(#[LiveArg] string $audio): void
{
$this->chat->say($audio);
// Convert base64 to temporary binary file
$path = tempnam(sys_get_temp_dir(), 'audio-').'.wav';
file_put_contents($path, base64_decode($audio));

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

$this->chat->submit(Message::ofUser($result->asText()));
}

#[LiveAction]
public function reset(): void
{
$this->chat->reset();
$this->messageStore->clear();
}
}
60 changes: 0 additions & 60 deletions demo/src/Wikipedia/Chat.php

This file was deleted.

15 changes: 11 additions & 4 deletions demo/src/Wikipedia/TwigComponent.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,11 @@

namespace App\Wikipedia;

use Symfony\AI\Agent\Chat\MessageStoreInterface;
use Symfony\AI\Agent\ChatInterface;
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageInterface;
use Symfony\Component\DependencyInjection\Attribute\Autowire;
use Symfony\UX\LiveComponent\Attribute\AsLiveComponent;
use Symfony\UX\LiveComponent\Attribute\LiveAction;
use Symfony\UX\LiveComponent\Attribute\LiveArg;
Expand All @@ -23,7 +27,10 @@ final class TwigComponent
use DefaultActionTrait;

public function __construct(
private readonly Chat $wikipedia,
#[Autowire(service: 'ai.chat.wikipedia')]
private readonly ChatInterface $chat,
#[Autowire(service: 'ai.message_store.cache.wikipedia')]
private readonly MessageStoreInterface $messageStore,
) {
}

Expand All @@ -32,18 +39,18 @@ public function __construct(
*/
public function getMessages(): array
{
return $this->wikipedia->loadMessages()->withoutSystemMessage()->getMessages();
return $this->chat->getCurrentMessageBag()->getMessages();
}

#[LiveAction]
public function submit(#[LiveArg] string $message): void
{
$this->wikipedia->submitMessage($message);
$this->chat->submit(Message::ofUser($message));
}

#[LiveAction]
public function reset(): void
{
$this->wikipedia->reset();
$this->messageStore->clear();
}
}
82 changes: 0 additions & 82 deletions demo/src/YouTube/Chat.php

This file was deleted.

Loading
Loading