Skip to content

Commit

Permalink
Merge pull request #293 from eliashaeussler/fix/list-supported-models
Browse files Browse the repository at this point in the history
[BUGFIX] List only supported models in `solver:list-models` command
  • Loading branch information
eliashaeussler authored Feb 8, 2025
2 parents 15a1dd0 + 62fe254 commit 0ec4ba0
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 5 deletions.
15 changes: 12 additions & 3 deletions Classes/Command/ListModelsCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
$io->title('Available GPT models');

// Filter by GPT models
$modelListResponse = \array_filter($modelListResponse, $this->isGPTModel(...));
$modelListResponse = \array_filter($modelListResponse, $this->isSupportedModel(...));
}

// Map responses to model IDs
Expand All @@ -86,9 +86,18 @@ protected function execute(Console\Input\InputInterface $input, Console\Output\O
return self::SUCCESS;
}

private function isGPTModel(Responses\Models\RetrieveResponse $response): bool
/**
* @see https://platform.openai.com/docs/models#model-endpoint-compatibility
*/
private function isSupportedModel(Responses\Models\RetrieveResponse $response): bool
{
return \str_starts_with(\strtolower($response->id), 'gpt-');
$identifier = \strtolower($response->id);

if (!\str_starts_with($identifier, 'gpt-') && !\str_starts_with($identifier, 'chatgpt-')) {
return false;
}

return !\str_contains($identifier, '-realtime') && !\str_contains($identifier, '-audio');
}

private function decorateModel(Responses\Models\RetrieveResponse $response): string
Expand Down
2 changes: 1 addition & 1 deletion Resources/Private/Frontend/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

23 changes: 22 additions & 1 deletion Tests/Unit/Command/ListModelsCommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ protected function setUp(): void
}

#[Framework\Attributes\Test]
public function executeListsAllGPTModels(): void
public function executeListsAllSupportedModels(): void
{
$response = new Psr7\Response(headers: [
'Content-Type' => 'application/json',
Expand All @@ -88,6 +88,13 @@ public function executeListsAllGPTModels(): void
]),
$this->commandTester->getDisplay(),
);
self::assertStringNotContainsString(
\implode(PHP_EOL, [
' * gpt-4o-mini-audio-preview (created at 16/12/2024)',
' * gpt-4o-realtime-preview (created at 30/09/2024)',
]),
$this->commandTester->getDisplay(),
);
self::assertStringContainsString(
\implode(PHP_EOL, [
' * gpt-3.5 (created at 28/02/2023)',
Expand Down Expand Up @@ -124,6 +131,8 @@ public function executeListsAllAvailableModels(): void
' * foo-1 (created at 01/01/2023)',
' * gpt-3.5 (created at 28/02/2023)',
' * gpt-3.5-turbo-0301 (created at 01/03/2023)',
' * gpt-4o-mini-audio-preview (created at 16/12/2024)',
' * gpt-4o-realtime-preview (created at 30/09/2024)',
]),
$this->commandTester->getDisplay(),
);
Expand Down Expand Up @@ -188,6 +197,18 @@ private function createListResponse(): array
'created' => 1641038400,
...$defaults,
],
[
'id' => 'gpt-4o-realtime-preview',
// 30/09/2024
'created' => 1727654400,
...$defaults,
],
[
'id' => 'gpt-4o-mini-audio-preview',
// 16/12/2024
'created' => 1734307200,
...$defaults,
],
],
];
}
Expand Down

0 comments on commit 0ec4ba0

Please sign in to comment.