Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| ChatAiServiceFactory | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
6.60 | |
0.00% |
0 / 1 |
| create | |
60.00% |
3 / 5 |
|
0.00% |
0 / 1 |
6.60 | |||
| 1 | <?php |
| 2 | |
| 3 | declare(strict_types=1); |
| 4 | |
| 5 | namespace Mbvb1223\ChatAiMulticlient; |
| 6 | |
| 7 | use Mbvb1223\ChatAiMulticlient\Clients\OpenAIClient; |
| 8 | use Mbvb1223\ChatAiMulticlient\Clients\GeminiClient; |
| 9 | use Mbvb1223\ChatAiMulticlient\Clients\GrokClient; |
| 10 | |
| 11 | class ChatAiServiceFactory |
| 12 | { |
| 13 | public const OPENAI = 'openai'; |
| 14 | public const GEMINI = 'gemini'; |
| 15 | public const GROK = 'grok'; |
| 16 | |
| 17 | public static function create(string $service, string $apiKey): ChatAiService |
| 18 | { |
| 19 | switch (strtolower($service)) { |
| 20 | case self::OPENAI: |
| 21 | return new ChatAiService(new OpenAIClient($apiKey)); |
| 22 | case self::GEMINI: |
| 23 | return new ChatAiService(new GeminiClient($apiKey)); |
| 24 | case self::GROK: |
| 25 | return new ChatAiService(new GrokClient($apiKey)); |
| 26 | default: |
| 27 | throw new \InvalidArgumentException("Unsupported service: {$service}"); |
| 28 | } |
| 29 | } |
| 30 | } |