|
| 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 | +namespace Symfony\AI\Platform\Bridge\Venice\Tests; |
| 13 | + |
| 14 | +use PHPUnit\Framework\TestCase; |
| 15 | +use Symfony\AI\Platform\Bridge\Venice\ModelCatalog; |
| 16 | +use Symfony\AI\Platform\Capability; |
| 17 | +use Symfony\AI\Platform\Exception\InvalidArgumentException; |
| 18 | +use Symfony\Component\HttpClient\MockHttpClient; |
| 19 | +use Symfony\Component\HttpClient\Response\JsonMockResponse; |
| 20 | + |
| 21 | +final class ModelCatalogTest extends TestCase |
| 22 | +{ |
| 23 | + public function testModelCatalogCannotReturnModelFromApiWhenUndefined() |
| 24 | + { |
| 25 | + $httpClient = new MockHttpClient([ |
| 26 | + new JsonMockResponse(['data' => []]), |
| 27 | + ]); |
| 28 | + |
| 29 | + $modelCatalog = new ModelCatalog($httpClient); |
| 30 | + |
| 31 | + $this->expectException(InvalidArgumentException::class); |
| 32 | + $this->expectExceptionMessage('The model "foo" cannot be retrieved from the API.'); |
| 33 | + $this->expectExceptionCode(0); |
| 34 | + $modelCatalog->getModel('foo'); |
| 35 | + } |
| 36 | + |
| 37 | + public function testModelCatalogCannotReturnUnsupportedModelFromApi() |
| 38 | + { |
| 39 | + $httpClient = new MockHttpClient([ |
| 40 | + new JsonMockResponse([ |
| 41 | + 'data' => [ |
| 42 | + [ |
| 43 | + 'createdAt' => (new \DateTimeImmutable())->getTimestamp(), |
| 44 | + 'id' => 'llama-3.2-3b', |
| 45 | + 'model_spec' => [ |
| 46 | + 'capabilities' => [ |
| 47 | + 'optimizedForCode' => true, |
| 48 | + 'quantization' => 'fp16', |
| 49 | + 'supportsFunctionCalling' => true, |
| 50 | + 'supportsReasoning' => false, |
| 51 | + 'supportsVision' => false, |
| 52 | + 'supportsWebSearch' => true, |
| 53 | + ], |
| 54 | + ], |
| 55 | + 'object' => 'model', |
| 56 | + 'owned_by' => 'venice.ai', |
| 57 | + 'type' => 'text', |
| 58 | + ], |
| 59 | + [ |
| 60 | + 'createdAt' => (new \DateTimeImmutable())->getTimestamp(), |
| 61 | + 'id' => 'foo', |
| 62 | + 'model_spec' => [ |
| 63 | + 'capabilities' => [ |
| 64 | + 'optimizedForCode' => false, |
| 65 | + 'quantization' => 'fp16', |
| 66 | + 'supportsFunctionCalling' => false, |
| 67 | + 'supportsReasoning' => false, |
| 68 | + 'supportsVision' => false, |
| 69 | + 'supportsWebSearch' => false, |
| 70 | + ], |
| 71 | + ], |
| 72 | + 'object' => 'model', |
| 73 | + 'owned_by' => 'venice.ai', |
| 74 | + 'type' => 'text', |
| 75 | + ], |
| 76 | + ], |
| 77 | + 'object' => 'list', |
| 78 | + 'type' => 'all', |
| 79 | + ]), |
| 80 | + ]); |
| 81 | + |
| 82 | + $modelCatalog = new ModelCatalog($httpClient); |
| 83 | + |
| 84 | + $this->expectException(InvalidArgumentException::class); |
| 85 | + $this->expectExceptionMessage('The model "foo" is not supported, please check the Venice API.'); |
| 86 | + $this->expectExceptionCode(0); |
| 87 | + $modelCatalog->getModel('foo'); |
| 88 | + } |
| 89 | + |
| 90 | + public function testModelCatalogCanReturnAsrModelFromApi() |
| 91 | + { |
| 92 | + $httpClient = new MockHttpClient([ |
| 93 | + new JsonMockResponse([ |
| 94 | + 'data' => [ |
| 95 | + [ |
| 96 | + 'createdAt' => (new \DateTimeImmutable())->getTimestamp(), |
| 97 | + 'id' => 'nvidia/parakeet-tdt-0.6b-v3', |
| 98 | + 'model_spec' => [ |
| 99 | + 'pricing' => [ |
| 100 | + 'per_audio_second' => [ |
| 101 | + 'usd' => 0.0001, |
| 102 | + 'diem' => 0.0001 |
| 103 | + ], |
| 104 | + ], |
| 105 | + ], |
| 106 | + 'name' => 'Parakeet ASR', |
| 107 | + 'modelSource' => 'https://huggingface.co/nvidia/parakeet-tdt-0.6b-v3', |
| 108 | + 'offline' => false, |
| 109 | + 'privacy' => 'private', |
| 110 | + 'object' => 'model', |
| 111 | + 'owned_by' => 'venice.ai', |
| 112 | + 'type' => 'asr', |
| 113 | + ], |
| 114 | + ], |
| 115 | + 'object' => 'list', |
| 116 | + 'type' => 'all', |
| 117 | + ]), |
| 118 | + ]); |
| 119 | + |
| 120 | + $modelCatalog = new ModelCatalog($httpClient); |
| 121 | + |
| 122 | + $model = $modelCatalog->getModel('nvidia/parakeet-tdt-0.6b-v3'); |
| 123 | + |
| 124 | + $this->assertSame('nvidia/parakeet-tdt-0.6b-v3', $model->getName()); |
| 125 | + $this->assertSame([ |
| 126 | + Capability::SPEECH_RECOGNITION, |
| 127 | + Capability::INPUT_TEXT, |
| 128 | + ], $model->getCapabilities()); |
| 129 | + |
| 130 | + $this->assertSame(1, $httpClient->getRequestsCount()); |
| 131 | + } |
| 132 | + |
| 133 | + public function testModelCatalogCanReturnEmbeddingModelFromApi() |
| 134 | + { |
| 135 | + $httpClient = new MockHttpClient([ |
| 136 | + new JsonMockResponse([ |
| 137 | + 'data' => [ |
| 138 | + [ |
| 139 | + 'createdAt' => (new \DateTimeImmutable())->getTimestamp(), |
| 140 | + 'id' => 'text-embedding-bge-m3', |
| 141 | + 'model_spec' => [ |
| 142 | + 'pricing' => [ |
| 143 | + 'input' => [ |
| 144 | + 'usd' => 0.15, |
| 145 | + 'diem' => 0.15 |
| 146 | + ], |
| 147 | + 'output' => [ |
| 148 | + 'usd' => 0.6, |
| 149 | + 'diem' => 0.6 |
| 150 | + ], |
| 151 | + ], |
| 152 | + ], |
| 153 | + 'name' => 'BGE-3', |
| 154 | + 'modelSource' => 'https://huggingface.co/BAAI/bge-m3', |
| 155 | + 'offline' => false, |
| 156 | + 'privacy' => 'private', |
| 157 | + 'object' => 'model', |
| 158 | + 'owned_by' => 'venice.ai', |
| 159 | + 'type' => 'embedding', |
| 160 | + ], |
| 161 | + ], |
| 162 | + 'object' => 'list', |
| 163 | + 'type' => 'all', |
| 164 | + ]), |
| 165 | + ]); |
| 166 | + |
| 167 | + $modelCatalog = new ModelCatalog($httpClient); |
| 168 | + |
| 169 | + $model = $modelCatalog->getModel('text-embedding-bge-m3'); |
| 170 | + |
| 171 | + $this->assertSame('text-embedding-bge-m3', $model->getName()); |
| 172 | + $this->assertSame([ |
| 173 | + Capability::EMBEDDINGS, |
| 174 | + Capability::INPUT_TEXT, |
| 175 | + ], $model->getCapabilities()); |
| 176 | + |
| 177 | + $this->assertSame(1, $httpClient->getRequestsCount()); |
| 178 | + } |
| 179 | + |
| 180 | + public function testModelCatalogCanReturnImageModelFromApi() |
| 181 | + { |
| 182 | + |
| 183 | + } |
| 184 | +} |
0 commit comments