Skip to content

Commit 29b31bd

Browse files
committed
Add comprehensive platform support to createModelForPlatform method
- Add support for all major AI platforms: vertexai, gemini, lmstudio, cerebras, perplexity - Support both 'gemini' and 'google' aliases for Google Gemini platform - Add test cases for VertexAI and Perplexity platforms - All 11 tests pass with 35 assertions - Provides proper model classes for better capability detection
1 parent f8e022a commit 29b31bd

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

src/ai-bundle/src/Command/PlatformInvokeCommand.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,9 +153,13 @@ private static function createModelForPlatform(string $platformName, string $mod
153153
return match ($platformName) {
154154
'openai' => new \Symfony\AI\Platform\Bridge\OpenAi\Gpt($modelName),
155155
'anthropic' => new \Symfony\AI\Platform\Bridge\Anthropic\Claude($modelName),
156-
'google' => new \Symfony\AI\Platform\Bridge\Gemini\Gemini($modelName),
156+
'gemini', 'google' => new \Symfony\AI\Platform\Bridge\Gemini\Gemini($modelName),
157+
'vertexai' => new \Symfony\AI\Platform\Bridge\VertexAi\Gemini\Model($modelName),
157158
'ollama' => new \Symfony\AI\Platform\Bridge\Ollama\Ollama($modelName),
158159
'mistral' => new \Symfony\AI\Platform\Bridge\Mistral\Mistral($modelName),
160+
'lmstudio' => new \Symfony\AI\Platform\Bridge\LmStudio\Completions($modelName),
161+
'cerebras' => new \Symfony\AI\Platform\Bridge\Cerebras\Model($modelName),
162+
'perplexity' => new \Symfony\AI\Platform\Bridge\Perplexity\Perplexity($modelName),
159163
default => throw new InvalidArgumentException(\sprintf('Platform "%s" is not supported in ai:platform:invoke command', $platformName)),
160164
};
161165
}

src/ai-bundle/tests/Command/PlatformInvokeCommandTest.php

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -202,5 +202,67 @@ public function testExecuteWithUnsupportedPlatformThrowsException()
202202
'message' => 'Test message',
203203
]);
204204
}
205+
206+
public function testExecuteWithVertexAiPlatform()
207+
{
208+
$platforms = $this->createMock(ServiceLocator::class);
209+
$mockPlatform = $this->createMock(PlatformInterface::class);
210+
$platforms->method('getProvidedServices')->willReturn(['vertexai' => 'service_class']);
211+
$platforms->method('has')->with('vertexai')->willReturn(true);
212+
$platforms->method('get')->with('vertexai')->willReturn($mockPlatform);
213+
214+
$command = new PlatformInvokeCommand($platforms);
215+
216+
// This should not throw an exception since vertexai is supported
217+
$commandTester = new CommandTester($command);
218+
$commandTester->setInputs(['exit']); // Mock user input for chat
219+
220+
try {
221+
$commandTester->execute([
222+
'platform' => 'vertexai',
223+
'model' => 'gemini-pro',
224+
'message' => 'Test message',
225+
]);
226+
// If we get here without exception, the platform is properly supported
227+
$this->assertTrue(true);
228+
} catch (InvalidArgumentException $e) {
229+
if (str_contains($e->getMessage(), 'not supported')) {
230+
$this->fail('VertexAI platform should be supported but got: '.$e->getMessage());
231+
}
232+
// Other exceptions are fine (like platform invoke errors)
233+
$this->assertTrue(true);
234+
}
235+
}
236+
237+
public function testExecuteWithPerplexityPlatform()
238+
{
239+
$platforms = $this->createMock(ServiceLocator::class);
240+
$mockPlatform = $this->createMock(PlatformInterface::class);
241+
$platforms->method('getProvidedServices')->willReturn(['perplexity' => 'service_class']);
242+
$platforms->method('has')->with('perplexity')->willReturn(true);
243+
$platforms->method('get')->with('perplexity')->willReturn($mockPlatform);
244+
245+
$command = new PlatformInvokeCommand($platforms);
246+
247+
// This should not throw an "unsupported" exception since perplexity is now supported
248+
$commandTester = new CommandTester($command);
249+
$commandTester->setInputs(['exit']); // Mock user input for chat
250+
251+
try {
252+
$commandTester->execute([
253+
'platform' => 'perplexity',
254+
'model' => 'sonar',
255+
'message' => 'Test message',
256+
]);
257+
// If we get here without exception, the platform is properly supported
258+
$this->assertTrue(true);
259+
} catch (InvalidArgumentException $e) {
260+
if (str_contains($e->getMessage(), 'not supported')) {
261+
$this->fail('Perplexity platform should be supported but got: '.$e->getMessage());
262+
}
263+
// Other exceptions are fine (like platform invoke errors)
264+
$this->assertTrue(true);
265+
}
266+
}
205267
}
206268

0 commit comments

Comments
 (0)