2025-08-21 12:14:52 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace BookStack\Search\Queries;
|
|
|
|
|
|
2026-01-11 18:00:07 +00:00
|
|
|
use BookStack\Entities\Models\Entity;
|
|
|
|
|
use BookStack\Search\SearchRunner;
|
2025-08-21 12:14:52 +01:00
|
|
|
use Exception;
|
|
|
|
|
|
|
|
|
|
class LlmQueryRunner
|
|
|
|
|
{
|
|
|
|
|
public function __construct(
|
2026-01-11 18:00:07 +00:00
|
|
|
protected LlmQueryServiceProvider $vectorQueryServiceProvider,
|
|
|
|
|
protected SearchRunner $searchRunner,
|
2025-08-21 12:14:52 +01:00
|
|
|
) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2026-01-11 18:00:07 +00:00
|
|
|
* Transform the given query into an array of terms which can be used
|
|
|
|
|
* to search for documents to help answer that query.
|
|
|
|
|
* @return string[]
|
2025-08-21 12:14:52 +01:00
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
2026-01-11 18:00:07 +00:00
|
|
|
public function queryToSearchTerms(string $query): array
|
2025-08-21 12:14:52 +01:00
|
|
|
{
|
|
|
|
|
$queryService = $this->vectorQueryServiceProvider->get();
|
|
|
|
|
|
2026-01-11 18:00:07 +00:00
|
|
|
return $queryService->queryToSearchTerms($query);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Run a query against the configured LLM to produce a text response.
|
|
|
|
|
* @param Entity[] $searchResults
|
|
|
|
|
* @throws Exception
|
|
|
|
|
*/
|
|
|
|
|
public function run(string $query, array $searchResults): string
|
|
|
|
|
{
|
|
|
|
|
$queryService = $this->vectorQueryServiceProvider->get();
|
|
|
|
|
return $queryService->query($query, $searchResults);
|
2025-08-21 12:14:52 +01:00
|
|
|
}
|
|
|
|
|
}
|