Skip to content
Merged
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
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,16 @@

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\AI\Platform\Bridge\DockerModelRunner\Completions;
use Symfony\AI\Platform\Bridge\DockerModelRunner\Completions\ResultConverter;
use Symfony\AI\Platform\Bridge\OpenAi\Gpt\ResultConverter as OpenAiResultConverter;
use Symfony\AI\Platform\Exception\ModelNotFoundException;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Result\RawHttpResult;
use Symfony\Contracts\HttpClient\ResponseInterface;

#[CoversClass(ResultConverter::class)]
#[UsesClass(Completions::class)]
Expand All @@ -31,4 +36,43 @@ public function testItSupportsCompletionsModel()

$this->assertTrue($converter->supports(new Completions('test-model')));
}

#[TestWith(['Model not found'])]
#[TestWith(['MODEL NOT FOUND'])]
public function testItThrowsModelNotFoundExceptionWhen404WithModelNotFoundMessage(string $message)
{
$response = $this->createMock(ResponseInterface::class);
$response
->method('getStatusCode')
->willReturn(404);
$response
->method('getContent')
->with(false)
->willReturn($message);

$this->expectException(ModelNotFoundException::class);
$this->expectExceptionMessage($message);

(new ResultConverter())->convert(new RawHttpResult($response));
}

public function testItDoesNotThrowModelNotFoundExceptionWhen404WithoutModelNotFoundMessage()
{
$response = $this->createMock(ResponseInterface::class);
$response
->method('getStatusCode')
->willReturn(404);
$response
->method('getContent')
->with(false)
->willReturn('Not found');
$response
->method('toArray')
->willReturn(['error' => 'some other error']);

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Response does not contain choices.');

(new ResultConverter())->convert(new RawHttpResult($response));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,12 @@

use PHPUnit\Framework\Attributes\CoversClass;
use PHPUnit\Framework\Attributes\Small;
use PHPUnit\Framework\Attributes\TestWith;
use PHPUnit\Framework\Attributes\UsesClass;
use PHPUnit\Framework\TestCase;
use Symfony\AI\Platform\Bridge\DockerModelRunner\Embeddings;
use Symfony\AI\Platform\Bridge\DockerModelRunner\Embeddings\ResultConverter;
use Symfony\AI\Platform\Exception\ModelNotFoundException;
use Symfony\AI\Platform\Exception\RuntimeException;
use Symfony\AI\Platform\Result\RawHttpResult;
use Symfony\AI\Platform\Result\VectorResult;
Expand Down Expand Up @@ -86,4 +88,43 @@ public function testItSupportsEmbeddingsModel()

$this->assertTrue($converter->supports(new Embeddings('test-model')));
}

#[TestWith(['Model not found'])]
#[TestWith(['MODEL NOT FOUND'])]
public function testItThrowsModelNotFoundExceptionWhen404WithModelNotFoundMessage(string $message)
{
$response = $this->createMock(ResponseInterface::class);
$response
->method('getStatusCode')
->willReturn(404);
$response
->method('getContent')
->with(false)
->willReturn($message);

$this->expectException(ModelNotFoundException::class);
$this->expectExceptionMessage($message);

(new ResultConverter())->convert(new RawHttpResult($response));
}

public function testItDoesNotThrowModelNotFoundExceptionWhen404WithoutModelNotFoundMessage()
{
$response = $this->createMock(ResponseInterface::class);
$response
->method('getStatusCode')
->willReturn(404);
$response
->method('getContent')
->with(false)
->willReturn('Not found');
$response
->method('toArray')
->willReturn(['error' => 'some other error']);

$this->expectException(RuntimeException::class);
$this->expectExceptionMessage('Response does not contain data.');

(new ResultConverter())->convert(new RawHttpResult($response));
}
}