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

eliashaeussler / typo3-solver / 13271925856

11 Feb 2025 08:29PM UTC coverage: 81.979% (-6.2%) from 88.153%
13271925856

Pull #295

github

web-flow
Merge 140b2a87d into dc3a40050
Pull Request #295: [FEATURE] Add Gemini as additional solution provider

8 of 90 new or added lines in 7 files covered. (8.89%)

1 existing line in 1 file now uncovered.

878 of 1071 relevant lines covered (81.98%)

2.18 hits per line

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

82.35
/Classes/ProblemSolving/Solution/Solution.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) 2023-2025 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\ProblemSolving\Solution;
25

26
use EliasHaeussler\Typo3Solver\ProblemSolving;
27
use GeminiAPI\Responses as GeminiResponses;
28
use IteratorAggregate;
29
use OpenAI\Responses as OpenAIResponses;
30

31
/**
32
 * Solution.
33
 *
34
 * @author Elias Häußler <elias@haeussler.dev>
35
 * @license GPL-2.0-or-later
36
 *
37
 * @implements IteratorAggregate<int, Model\CompletionResponse>
38
 *
39
 * @phpstan-import-type CompletionResponseArray from ProblemSolving\Solution\Model\CompletionResponse
40
 * @phpstan-type SolutionArray array{responses: array<int, CompletionResponseArray>, model: string, prompt: string}
41
 */
42
final class Solution implements \Countable, \IteratorAggregate, \JsonSerializable
43
{
44
    private ?\DateTimeInterface $createDate = null;
45
    private ?string $cacheIdentifier = null;
46

47
    /**
48
     * @param array<int, Model\CompletionResponse> $responses
49
     */
50
    public function __construct(
8✔
51
        public readonly array $responses,
52
        public readonly string $model,
53
        public readonly string $prompt,
54
    ) {}
8✔
55

56
    public static function fromOpenAIResponse(OpenAIResponses\Chat\CreateResponse $response, string $prompt): self
1✔
57
    {
58
        return new self(
1✔
59
            \array_map(
1✔
60
                Model\CompletionResponse::fromOpenAIChoice(...),
1✔
61
                $response->choices,
1✔
62
            ),
1✔
63
            $response->model,
1✔
64
            $prompt,
1✔
65
        );
1✔
66
    }
67

NEW
68
    public static function fromGeminiResponse(
×
69
        GeminiResponses\GenerateContentResponse $response,
70
        string $model,
71
        string $prompt,
72
    ): self {
NEW
73
        return new self(
×
NEW
74
            \array_map(
×
NEW
75
                Model\CompletionResponse::fromGeminiCandidate(...),
×
NEW
76
                $response->candidates,
×
NEW
77
            ),
×
NEW
78
            $model,
×
NEW
79
            $prompt,
×
NEW
80
        );
×
81
    }
82

83
    /**
84
     * @phpstan-param SolutionArray $solution
85
     */
86
    public static function fromArray(array $solution): self
1✔
87
    {
88
        $responses = \array_map(
1✔
89
            Model\CompletionResponse::fromArray(...),
1✔
90
            $solution['responses'],
1✔
91
        );
1✔
92

93
        return new self($responses, $solution['model'], $solution['prompt']);
1✔
94
    }
95

96
    public function count(): int
1✔
97
    {
98
        return \count($this->responses);
1✔
99
    }
100

101
    public function getCreateDate(): ?\DateTimeInterface
1✔
102
    {
103
        return $this->createDate;
1✔
104
    }
105

106
    public function setCreateDate(\DateTimeInterface $createDate): self
1✔
107
    {
108
        $this->createDate = $createDate;
1✔
109

110
        return $this;
1✔
111
    }
112

113
    public function getCacheIdentifier(): ?string
1✔
114
    {
115
        return $this->cacheIdentifier;
1✔
116
    }
117

118
    public function setCacheIdentifier(string $cacheIdentifier): self
1✔
119
    {
120
        $this->cacheIdentifier = $cacheIdentifier;
1✔
121

122
        return $this;
1✔
123
    }
124

125
    public function getIterator(): \Traversable
1✔
126
    {
127
        return new \ArrayIterator($this->responses);
1✔
128
    }
129

130
    /**
131
     * @phpstan-return SolutionArray
132
     */
133
    public function toArray(): array
2✔
134
    {
135
        return [
2✔
136
            'responses' => \array_map(
2✔
137
                static fn(ProblemSolving\Solution\Model\CompletionResponse $response): array => $response->toArray(),
2✔
138
                $this->responses,
2✔
139
            ),
2✔
140
            'model' => $this->model,
2✔
141
            'prompt' => $this->prompt,
2✔
142
        ];
2✔
143
    }
144

145
    /**
146
     * @phpstan-return SolutionArray
147
     */
148
    public function jsonSerialize(): array
1✔
149
    {
150
        return $this->toArray();
1✔
151
    }
152
}
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

© 2025 Coveralls, Inc