Skip to content

Commit 03625ae

Browse files
committed
ref
1 parent 601d958 commit 03625ae

File tree

6 files changed

+73
-10
lines changed

6 files changed

+73
-10
lines changed

examples/chat/persistent-chat.php

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
use Symfony\AI\Agent\Agent;
13+
use Symfony\AI\Chat\Bridge\Local\InMemoryStore;
14+
use Symfony\AI\Chat\Chat;
15+
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory;
16+
use Symfony\AI\Platform\Message\Message;
17+
use Symfony\AI\Platform\Message\MessageBag;
18+
19+
require_once dirname(__DIR__).'/bootstrap.php';
20+
21+
$platform = PlatformFactory::create(env('OPENAI_API_KEY'), http_client());
22+
23+
$agent = new Agent($platform, 'gpt-4o-mini', logger: logger());
24+
$chat = new Chat($agent, new InMemoryStore());
25+
26+
$messages = new MessageBag(
27+
Message::forSystem('You are a helpful assistant. You only answer with short sentences.'),
28+
);
29+
30+
$chat->initiate($messages);
31+
$chat->submit(Message::ofUser('My name is Christopher.'));
32+
$message = $chat->submit(Message::ofUser('What is my name?'));
33+
34+
echo $message->content.\PHP_EOL;

examples/misc/persistent-chat-meilisearch.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
* file that was distributed with this source code.
1010
*/
1111

12+
use Bridge\Meilisearch\MessageStore;
1213
use Symfony\AI\Agent\Agent;
13-
use Symfony\AI\Agent\Bridge\Meilisearch\MessageStore;
1414
use Symfony\AI\Agent\Chat;
1515
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
1616
use Symfony\AI\Platform\Bridge\OpenAi\PlatformFactory;

src/agent/src/Bridge/Meilisearch/MessageStore.php renamed to src/chat/src/Bridge/Meilisearch/MessageStore.php

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\AI\Agent\Bridge\Meilisearch;
12+
namespace Symfony\AI\Chat\Bridge\Meilisearch;
1313

14-
use Symfony\AI\Agent\Chat\InitializableMessageStoreInterface;
1514
use Symfony\AI\Agent\Chat\MessageStoreInterface;
1615
use Symfony\AI\Agent\Exception\InvalidArgumentException;
1716
use Symfony\AI\Agent\Exception\LogicException;
17+
use Symfony\AI\Chat\ManagedStoreInterface;
1818
use Symfony\AI\Platform\Message\AssistantMessage;
1919
use Symfony\AI\Platform\Message\Content\Audio;
2020
use Symfony\AI\Platform\Message\Content\ContentInterface;
@@ -24,7 +24,6 @@
2424
use Symfony\AI\Platform\Message\Content\ImageUrl;
2525
use Symfony\AI\Platform\Message\Content\Text;
2626
use Symfony\AI\Platform\Message\MessageBag;
27-
use Symfony\AI\Platform\Message\MessageBagInterface;
2827
use Symfony\AI\Platform\Message\MessageInterface;
2928
use Symfony\AI\Platform\Message\SystemMessage;
3029
use Symfony\AI\Platform\Message\ToolCallMessage;
@@ -35,7 +34,7 @@
3534
/**
3635
* @author Guillaume Loulier <[email protected]>
3736
*/
38-
final readonly class MessageStore implements InitializableMessageStoreInterface, MessageStoreInterface
37+
final readonly class MessageStore implements ManagedStoreInterface, MessageStoreInterface
3938
{
4039
public function __construct(
4140
private HttpClientInterface $httpClient,
@@ -45,7 +44,7 @@ public function __construct(
4544
) {
4645
}
4746

48-
public function save(MessageBagInterface $messages): void
47+
public function save(MessageBag $messages): void
4948
{
5049
$messages = $messages->getMessages();
5150

@@ -55,7 +54,7 @@ public function save(MessageBagInterface $messages): void
5554
));
5655
}
5756

58-
public function load(): MessageBagInterface
57+
public function load(): MessageBag
5958
{
6059
$messages = $this->request('POST', \sprintf('indexes/%s/documents/fetch', $this->indexName));
6160

@@ -67,7 +66,7 @@ public function clear(): void
6766
$this->request('DELETE', \sprintf('indexes/%s/documents', $this->indexName));
6867
}
6968

70-
public function initialize(array $options = []): void
69+
public function setup(array $options = []): void
7170
{
7271
if ([] !== $options) {
7372
throw new InvalidArgumentException('No supported options.');
@@ -79,6 +78,11 @@ public function initialize(array $options = []): void
7978
]);
8079
}
8180

81+
public function drop(): void
82+
{
83+
$this->request('DELETE', \sprintf('indexes/%s', $this->indexName));
84+
}
85+
8286
/**
8387
* @param array<string, mixed>|list<array<string, mixed>> $payload
8488
*

src/chat/src/InitializableMessageStoreInterface.php

Whitespace-only changes.
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <[email protected]>
7+
*
8+
* For the full copyright and license information, please view the LICENSE
9+
* file that was distributed with this source code.
10+
*/
11+
12+
namespace Symfony\AI\Chat;
13+
14+
/**
15+
* @author Guillaume Loulier <[email protected]>
16+
*/
17+
interface ManagedStoreInterface
18+
{
19+
/**
20+
* @param array<mixed> $options
21+
*/
22+
public function setup(array $options = []): void;
23+
24+
public function drop(): void;
25+
}

src/agent/tests/Bridge/Meilisearch/MessageStoreTest.php renamed to src/chat/tests/Bridge/Meilisearch/MessageStoreTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
* file that was distributed with this source code.
1010
*/
1111

12-
namespace Symfony\AI\Agent\Tests\Bridge\Meilisearch;
12+
namespace Symfony\AI\Chat\Tests\Bridge\Meilisearch;
1313

1414
use PHPUnit\Framework\Attributes\CoversClass;
1515
use PHPUnit\Framework\Attributes\DataProvider;
1616
use PHPUnit\Framework\TestCase;
17-
use Symfony\AI\Agent\Bridge\Meilisearch\MessageStore;
17+
use Symfony\AI\Chat\Bridge\Meilisearch\MessageStore;
1818
use Symfony\AI\Platform\Message\AssistantMessage;
1919
use Symfony\AI\Platform\Message\Content\Text;
2020
use Symfony\AI\Platform\Message\Message;

0 commit comments

Comments
 (0)