Skip to content

Commit c9fb496

Browse files
committed
feature #628 [Platform][DockerModelRunner] Add ModelNotFoundException (welcoMattic)
This PR was merged into the main branch. Discussion ---------- [Platform][DockerModelRunner] Add `ModelNotFoundException` | Q | A | ------------- | --- | Bug fix? | no | New feature? | yes<!-- please update src/**/CHANGELOG.md files --> | Docs? | no <!-- required for new features --> | Issues | Fix #... <!-- prefix each issue number with "Fix #", no need to create an issue if none exist, explain below instead --> | License | MIT Following up #531 This PR introduce `ModelNotFoundException`, useful for local model runners that return an error due to a non-existing model locally (typo in name or never downloaded model for instance). It must be used by Ollama and LmStudio bridges. PRs are welcome. Commits ------- 3374b14 Add ModelNotFoundException
2 parents ea80e67 + 3374b14 commit c9fb496

File tree

4 files changed

+32
-1
lines changed

4 files changed

+32
-1
lines changed

src/platform/src/Bridge/DockerModelRunner/Completions/ResultConverter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
use Symfony\AI\Platform\Bridge\DockerModelRunner\Completions;
1515
use Symfony\AI\Platform\Exception\ContentFilterException;
1616
use Symfony\AI\Platform\Exception\ExceedContextSizeException;
17+
use Symfony\AI\Platform\Exception\ModelNotFoundException;
1718
use Symfony\AI\Platform\Exception\RuntimeException;
1819
use Symfony\AI\Platform\Model;
1920
use Symfony\AI\Platform\Result\ChoiceResult;
@@ -46,6 +47,11 @@ public function convert(RawResultInterface|RawHttpResult $result, array $options
4647
return new StreamResult($this->convertStream($result->getObject()));
4748
}
4849

50+
if (404 === $result->getObject()->getStatusCode()
51+
&& str_contains(strtolower($result->getObject()->getContent(false)), 'model not found')) {
52+
throw new ModelNotFoundException($result->getObject()->getContent(false));
53+
}
54+
4955
$data = $result->getData();
5056

5157
if (isset($data['error']['type']) && 'exceed_context_size_error' === $data['error']['type']) {

src/platform/src/Bridge/DockerModelRunner/Embeddings/ResultConverter.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
namespace Symfony\AI\Platform\Bridge\DockerModelRunner\Embeddings;
1313

1414
use Symfony\AI\Platform\Bridge\DockerModelRunner\Embeddings;
15+
use Symfony\AI\Platform\Exception\ModelNotFoundException;
1516
use Symfony\AI\Platform\Exception\RuntimeException;
1617
use Symfony\AI\Platform\Model;
1718
use Symfony\AI\Platform\Result\RawResultInterface;
@@ -31,6 +32,11 @@ public function supports(Model $model): bool
3132

3233
public function convert(RawResultInterface $result, array $options = []): VectorResult
3334
{
35+
if (404 === $result->getObject()->getStatusCode()
36+
&& str_contains(strtolower($result->getObject()->getContent(false)), 'model not found')) {
37+
throw new ModelNotFoundException($result->getObject()->getContent(false));
38+
}
39+
3440
$data = $result->getData();
3541

3642
if (!isset($data['data'])) {

src/platform/src/Exception/ExceedContextSizeException.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,6 @@
1414
/**
1515
* @author Mathieu Santostefano <[email protected]>
1616
*/
17-
class ExceedContextSizeException extends InvalidArgumentException
17+
class ExceedContextSizeException extends InvalidArgumentException implements ExceptionInterface
1818
{
1919
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
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\Platform\Exception;
13+
14+
/**
15+
* @author Mathieu Santostefano <[email protected]>
16+
*/
17+
class ModelNotFoundException extends \InvalidArgumentException implements ExceptionInterface
18+
{
19+
}

0 commit comments

Comments
 (0)