Skip to content

Commit 8584c5f

Browse files
committed
Rework Platform API to invoke and result
1 parent c0266db commit 8584c5f

File tree

295 files changed

+1637
-1645
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

295 files changed

+1637
-1645
lines changed

demo/src/Audio/Chat.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
use Symfony\AI\Platform\Message\Message;
1818
use Symfony\AI\Platform\Message\MessageBag;
1919
use Symfony\AI\Platform\PlatformInterface;
20-
use Symfony\AI\Platform\Response\TextResponse;
20+
use Symfony\AI\Platform\Result\TextResult;
2121
use Symfony\Component\DependencyInjection\Attribute\Autowire;
2222
use Symfony\Component\HttpFoundation\RequestStack;
2323

@@ -39,9 +39,9 @@ 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-
$response = $this->platform->request(new Whisper(), Audio::fromFile($path));
42+
$result = $this->platform->invoke(new Whisper(), Audio::fromFile($path));
4343

44-
$this->submitMessage($response->asText());
44+
$this->submitMessage($result->asText());
4545
}
4646

4747
public function loadMessages(): MessageBag
@@ -54,11 +54,11 @@ public function submitMessage(string $message): void
5454
$messages = $this->loadMessages();
5555

5656
$messages->add(Message::ofUser($message));
57-
$response = $this->agent->call($messages);
57+
$result = $this->agent->call($messages);
5858

59-
\assert($response instanceof TextResponse);
59+
\assert($result instanceof TextResult);
6060

61-
$messages->add(Message::ofAssistant($response->getContent()));
61+
$messages->add(Message::ofAssistant($result->getContent()));
6262

6363
$this->saveMessages($messages);
6464
}

demo/src/Blog/Chat.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +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\Response\TextResponse;
17+
use Symfony\AI\Platform\Result\TextResult;
1818
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1919
use Symfony\Component\HttpFoundation\RequestStack;
2020

@@ -49,11 +49,11 @@ public function submitMessage(string $message): void
4949
$messages = $this->loadMessages();
5050

5151
$messages->add(Message::ofUser($message));
52-
$response = $this->agent->call($messages);
52+
$result = $this->agent->call($messages);
5353

54-
\assert($response instanceof TextResponse);
54+
\assert($result instanceof TextResult);
5555

56-
$messages->add(Message::ofAssistant($response->getContent()));
56+
$messages->add(Message::ofAssistant($result->getContent()));
5757

5858
$this->saveMessages($messages);
5959
}

demo/src/Blog/Command/QueryCommand.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
4848
$io->comment(\sprintf('Converting "%s" to vector & searching in Chroma DB ...', $search));
4949
$io->comment('Results are limited to 4 most similar documents.');
5050

51-
$platformResponse = $this->platform->request(new Embeddings(), $search);
51+
$platformResponse = $this->platform->invoke(new Embeddings(), $search);
5252
$queryResponse = $collection->query(
5353
queryEmbeddings: [$platformResponse->asVectors()[0]->getData()],
5454
nResults: 4,

demo/src/Blog/FeedLoader.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,10 @@ public function __construct(
2727
*/
2828
public function load(): array
2929
{
30-
$response = $this->httpClient->request('GET', 'https://feeds.feedburner.com/symfony/blog');
30+
$result = $this->httpClient->request('GET', 'https://feeds.feedburner.com/symfony/blog');
3131

3232
$posts = [];
33-
$crawler = new Crawler($response->getContent());
33+
$crawler = new Crawler($result->getContent());
3434
$crawler->filter('item')->each(function (Crawler $node) use (&$posts) {
3535
$title = $node->filter('title')->text();
3636
$posts[] = new Post(

demo/src/Video/TwigComponent.php

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

50-
$response = $this->platform->request(new GPT(GPT::GPT_4O_MINI), $messageBag, [
50+
$result = $this->platform->invoke(new GPT(GPT::GPT_4O_MINI), $messageBag, [
5151
'max_tokens' => 100,
5252
]);
5353

54-
$this->caption = $response->asText();
54+
$this->caption = $result->asText();
5555
}
5656
}

demo/src/Wikipedia/Chat.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +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\Response\TextResponse;
17+
use Symfony\AI\Platform\Result\TextResult;
1818
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1919
use Symfony\Component\HttpFoundation\RequestStack;
2020

@@ -39,11 +39,11 @@ public function submitMessage(string $message): void
3939
$messages = $this->loadMessages();
4040

4141
$messages->add(Message::ofUser($message));
42-
$response = $this->agent->call($messages);
42+
$result = $this->agent->call($messages);
4343

44-
\assert($response instanceof TextResponse);
44+
\assert($result instanceof TextResult);
4545

46-
$messages->add(Message::ofAssistant($response->getContent()));
46+
$messages->add(Message::ofAssistant($result->getContent()));
4747

4848
$this->saveMessages($messages);
4949
}

demo/src/YouTube/Chat.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +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\Response\TextResponse;
17+
use Symfony\AI\Platform\Result\TextResult;
1818
use Symfony\Component\DependencyInjection\Attribute\Autowire;
1919
use Symfony\Component\HttpFoundation\RequestStack;
2020

@@ -61,11 +61,11 @@ public function submitMessage(string $message): void
6161
$messages = $this->loadMessages();
6262

6363
$messages->add(Message::ofUser($message));
64-
$response = $this->agent->call($messages);
64+
$result = $this->agent->call($messages);
6565

66-
\assert($response instanceof TextResponse);
66+
\assert($result instanceof TextResult);
6767

68-
$messages->add(Message::ofAssistant($response->getContent()));
68+
$messages->add(Message::ofAssistant($result->getContent()));
6969

7070
$this->saveMessages($messages);
7171
}

examples/albert/chat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,6 @@
4949
Message::ofUser('What are the main objectives of France\'s AI strategy?'),
5050
);
5151

52-
$response = $agent->call($messages);
52+
$result = $agent->call($messages);
5353

54-
echo $response->getContent().\PHP_EOL;
54+
echo $result->getContent().\PHP_EOL;

examples/anthropic/chat.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,6 @@
3232
Message::forSystem('You are a pirate and you write funny.'),
3333
Message::ofUser('What is the Symfony framework?'),
3434
);
35-
$response = $agent->call($messages);
35+
$result = $agent->call($messages);
3636

37-
echo $response->getContent().\PHP_EOL;
37+
echo $result->getContent().\PHP_EOL;

examples/anthropic/image-input-binary.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,6 @@
3636
'Describe this image.',
3737
),
3838
);
39-
$response = $agent->call($messages);
39+
$result = $agent->call($messages);
4040

41-
echo $response->getContent().\PHP_EOL;
41+
echo $result->getContent().\PHP_EOL;

0 commit comments

Comments
 (0)