• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

eliashaeussler / typo3-solver / 8670530347

13 Apr 2024 02:49AM UTC coverage: 87.107%. Remained the same
8670530347

push

github

web-flow
[TASK] Update all dependencies

858 of 985 relevant lines covered (87.11%)

6.71 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

100.0
/Classes/Command/ListModelsCommand.php
1
<?php
2

3
declare(strict_types=1);
4

5
/*
6
 * This file is part of the TYPO3 CMS extension "solver".
7
 *
8
 * Copyright (C) 2024 Elias Häußler <elias@haeussler.dev>
9
 *
10
 * This program is free software: you can redistribute it and/or modify
11
 * it under the terms of the GNU General Public License as published by
12
 * the Free Software Foundation, either version 2 of the License, or
13
 * (at your option) any later version.
14
 *
15
 * This program is distributed in the hope that it will be useful,
16
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18
 * GNU General Public License for more details.
19
 *
20
 * You should have received a copy of the GNU General Public License
21
 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22
 */
23

24
namespace EliasHaeussler\Typo3Solver\Command;
25

26
use OpenAI\Client;
27
use OpenAI\Responses;
28
use Symfony\Component\Console;
29

30
use function array_filter;
31
use function array_map;
32
use function date;
33
use function sort;
34
use function sprintf;
35
use function str_starts_with;
36
use function strtolower;
37

38
/**
39
 * ListModelsCommand
40
 *
41
 * @author Elias Häußler <elias@haeussler.dev>
42
 * @license GPL-2.0-or-later
43
 */
44
final class ListModelsCommand extends Console\Command\Command
45
{
46
    public function __construct(
2✔
47
        private readonly Client $client,
48
    ) {
49
        parent::__construct('solver:list-models');
2✔
50
    }
51

52
    protected function configure(): void
2✔
53
    {
54
        $this->addOption(
2✔
55
            'all',
2✔
56
            'a',
2✔
57
            Console\Input\InputOption::VALUE_NONE,
2✔
58
            'List all available models, even those which cannot be used',
2✔
59
        );
2✔
60
    }
61

62
    protected function execute(Console\Input\InputInterface $input, Console\Output\OutputInterface $output): int
2✔
63
    {
64
        $io = new Console\Style\SymfonyStyle($input, $output);
2✔
65
        $listAll = $input->getOption('all');
2✔
66

67
        // Retrieve all available models
68
        $modelListResponse = $this->client->models()->list()->data;
2✔
69

70
        if ($listAll) {
2✔
71
            $io->title('Available OpenAI models');
1✔
72
        } else {
73
            $io->title('Available GPT models');
1✔
74

75
            // Filter by GPT models
76
            $modelListResponse = array_filter($modelListResponse, $this->isGPTModel(...));
1✔
77
        }
78

79
        // Map responses to model IDs
80
        $models = array_map(
2✔
81
            $this->decorateModel(...),
2✔
82
            $modelListResponse,
2✔
83
        );
2✔
84

85
        sort($models);
2✔
86

87
        $io->listing($models);
2✔
88

89
        if ($listAll) {
2✔
90
            $io->writeln('💡 <comment>Only GPT models can be used with this extension.</comment>');
1✔
91
            $io->newLine();
1✔
92
        }
93

94
        return self::SUCCESS;
2✔
95
    }
96

97
    private function isGPTModel(Responses\Models\RetrieveResponse $response): bool
1✔
98
    {
99
        return str_starts_with(strtolower($response->id), 'gpt-');
1✔
100
    }
101

102
    private function decorateModel(Responses\Models\RetrieveResponse $response): string
2✔
103
    {
104
        return sprintf('%s <fg=gray>(created at %s)</>', $response->id, date('d/m/Y', $response->created));
2✔
105
    }
106
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc