]> BookStack Code Mirror - bookstack/blob - app/Search/Vectors/VectorQueryServiceProvider.php
Vectors: Added command to regenerate for all
[bookstack] / app / Search / Vectors / VectorQueryServiceProvider.php
1 <?php
2
3 namespace BookStack\Search\Vectors;
4
5 use BookStack\Http\HttpRequestService;
6 use BookStack\Search\Vectors\Services\OpenAiVectorQueryService;
7 use BookStack\Search\Vectors\Services\VectorQueryService;
8
9 class VectorQueryServiceProvider
10 {
11     public function __construct(
12         protected HttpRequestService $http,
13     ) {
14     }
15
16     public function get(): VectorQueryService
17     {
18         $service = $this->getServiceName();
19
20         if ($service === 'openai') {
21             return new OpenAiVectorQueryService(config('services.openai'), $this->http);
22         }
23
24         throw new \Exception("No '{$service}' LLM service found");
25     }
26
27     protected static function getServiceName(): string
28     {
29         return strtolower(config('services.llm'));
30     }
31
32     public static function isEnabled(): bool
33     {
34         return !empty(static::getServiceName());
35     }
36 }