Skip to content

Commit 8779cda

Browse files
committed
ref
1 parent 4b22015 commit 8779cda

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
/*
4+
* This file is part of the Symfony package.
5+
*
6+
* (c) Fabien Potencier <fabien@symfony.com>
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+
use Symfony\AI\Platform\Bridge\Ollama\Ollama;
13+
use Symfony\AI\Platform\Bridge\Ollama\PlatformFactory;
14+
use Symfony\AI\Platform\Message\Message;
15+
use Symfony\AI\Platform\Message\MessageBag;
16+
use Symfony\AI\Platform\ModelCatalog\DynamicModelCatalog;
17+
18+
require_once dirname(__DIR__).'/bootstrap.php';
19+
20+
$platform = PlatformFactory::create(env('OLLAMA_HOST_URL'), http_client(), new DynamicModelCatalog(Ollama::class));
21+
22+
$messages = new MessageBag(
23+
Message::forSystem('You are a helpful assistant.'),
24+
Message::ofUser('Tina has one brother and one sister. How many sisters do Tina\'s siblings have?'),
25+
);
26+
27+
try {
28+
$result = $platform->invoke(env('OLLAMA_LLM'), $messages);
29+
echo $result->asText().\PHP_EOL;
30+
} catch (InvalidArgumentException $e) {
31+
echo $e->getMessage()."\nMaybe use a different model?\n";
32+
}

src/platform/src/ModelCatalog/DynamicModelCatalog.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,16 @@
2525

2626
class DynamicModelCatalog extends AbstractModelCatalog
2727
{
28-
public function __construct()
29-
{
28+
public function __construct(
29+
private readonly ?string $expectedModel = Model::class,
30+
) {
3031
$this->models = [];
3132
}
3233

3334
public function getModel(string $modelName): Model
3435
{
3536
$parsed = self::parseModelName($modelName);
3637

37-
return new Model($parsed['name'], Capability::cases(), $parsed['options']);
38+
return new $this->expectedModel($parsed['name'], Capability::cases(), $parsed['options']);
3839
}
3940
}

0 commit comments

Comments
 (0)