diff --git a/examples/bootstrap.php b/examples/bootstrap.php
index de9440a50..03bba3861 100644
--- a/examples/bootstrap.php
+++ b/examples/bootstrap.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Exception\ExceptionInterface as PlatformException;
use Symfony\AI\Platform\Metadata\Metadata;
use Symfony\AI\Platform\Metadata\TokenUsage;
-use Symfony\AI\Platform\Result\ResultPromise;
+use Symfony\AI\Platform\Result\DeferredResult;
use Symfony\AI\Store\Exception\ExceptionInterface as StoreException;
use Symfony\Component\Console\Helper\Table;
use Symfony\Component\Console\Logger\ConsoleLogger;
@@ -120,7 +120,7 @@ function print_token_usage(Metadata $metadata): void
$table->render();
}
-function print_vectors(ResultPromise $result): void
+function print_vectors(DeferredResult $result): void
{
assert([] !== $result->asVectors());
assert(array_key_exists(0, $result->asVectors()));
@@ -178,7 +178,7 @@ function perplexity_print_citations(Metadata $metadata): void
}
}
-function print_stream(ResultPromise $result): void
+function print_stream(DeferredResult $result): void
{
foreach ($result->asStream() as $word) {
echo $word;
diff --git a/src/agent/tests/AgentTest.php b/src/agent/tests/AgentTest.php
index 1973ab244..a3e3636de 100644
--- a/src/agent/tests/AgentTest.php
+++ b/src/agent/tests/AgentTest.php
@@ -26,9 +26,10 @@
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Platform\Message\UserMessage;
use Symfony\AI\Platform\PlatformInterface;
+use Symfony\AI\Platform\Result\DeferredResult;
use Symfony\AI\Platform\Result\RawResultInterface;
use Symfony\AI\Platform\Result\ResultInterface;
-use Symfony\AI\Platform\Result\ResultPromise;
+use Symfony\AI\Platform\Test\PlainConverter;
final class AgentTest extends TestCase
{
@@ -120,7 +121,7 @@ public function testCallProcessesInputThroughProcessors()
->with($this->isInstanceOf(Input::class));
$rawResult = $this->createMock(RawResultInterface::class);
- $response = new ResultPromise(fn () => $result, $rawResult, []);
+ $response = new DeferredResult(new PlainConverter($result), $rawResult, []);
$platform->expects($this->once())
->method('invoke')
@@ -146,7 +147,7 @@ public function testCallProcessesOutputThroughProcessors()
->with($this->isInstanceOf(Output::class));
$rawResult = $this->createMock(RawResultInterface::class);
- $response = new ResultPromise(fn () => $result, $rawResult, []);
+ $response = new DeferredResult(new PlainConverter($result), $rawResult, []);
$platform->expects($this->once())
->method('invoke')
@@ -166,7 +167,7 @@ public function testCallAllowsAudioInputWithSupport()
$result = $this->createMock(ResultInterface::class);
$rawResult = $this->createMock(RawResultInterface::class);
- $response = new ResultPromise(fn () => $result, $rawResult, []);
+ $response = new DeferredResult(new PlainConverter($result), $rawResult, []);
$platform->expects($this->once())
->method('invoke')
@@ -186,7 +187,7 @@ public function testCallAllowsImageInputWithSupport()
$result = $this->createMock(ResultInterface::class);
$rawResult = $this->createMock(RawResultInterface::class);
- $response = new ResultPromise(fn () => $result, $rawResult, []);
+ $response = new DeferredResult(new PlainConverter($result), $rawResult, []);
$platform->expects($this->once())
->method('invoke')
@@ -207,7 +208,7 @@ public function testCallPassesOptionsToInvoke()
$result = $this->createMock(ResultInterface::class);
$rawResult = $this->createMock(RawResultInterface::class);
- $response = new ResultPromise(fn () => $result, $rawResult, []);
+ $response = new DeferredResult(new PlainConverter($result), $rawResult, []);
$platform->expects($this->once())
->method('invoke')
diff --git a/src/agent/tests/Memory/EmbeddingProviderTest.php b/src/agent/tests/Memory/EmbeddingProviderTest.php
index bcea04182..456e4cf6d 100644
--- a/src/agent/tests/Memory/EmbeddingProviderTest.php
+++ b/src/agent/tests/Memory/EmbeddingProviderTest.php
@@ -20,9 +20,10 @@
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\PlatformInterface;
+use Symfony\AI\Platform\Result\DeferredResult;
use Symfony\AI\Platform\Result\RawResultInterface;
-use Symfony\AI\Platform\Result\ResultPromise;
use Symfony\AI\Platform\Result\VectorResult;
+use Symfony\AI\Platform\Test\PlainConverter;
use Symfony\AI\Platform\Vector\Vector;
use Symfony\AI\Store\StoreInterface;
@@ -78,8 +79,8 @@ public function testItIsDoingNothingWhenUserMessageHasNoTextContent()
public function testItIsNotCreatingMemoryWhenNoVectorsFound()
{
$vectorResult = new VectorResult($vector = new Vector([0.1, 0.2], 2));
- $resultPromise = new ResultPromise(
- static fn () => $vectorResult,
+ $deferredResult = new DeferredResult(
+ new PlainConverter($vectorResult),
$this->createStub(RawResultInterface::class),
);
@@ -87,7 +88,7 @@ public function testItIsNotCreatingMemoryWhenNoVectorsFound()
$platform->expects($this->once())
->method('invoke')
->with('text-embedding-3-small', 'Have we talked about the weather?')
- ->willReturn($resultPromise);
+ ->willReturn($deferredResult);
$store = $this->createMock(StoreInterface::class);
$store->expects($this->once())
@@ -109,8 +110,8 @@ public function testItIsNotCreatingMemoryWhenNoVectorsFound()
public function testItIsCreatingMemoryWithFoundVectors()
{
$vectorResult = new VectorResult($vector = new Vector([0.1, 0.2], 2));
- $resultPromise = new ResultPromise(
- static fn () => $vectorResult,
+ $deferredResult = new DeferredResult(
+ new PlainConverter($vectorResult),
$this->createStub(RawResultInterface::class),
);
@@ -118,7 +119,7 @@ public function testItIsCreatingMemoryWithFoundVectors()
$platform->expects($this->once())
->method('invoke')
->with('text-embedding-3-small', 'Have we talked about the weather?')
- ->willReturn($resultPromise);
+ ->willReturn($deferredResult);
$store = $this->createMock(StoreInterface::class);
$store->expects($this->once())
diff --git a/src/ai-bundle/src/Command/PlatformInvokeCommand.php b/src/ai-bundle/src/Command/PlatformInvokeCommand.php
index 665854036..4f49c31e2 100644
--- a/src/ai-bundle/src/Command/PlatformInvokeCommand.php
+++ b/src/ai-bundle/src/Command/PlatformInvokeCommand.php
@@ -98,8 +98,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$messages = new MessageBag();
$messages->add(Message::ofUser($this->message));
- $resultPromise = $this->platform->invoke($this->model, $messages);
- $result = $resultPromise->getResult();
+ $result = $this->platform->invoke($this->model, $messages)->getResult();
if ($result instanceof TextResult) {
$io->writeln('Response: '.$result->getContent());
diff --git a/src/ai-bundle/src/Profiler/DataCollector.php b/src/ai-bundle/src/Profiler/DataCollector.php
index 546ecdabd..e09a945da 100644
--- a/src/ai-bundle/src/Profiler/DataCollector.php
+++ b/src/ai-bundle/src/Profiler/DataCollector.php
@@ -105,7 +105,7 @@ private function awaitCallResults(TraceablePlatform $platform): array
{
$calls = $platform->calls;
foreach ($calls as $key => $call) {
- $result = $call['result']->await();
+ $result = $call['result']->getResult();
if (isset($platform->resultCache[$result])) {
$call['result'] = $platform->resultCache[$result];
diff --git a/src/ai-bundle/src/Profiler/TraceablePlatform.php b/src/ai-bundle/src/Profiler/TraceablePlatform.php
index e8d0e01ee..5bfe6b58b 100644
--- a/src/ai-bundle/src/Profiler/TraceablePlatform.php
+++ b/src/ai-bundle/src/Profiler/TraceablePlatform.php
@@ -15,9 +15,10 @@
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
use Symfony\AI\Platform\PlatformInterface;
+use Symfony\AI\Platform\Result\DeferredResult;
use Symfony\AI\Platform\Result\ResultInterface;
-use Symfony\AI\Platform\Result\ResultPromise;
use Symfony\AI\Platform\Result\StreamResult;
+use Symfony\AI\Platform\Test\PlainConverter;
/**
* @author Christopher Hertel
@@ -26,7 +27,7 @@
* model: string,
* input: array|string|object,
* options: array,
- * result: ResultPromise,
+ * result: DeferredResult,
* }
*/
final class TraceablePlatform implements PlatformInterface
@@ -46,27 +47,27 @@ public function __construct(
$this->resultCache = new \WeakMap();
}
- public function invoke(string $model, array|string|object $input, array $options = []): ResultPromise
+ public function invoke(string $model, array|string|object $input, array $options = []): DeferredResult
{
- $resultPromise = $this->platform->invoke($model, $input, $options);
+ $deferredResult = $this->platform->invoke($model, $input, $options);
if ($input instanceof File) {
$input = $input::class.': '.$input->getFormat();
}
if ($options['stream'] ?? false) {
- $originalStream = $resultPromise->asStream();
- $resultPromise = new ResultPromise(fn () => $this->createTraceableStreamResult($originalStream), $resultPromise->getRawResult(), $options);
+ $originalStream = $deferredResult->asStream();
+ $deferredResult = new DeferredResult(new PlainConverter($this->createTraceableStreamResult($originalStream)), $deferredResult->getRawResult(), $options);
}
$this->calls[] = [
'model' => $model,
'input' => \is_object($input) ? clone $input : $input,
'options' => $options,
- 'result' => $resultPromise,
+ 'result' => $deferredResult,
];
- return $resultPromise;
+ return $deferredResult;
}
public function getModelCatalog(): ModelCatalogInterface
diff --git a/src/ai-bundle/tests/Command/PlatformInvokeCommandTest.php b/src/ai-bundle/tests/Command/PlatformInvokeCommandTest.php
index c9a087213..83e2a98fd 100644
--- a/src/ai-bundle/tests/Command/PlatformInvokeCommandTest.php
+++ b/src/ai-bundle/tests/Command/PlatformInvokeCommandTest.php
@@ -15,9 +15,10 @@
use Symfony\AI\AiBundle\Command\PlatformInvokeCommand;
use Symfony\AI\AiBundle\Exception\InvalidArgumentException;
use Symfony\AI\Platform\PlatformInterface;
+use Symfony\AI\Platform\Result\DeferredResult;
use Symfony\AI\Platform\Result\InMemoryRawResult;
-use Symfony\AI\Platform\Result\ResultPromise;
use Symfony\AI\Platform\Result\TextResult;
+use Symfony\AI\Platform\Test\PlainConverter;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Tester\CommandTester;
use Symfony\Component\DependencyInjection\ServiceLocator;
@@ -28,7 +29,7 @@ public function testExecuteSuccessfully()
{
$textResult = new TextResult('Hello! How can I assist you?');
$rawResult = new InMemoryRawResult([]);
- $promise = new ResultPromise(fn () => $textResult, $rawResult);
+ $promise = new DeferredResult(new PlainConverter($textResult), $rawResult);
$platform = $this->createMock(PlatformInterface::class);
$platform->method('invoke')
diff --git a/src/ai-bundle/tests/Profiler/DataCollectorTest.php b/src/ai-bundle/tests/Profiler/DataCollectorTest.php
index bed7ded34..81c2d1322 100644
--- a/src/ai-bundle/tests/Profiler/DataCollectorTest.php
+++ b/src/ai-bundle/tests/Profiler/DataCollectorTest.php
@@ -19,10 +19,11 @@
use Symfony\AI\Platform\Message\Message;
use Symfony\AI\Platform\Message\MessageBag;
use Symfony\AI\Platform\PlatformInterface;
+use Symfony\AI\Platform\Result\DeferredResult;
use Symfony\AI\Platform\Result\RawResultInterface;
-use Symfony\AI\Platform\Result\ResultPromise;
use Symfony\AI\Platform\Result\StreamResult;
use Symfony\AI\Platform\Result\TextResult;
+use Symfony\AI\Platform\Test\PlainConverter;
class DataCollectorTest extends TestCase
{
@@ -33,7 +34,7 @@ public function testCollectsDataForNonStreamingResponse()
$messageBag = new MessageBag(Message::ofUser(new Text('Hello')));
$result = new TextResult('Assistant response');
- $platform->method('invoke')->willReturn(new ResultPromise(static fn () => $result, $this->createStub(RawResultInterface::class)));
+ $platform->method('invoke')->willReturn(new DeferredResult(new PlainConverter($result), $this->createStub(RawResultInterface::class)));
$result = $traceablePlatform->invoke('gpt-4o', $messageBag, ['stream' => false]);
$this->assertSame('Assistant response', $result->asText());
@@ -57,7 +58,7 @@ public function testCollectsDataForStreamingResponse()
})(),
);
- $platform->method('invoke')->willReturn(new ResultPromise(static fn () => $result, $this->createStub(RawResultInterface::class)));
+ $platform->method('invoke')->willReturn(new DeferredResult(new PlainConverter($result), $this->createStub(RawResultInterface::class)));
$result = $traceablePlatform->invoke('gpt-4o', $messageBag, ['stream' => true]);
$this->assertSame('Assistant response', implode('', iterator_to_array($result->asStream())));
diff --git a/src/platform/src/Platform.php b/src/platform/src/Platform.php
index b3c19ff3c..e6759d448 100644
--- a/src/platform/src/Platform.php
+++ b/src/platform/src/Platform.php
@@ -13,8 +13,8 @@
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
+use Symfony\AI\Platform\Result\DeferredResult;
use Symfony\AI\Platform\Result\RawResultInterface;
-use Symfony\AI\Platform\Result\ResultPromise;
/**
* @author Christopher Hertel
@@ -46,7 +46,7 @@ public function __construct(
$this->resultConverters = $resultConverters instanceof \Traversable ? iterator_to_array($resultConverters) : $resultConverters;
}
- public function invoke(string $model, array|string|object $input, array $options = []): ResultPromise
+ public function invoke(string $model, array|string|object $input, array $options = []): DeferredResult
{
$model = $this->modelCatalog->getModel($model);
$payload = $this->contract->createRequestPayload($model, $input);
@@ -84,11 +84,11 @@ private function doInvoke(Model $model, array|string $payload, array $options =
/**
* @param array $options
*/
- private function convertResult(Model $model, RawResultInterface $result, array $options): ResultPromise
+ private function convertResult(Model $model, RawResultInterface $result, array $options): DeferredResult
{
foreach ($this->resultConverters as $resultConverter) {
if ($resultConverter->supports($model)) {
- return new ResultPromise($resultConverter->convert(...), $result, $options);
+ return new DeferredResult($resultConverter, $result, $options);
}
}
diff --git a/src/platform/src/PlatformInterface.php b/src/platform/src/PlatformInterface.php
index e6dcfbd36..109ad018e 100644
--- a/src/platform/src/PlatformInterface.php
+++ b/src/platform/src/PlatformInterface.php
@@ -12,7 +12,7 @@
namespace Symfony\AI\Platform;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Result\ResultPromise;
+use Symfony\AI\Platform\Result\DeferredResult;
/**
* @author Christopher Hertel
@@ -24,7 +24,7 @@ interface PlatformInterface
* @param array|string|object $input The input data
* @param array $options The options to customize the model invocation
*/
- public function invoke(string $model, array|string|object $input, array $options = []): ResultPromise;
+ public function invoke(string $model, array|string|object $input, array $options = []): DeferredResult;
public function getModelCatalog(): ModelCatalogInterface;
}
diff --git a/src/platform/src/Result/ResultPromise.php b/src/platform/src/Result/DeferredResult.php
similarity index 90%
rename from src/platform/src/Result/ResultPromise.php
rename to src/platform/src/Result/DeferredResult.php
index 51ff09e19..85b23c5ba 100644
--- a/src/platform/src/Result/ResultPromise.php
+++ b/src/platform/src/Result/DeferredResult.php
@@ -13,12 +13,13 @@
use Symfony\AI\Platform\Exception\ExceptionInterface;
use Symfony\AI\Platform\Exception\UnexpectedResultTypeException;
+use Symfony\AI\Platform\ResultConverterInterface;
use Symfony\AI\Platform\Vector\Vector;
/**
* @author Christopher Hertel
*/
-final class ResultPromise
+final class DeferredResult
{
private bool $isConverted = false;
private ResultInterface $convertedResult;
@@ -27,7 +28,7 @@ final class ResultPromise
* @param array $options
*/
public function __construct(
- private readonly \Closure $resultConverter,
+ private readonly ResultConverterInterface $resultConverter,
private readonly RawResultInterface $rawResult,
private readonly array $options = [],
) {
@@ -37,22 +38,9 @@ public function __construct(
* @throws ExceptionInterface
*/
public function getResult(): ResultInterface
- {
- return $this->await();
- }
-
- public function getRawResult(): RawResultInterface
- {
- return $this->rawResult;
- }
-
- /**
- * @throws ExceptionInterface
- */
- public function await(): ResultInterface
{
if (!$this->isConverted) {
- $this->convertedResult = ($this->resultConverter)($this->rawResult, $this->options);
+ $this->convertedResult = $this->resultConverter->convert($this->rawResult, $this->options);
if (null === $this->convertedResult->getRawResult()) {
// Fallback to set the raw result when it was not handled by the ResultConverter itself
@@ -65,6 +53,11 @@ public function await(): ResultInterface
return $this->convertedResult;
}
+ public function getRawResult(): RawResultInterface
+ {
+ return $this->rawResult;
+ }
+
/**
* @throws ExceptionInterface
*/
diff --git a/src/platform/src/InMemoryPlatform.php b/src/platform/src/Test/InMemoryPlatform.php
similarity index 88%
rename from src/platform/src/InMemoryPlatform.php
rename to src/platform/src/Test/InMemoryPlatform.php
index 548eba99a..42cb174fe 100644
--- a/src/platform/src/InMemoryPlatform.php
+++ b/src/platform/src/Test/InMemoryPlatform.php
@@ -9,13 +9,15 @@
* file that was distributed with this source code.
*/
-namespace Symfony\AI\Platform;
+namespace Symfony\AI\Platform\Test;
+use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelCatalog\DynamicModelCatalog;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
+use Symfony\AI\Platform\PlatformInterface;
+use Symfony\AI\Platform\Result\DeferredResult;
use Symfony\AI\Platform\Result\InMemoryRawResult;
use Symfony\AI\Platform\Result\ResultInterface;
-use Symfony\AI\Platform\Result\ResultPromise;
use Symfony\AI\Platform\Result\TextResult;
/**
@@ -38,7 +40,7 @@ public function __construct(private readonly \Closure|string $mockResult)
$this->modelCatalog = new DynamicModelCatalog();
}
- public function invoke(string $model, array|string|object $input, array $options = []): ResultPromise
+ public function invoke(string $model, array|string|object $input, array $options = []): DeferredResult
{
$model = new class($model) extends Model {
public function __construct(string $name)
@@ -66,13 +68,13 @@ public function getModelCatalog(): ModelCatalogInterface
* @param ResultInterface $result The result to wrap in a promise
* @param array $options Additional options for the promise
*/
- private function createPromise(ResultInterface $result, array $options): ResultPromise
+ private function createPromise(ResultInterface $result, array $options): DeferredResult
{
$rawResult = $result->getRawResult() ?? new InMemoryRawResult(
['text' => $result->getContent()],
(object) ['text' => $result->getContent()],
);
- return new ResultPromise(static fn () => $result, $rawResult, $options);
+ return new DeferredResult(new PlainConverter($result), $rawResult, $options);
}
}
diff --git a/src/platform/src/Tests/ModelCatalogTestCase.php b/src/platform/src/Test/ModelCatalogTestCase.php
similarity index 99%
rename from src/platform/src/Tests/ModelCatalogTestCase.php
rename to src/platform/src/Test/ModelCatalogTestCase.php
index 7fb31764e..ee94e0644 100644
--- a/src/platform/src/Tests/ModelCatalogTestCase.php
+++ b/src/platform/src/Test/ModelCatalogTestCase.php
@@ -9,7 +9,7 @@
* file that was distributed with this source code.
*/
-namespace Symfony\AI\Platform\Tests;
+namespace Symfony\AI\Platform\Test;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\TestCase;
diff --git a/src/platform/src/Test/PlainConverter.php b/src/platform/src/Test/PlainConverter.php
new file mode 100644
index 000000000..d2c932693
--- /dev/null
+++ b/src/platform/src/Test/PlainConverter.php
@@ -0,0 +1,35 @@
+
+ *
+ * For the full copyright and license information, please view the LICENSE
+ * file that was distributed with this source code.
+ */
+
+namespace Symfony\AI\Platform\Test;
+
+use Symfony\AI\Platform\Model;
+use Symfony\AI\Platform\Result\RawResultInterface;
+use Symfony\AI\Platform\Result\ResultInterface;
+use Symfony\AI\Platform\ResultConverterInterface;
+
+final readonly class PlainConverter implements ResultConverterInterface
+{
+ public function __construct(
+ private ResultInterface $result,
+ ) {
+ }
+
+ public function supports(Model $model): bool
+ {
+ return true;
+ }
+
+ public function convert(RawResultInterface $result, array $options = []): ResultInterface
+ {
+ return $this->result;
+ }
+}
diff --git a/src/platform/tests/Bridge/AiMlApi/ModelCatalogTest.php b/src/platform/tests/Bridge/AiMlApi/ModelCatalogTest.php
index 6d4640463..8cf6d76fe 100644
--- a/src/platform/tests/Bridge/AiMlApi/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/AiMlApi/ModelCatalogTest.php
@@ -16,7 +16,7 @@
use Symfony\AI\Platform\Bridge\AiMlApi\ModelCatalog;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
final class ModelCatalogTest extends ModelCatalogTestCase
{
diff --git a/src/platform/tests/Bridge/Albert/ModelCatalogTest.php b/src/platform/tests/Bridge/Albert/ModelCatalogTest.php
index b48cc1f19..846a99b19 100644
--- a/src/platform/tests/Bridge/Albert/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Albert/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Bridge\OpenAi\Gpt;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Anthropic/ModelCatalogTest.php b/src/platform/tests/Bridge/Anthropic/ModelCatalogTest.php
index 984f68be2..17f7718cc 100644
--- a/src/platform/tests/Bridge/Anthropic/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Anthropic/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Bridge\Anthropic\ModelCatalog;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Azure/Meta/ModelCatalogTest.php b/src/platform/tests/Bridge/Azure/Meta/ModelCatalogTest.php
index 6dd5eb52e..8666f90a1 100644
--- a/src/platform/tests/Bridge/Azure/Meta/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Azure/Meta/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Bridge\Meta\Llama;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Azure/OpenAi/ModelCatalogTest.php b/src/platform/tests/Bridge/Azure/OpenAi/ModelCatalogTest.php
index 56cd34bd5..dd89c3d6f 100644
--- a/src/platform/tests/Bridge/Azure/OpenAi/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Azure/OpenAi/ModelCatalogTest.php
@@ -17,7 +17,7 @@
use Symfony\AI\Platform\Bridge\OpenAi\Whisper;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Bedrock/ModelCatalogTest.php b/src/platform/tests/Bridge/Bedrock/ModelCatalogTest.php
index cafcb693a..afaf68ad2 100644
--- a/src/platform/tests/Bridge/Bedrock/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Bedrock/ModelCatalogTest.php
@@ -16,7 +16,7 @@
use Symfony\AI\Platform\Bridge\Bedrock\Nova\Nova;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Cerebras/ModelCatalogTest.php b/src/platform/tests/Bridge/Cerebras/ModelCatalogTest.php
index fd5d7b858..0da88e1d9 100644
--- a/src/platform/tests/Bridge/Cerebras/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Cerebras/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/DeepSeek/ModelCatalogTest.php b/src/platform/tests/Bridge/DeepSeek/ModelCatalogTest.php
index 40c3a07b1..436b7c440 100644
--- a/src/platform/tests/Bridge/DeepSeek/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/DeepSeek/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Bridge\DeepSeek\ModelCatalog;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/DockerModelRunner/ModelCatalogTest.php b/src/platform/tests/Bridge/DockerModelRunner/ModelCatalogTest.php
index 7c22dcdbc..04c62cb4b 100644
--- a/src/platform/tests/Bridge/DockerModelRunner/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/DockerModelRunner/ModelCatalogTest.php
@@ -16,7 +16,7 @@
use Symfony\AI\Platform\Bridge\DockerModelRunner\ModelCatalog;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/ElevenLabs/ModelCatalogTest.php b/src/platform/tests/Bridge/ElevenLabs/ModelCatalogTest.php
index 35bc30830..ccac7dc7b 100644
--- a/src/platform/tests/Bridge/ElevenLabs/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/ElevenLabs/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Bridge\ElevenLabs\ModelCatalog;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Gemini/ModelCatalogTest.php b/src/platform/tests/Bridge/Gemini/ModelCatalogTest.php
index 430df07bb..924f39b92 100644
--- a/src/platform/tests/Bridge/Gemini/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Gemini/ModelCatalogTest.php
@@ -16,7 +16,7 @@
use Symfony\AI\Platform\Bridge\Gemini\ModelCatalog;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Mistral/ModelCatalogTest.php b/src/platform/tests/Bridge/Mistral/ModelCatalogTest.php
index cfdec2d0f..eea0290df 100644
--- a/src/platform/tests/Bridge/Mistral/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Mistral/ModelCatalogTest.php
@@ -16,7 +16,7 @@
use Symfony\AI\Platform\Bridge\Mistral\ModelCatalog;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Ollama/ModelCatalogTest.php b/src/platform/tests/Bridge/Ollama/ModelCatalogTest.php
index dac4e8b97..037da6c45 100644
--- a/src/platform/tests/Bridge/Ollama/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Ollama/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Bridge\Ollama\Ollama;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/OpenAi/ModelCatalogTest.php b/src/platform/tests/Bridge/OpenAi/ModelCatalogTest.php
index 0cd8a73bb..fa1cd5e23 100644
--- a/src/platform/tests/Bridge/OpenAi/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/OpenAi/ModelCatalogTest.php
@@ -18,7 +18,7 @@
use Symfony\AI\Platform\Bridge\OpenAi\Whisper;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Perplexity/ModelCatalogTest.php b/src/platform/tests/Bridge/Perplexity/ModelCatalogTest.php
index a1b479d96..ae1180661 100644
--- a/src/platform/tests/Bridge/Perplexity/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Perplexity/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Bridge\Perplexity\Perplexity;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Replicate/ModelCatalogTest.php b/src/platform/tests/Bridge/Replicate/ModelCatalogTest.php
index 619434be1..7c8aea162 100644
--- a/src/platform/tests/Bridge/Replicate/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Replicate/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Bridge\Replicate\ModelCatalog;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Scaleway/ModelCatalogTest.php b/src/platform/tests/Bridge/Scaleway/ModelCatalogTest.php
index 9a23094c4..e323d408a 100644
--- a/src/platform/tests/Bridge/Scaleway/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Scaleway/ModelCatalogTest.php
@@ -16,7 +16,7 @@
use Symfony\AI\Platform\Bridge\Scaleway\Scaleway;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/TransformersPhp/ModelCatalogTest.php b/src/platform/tests/Bridge/TransformersPhp/ModelCatalogTest.php
index 9a2ba0f52..e118e9f93 100644
--- a/src/platform/tests/Bridge/TransformersPhp/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/TransformersPhp/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/VertexAi/ModelCatalogTest.php b/src/platform/tests/Bridge/VertexAi/ModelCatalogTest.php
index 2f0b9eff4..7b03fc563 100644
--- a/src/platform/tests/Bridge/VertexAi/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/VertexAi/ModelCatalogTest.php
@@ -16,7 +16,7 @@
use Symfony\AI\Platform\Bridge\VertexAi\ModelCatalog;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
/**
* @author Oskar Stark
diff --git a/src/platform/tests/Bridge/Voyage/ModelCatalogTest.php b/src/platform/tests/Bridge/Voyage/ModelCatalogTest.php
index 4f81782d0..af2e50f8e 100644
--- a/src/platform/tests/Bridge/Voyage/ModelCatalogTest.php
+++ b/src/platform/tests/Bridge/Voyage/ModelCatalogTest.php
@@ -15,7 +15,7 @@
use Symfony\AI\Platform\Bridge\Voyage\Voyage;
use Symfony\AI\Platform\Capability;
use Symfony\AI\Platform\ModelCatalog\ModelCatalogInterface;
-use Symfony\AI\Platform\Tests\ModelCatalogTestCase;
+use Symfony\AI\Platform\Test\ModelCatalogTestCase;
final class ModelCatalogTest extends ModelCatalogTestCase
{
diff --git a/src/platform/tests/InMemoryPlatformTest.php b/src/platform/tests/InMemoryPlatformTest.php
index 0ddfadc9f..0f9c7e345 100644
--- a/src/platform/tests/InMemoryPlatformTest.php
+++ b/src/platform/tests/InMemoryPlatformTest.php
@@ -10,9 +10,9 @@
*/
use PHPUnit\Framework\TestCase;
-use Symfony\AI\Platform\InMemoryPlatform;
use Symfony\AI\Platform\Model;
use Symfony\AI\Platform\Result\VectorResult;
+use Symfony\AI\Platform\Test\InMemoryPlatform;
use Symfony\AI\Platform\Vector\Vector;
class InMemoryPlatformTest extends TestCase
diff --git a/src/platform/tests/Result/ResultPromiseTest.php b/src/platform/tests/Result/DeferredResultTest.php
similarity index 80%
rename from src/platform/tests/Result/ResultPromiseTest.php
rename to src/platform/tests/Result/DeferredResultTest.php
index b6bb93ffb..31c38a2ea 100644
--- a/src/platform/tests/Result/ResultPromiseTest.php
+++ b/src/platform/tests/Result/DeferredResultTest.php
@@ -13,15 +13,15 @@
use PHPUnit\Framework\TestCase;
use Symfony\AI\Platform\Result\BaseResult;
+use Symfony\AI\Platform\Result\DeferredResult;
use Symfony\AI\Platform\Result\RawHttpResult;
use Symfony\AI\Platform\Result\RawResultInterface;
use Symfony\AI\Platform\Result\ResultInterface;
-use Symfony\AI\Platform\Result\ResultPromise;
use Symfony\AI\Platform\Result\TextResult;
use Symfony\AI\Platform\ResultConverterInterface;
use Symfony\Contracts\HttpClient\ResponseInterface as SymfonyHttpResponse;
-final class ResultPromiseTest extends TestCase
+final class DeferredResultTest extends TestCase
{
public function testItUnwrapsTheResultWhenGettingContent()
{
@@ -35,9 +35,9 @@ public function testItUnwrapsTheResultWhenGettingContent()
->with($rawHttpResult, [])
->willReturn($textResult);
- $resultPromise = new ResultPromise($resultConverter->convert(...), $rawHttpResult);
+ $deferredResult = new DeferredResult($resultConverter, $rawHttpResult);
- $this->assertSame('test content', $resultPromise->getResult()->getContent());
+ $this->assertSame('test content', $deferredResult->getResult()->getContent());
}
public function testItConvertsTheResponseOnlyOnce()
@@ -52,12 +52,12 @@ public function testItConvertsTheResponseOnlyOnce()
->with($rawHttpResult, [])
->willReturn($textResult);
- $resultPromise = new ResultPromise($resultConverter->convert(...), $rawHttpResult);
+ $deferredResult = new DeferredResult($resultConverter, $rawHttpResult);
// Call unwrap multiple times, but the converter should only be called once
- $resultPromise->await();
- $resultPromise->await();
- $resultPromise->getResult();
+ $deferredResult->getResult();
+ $deferredResult->getResult();
+ $deferredResult->getResult();
}
public function testItGetsRawResponseDirectly()
@@ -65,9 +65,9 @@ public function testItGetsRawResponseDirectly()
$httpResponse = $this->createStub(SymfonyHttpResponse::class);
$resultConverter = $this->createStub(ResultConverterInterface::class);
- $resultPromise = new ResultPromise($resultConverter->convert(...), new RawHttpResult($httpResponse));
+ $deferredResult = new DeferredResult($resultConverter, new RawHttpResult($httpResponse));
- $this->assertSame($httpResponse, $resultPromise->getRawResult()->getObject());
+ $this->assertSame($httpResponse, $deferredResult->getRawResult()->getObject());
}
public function testItSetsRawResponseOnUnwrappedResponseWhenNeeded()
@@ -79,8 +79,8 @@ public function testItSetsRawResponseOnUnwrappedResponseWhenNeeded()
$resultConverter = $this->createStub(ResultConverterInterface::class);
$resultConverter->method('convert')->willReturn($unwrappedResponse);
- $resultPromise = new ResultPromise($resultConverter->convert(...), new RawHttpResult($httpResponse));
- $resultPromise->await();
+ $deferredResult = new DeferredResult($resultConverter, new RawHttpResult($httpResponse));
+ $deferredResult->getResult();
// The raw response in the model response is now set and not null anymore
$this->assertSame($httpResponse, $unwrappedResponse->getRawResult()->getObject());
@@ -96,8 +96,8 @@ public function testItDoesNotSetRawResponseOnUnwrappedResponseWhenAlreadySet()
$resultConverter = $this->createStub(ResultConverterInterface::class);
$resultConverter->method('convert')->willReturn($unwrappedResult);
- $resultPromise = new ResultPromise($resultConverter->convert(...), new RawHttpResult($originHttpResponse));
- $resultPromise->await();
+ $deferredResult = new DeferredResult($resultConverter, new RawHttpResult($originHttpResponse));
+ $deferredResult->getResult();
// It is still the same raw response as set initially and so not overwritten
$this->assertSame($anotherHttpResponse, $unwrappedResult->getRawResult()->getObject());
@@ -115,8 +115,8 @@ public function testItPassesOptionsToConverter()
->with($rawHttpResponse, $options)
->willReturn($this->createResult(null));
- $resultPromise = new ResultPromise($resultConverter->convert(...), $rawHttpResponse, $options);
- $resultPromise->await();
+ $deferredResult = new DeferredResult($resultConverter, $rawHttpResponse, $options);
+ $deferredResult->getResult();
}
/**
diff --git a/src/store/tests/Document/VectorizerTest.php b/src/store/tests/Document/VectorizerTest.php
index 3946e9e37..bad7f3e24 100644
--- a/src/store/tests/Document/VectorizerTest.php
+++ b/src/store/tests/Document/VectorizerTest.php
@@ -20,9 +20,10 @@
use Symfony\AI\Platform\ModelCatalog\AbstractModelCatalog;
use Symfony\AI\Platform\ModelCatalog\DynamicModelCatalog;
use Symfony\AI\Platform\PlatformInterface;
+use Symfony\AI\Platform\Result\DeferredResult;
use Symfony\AI\Platform\Result\RawResultInterface;
-use Symfony\AI\Platform\Result\ResultPromise;
use Symfony\AI\Platform\Result\VectorResult;
+use Symfony\AI\Platform\Test\PlainConverter;
use Symfony\AI\Platform\Vector\Vector;
use Symfony\AI\Store\Document\Metadata;
use Symfony\AI\Store\Document\TextDocument;
@@ -487,7 +488,7 @@ public function testVectorizeStringPassesOptionsToInvoke()
$this->equalTo($text),
$this->equalTo($options)
)
- ->willReturn(new ResultPromise(fn () => new VectorResult($vector), $this->createMock(RawResultInterface::class)));
+ ->willReturn(new DeferredResult(new PlainConverter(new VectorResult($vector)), $this->createMock(RawResultInterface::class)));
$vectorizer = new Vectorizer($platform, 'text-embedding-3-small');
$result = $vectorizer->vectorize($text, $options);
@@ -508,7 +509,7 @@ public function testVectorizeStringWithEmptyOptions()
$this->equalTo($text),
$this->equalTo([])
)
- ->willReturn(new ResultPromise(fn () => new VectorResult($vector), $this->createMock(RawResultInterface::class)));
+ ->willReturn(new DeferredResult(new PlainConverter(new VectorResult($vector)), $this->createMock(RawResultInterface::class)));
$vectorizer = new Vectorizer($platform, 'text-embedding-3-small');
$result = $vectorizer->vectorize($text);