Skip to content

Commit 61b5241

Browse files
committed
refactor!: improve types in platform api (#376)
I was just tired of doing those `assert($response instanceof ...);` statements also resolves the special status of `AsyncResponse` by decoupling it from the `ResponseInterface` WDYT?
1 parent 02b5a55 commit 61b5241

File tree

2 files changed

+2
-9
lines changed

2 files changed

+2
-9
lines changed

src/Agent.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
use Symfony\AI\Platform\Message\MessageBagInterface;
2121
use Symfony\AI\Platform\Model;
2222
use Symfony\AI\Platform\PlatformInterface;
23-
use Symfony\AI\Platform\Response\AsyncResponse;
2423
use Symfony\AI\Platform\Response\ResponseInterface;
2524
use Symfony\Contracts\HttpClient\Exception\ClientExceptionInterface;
2625
use Symfony\Contracts\HttpClient\Exception\HttpExceptionInterface;
@@ -76,11 +75,7 @@ public function call(MessageBagInterface $messages, array $options = []): Respon
7675
}
7776

7877
try {
79-
$response = $this->platform->request($model, $messages, $options);
80-
81-
if ($response instanceof AsyncResponse) {
82-
$response = $response->unwrap();
83-
}
78+
$response = $this->platform->request($model, $messages, $options)->getResponse();
8479
} catch (ClientExceptionInterface $e) {
8580
$message = $e->getMessage();
8681
$content = $e->getResponse()->toArray(false);

src/Toolbox/Tool/SimilaritySearch.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
use Symfony\AI\Agent\Toolbox\Attribute\AsTool;
1515
use Symfony\AI\Platform\Model;
1616
use Symfony\AI\Platform\PlatformInterface;
17-
use Symfony\AI\Platform\Vector\Vector;
1817
use Symfony\AI\Store\Document\VectorDocument;
1918
use Symfony\AI\Store\VectorStoreInterface;
2019

@@ -41,8 +40,7 @@ public function __construct(
4140
*/
4241
public function __invoke(string $searchTerm): string
4342
{
44-
/** @var Vector[] $vectors */
45-
$vectors = $this->platform->request($this->model, $searchTerm)->getContent();
43+
$vectors = $this->platform->request($this->model, $searchTerm)->asVectors();
4644
$this->usedDocuments = $this->vectorStore->query($vectors[0]);
4745

4846
if (0 === \count($this->usedDocuments)) {

0 commit comments

Comments
 (0)