|
| 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\Bridge\Ollama; |
| 13 | + |
| 14 | +use Symfony\AI\Platform\Capability; |
| 15 | +use Symfony\AI\Platform\Model; |
| 16 | + |
| 17 | +/** |
| 18 | + * @author Joshua Behrens <[email protected]> |
| 19 | + */ |
| 20 | +class Ollama extends Model |
| 21 | +{ |
| 22 | + public const DEEPSEEK_R_1 = 'deepseek-r1'; |
| 23 | + public const GEMMA_3_N = 'gemma3n'; |
| 24 | + public const GEMMA_3 = 'gemma3'; |
| 25 | + public const QWEN_3 = 'qwen3'; |
| 26 | + public const QWEN_2_5_VL = 'qwen2.5vl'; |
| 27 | + public const LLAMA_3_1 = 'llama3.1'; |
| 28 | + public const LLAMA_3_2 = 'llama3.2'; |
| 29 | + public const MISTRAL = 'mistral'; |
| 30 | + public const QWEN_2_5 = 'qwen2.5'; |
| 31 | + public const LLAMA_3 = 'llama3'; |
| 32 | + public const LLAVA = 'llava'; |
| 33 | + public const PHI_3 = 'phi3'; |
| 34 | + public const GEMMA_2 = 'gemma2'; |
| 35 | + public const QWEN_2_5_CODER = 'qwen2.5-coder'; |
| 36 | + public const GEMMA = 'gemma'; |
| 37 | + public const QWEN = 'qwen'; |
| 38 | + public const QWEN_2 = 'qwen2'; |
| 39 | + public const LLAMA_2 = 'llama2'; |
| 40 | + |
| 41 | + private const TOOL_PATTERNS = [ |
| 42 | + '/./' => [ |
| 43 | + Capability::INPUT_MESSAGES, |
| 44 | + Capability::OUTPUT_TEXT, |
| 45 | + ], |
| 46 | + '/^llama\D*3(\D*\d+)/' => [ |
| 47 | + Capability::TOOL_CALLING, |
| 48 | + ], |
| 49 | + '/^qwen\d(\.\d)?(-coder)?$/' => [ |
| 50 | + Capability::TOOL_CALLING, |
| 51 | + ], |
| 52 | + '/^(deepseek|mistral)/' => [ |
| 53 | + Capability::TOOL_CALLING, |
| 54 | + ], |
| 55 | + ]; |
| 56 | + |
| 57 | + /** |
| 58 | + * @param array<string, mixed> $options |
| 59 | + */ |
| 60 | + public function __construct(string $name = self::LLAMA_3_2, array $options = []) |
| 61 | + { |
| 62 | + $capabilities = []; |
| 63 | + |
| 64 | + foreach (self::TOOL_PATTERNS as $pattern => $possibleCapabilities) { |
| 65 | + if (1 === preg_match($pattern, $name)) { |
| 66 | + foreach ($possibleCapabilities as $capability) { |
| 67 | + $capabilities[] = $capability; |
| 68 | + } |
| 69 | + } |
| 70 | + } |
| 71 | + |
| 72 | + parent::__construct($name, $capabilities, $options); |
| 73 | + } |
| 74 | +} |
0 commit comments