]> BookStack Code Mirror - bookstack/blob - app/Search/Vectors/VectorQueryServiceProvider.php
Vectors: Built content vector indexing system
[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             $key = config('services.openai.key');
22             $endpoint = config('services.openai.endpoint');
23             return new OpenAiVectorQueryService($endpoint, $key, $this->http);
24         }
25
26         throw new \Exception("No '{$service}' LLM service found");
27     }
28
29     protected static function getServiceName(): string
30     {
31         return strtolower(config('services.llm'));
32     }
33
34     public static function isEnabled(): bool
35     {
36         return !empty(static::getServiceName());
37     }
38 }