Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
CRAP
100.00% covered (success)
100.00%
1 / 1
AiClient
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
100.00% covered (success)
100.00%
1 / 1
 ask
n/a
0 / 0
n/a
0 / 0
0
 create
100.00% covered (success)
100.00%
6 / 6
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2namespace Apie\AiInstructor;
3
4use cebe\openapi\spec\Schema;
5use Symfony\Contracts\HttpClient\HttpClientInterface;
6
7abstract class AiClient
8{
9    abstract public function ask(string $systemMessage, string $prompt, Schema $schema, ?string $model = null): string;
10    
11    public static function create(
12        ?HttpClientInterface $client = null,
13        string $baseUrl = 'http://localhost:11434',
14        string $apiKey = 'ignored'
15    ): AiClient {
16        if (str_starts_with($baseUrl, 'https://api.openai.com/v1')) {
17            return new OpenAiClient(
18                $client,
19                $apiKey
20            );
21        }
22
23        return new OllamaClient($client, $baseUrl);
24    }
25}