Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
92.31% |
12 / 13 |
|
66.67% |
2 / 3 |
CRAP | |
0.00% |
0 / 1 |
| TextSummaryGenerator | |
92.31% |
12 / 13 |
|
66.67% |
2 / 3 |
3.00 | |
0.00% |
0 / 1 |
| generateTextSummary | |
100.00% |
7 / 7 |
|
100.00% |
1 / 1 |
1 | |||
| getExpectedKeys | |
100.00% |
5 / 5 |
|
100.00% |
1 / 1 |
1 | |||
| getLoggerName | |
0.00% |
0 / 1 |
|
0.00% |
0 / 1 |
2 | |||
| 1 | <?php |
| 2 | declare(strict_types=1); |
| 3 | |
| 4 | namespace App\Service\Api\Anthropic; |
| 5 | |
| 6 | /** |
| 7 | * Class TextSummaryGenerator |
| 8 | * |
| 9 | * This class is responsible for generating summaries of text using the Anthropic |
| 10 | * API service. It interacts with the AI prompts table to retrieve prompt data |
| 11 | * and uses the AnthropicApiService to send requests and parse responses. |
| 12 | */ |
| 13 | class TextSummaryGenerator extends AbstractAnthropicGenerator |
| 14 | { |
| 15 | /** |
| 16 | * Generates a text summary using the Anthropic API. |
| 17 | * |
| 18 | * @param string $context The context for the text summary. |
| 19 | * @param string $text The text to be summarized. |
| 20 | * @return array The generated summary and key points. |
| 21 | */ |
| 22 | public function generateTextSummary(string $context, string $text): array |
| 23 | { |
| 24 | $promptData = $this->getPromptData('text_summary'); |
| 25 | $payload = $this->createPayload($promptData, [ |
| 26 | 'context' => $context, |
| 27 | 'text' => $text, |
| 28 | ]); |
| 29 | |
| 30 | $result = $this->sendApiRequest($payload); |
| 31 | |
| 32 | return $this->ensureExpectedKeys($result); |
| 33 | } |
| 34 | |
| 35 | /** |
| 36 | * Gets the expected keys for the API response. |
| 37 | * |
| 38 | * @return array Array of expected response keys. |
| 39 | */ |
| 40 | protected function getExpectedKeys(): array |
| 41 | { |
| 42 | return [ |
| 43 | 'summary', |
| 44 | 'key_points', |
| 45 | 'lede', |
| 46 | ]; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * Gets the logger name for this generator. |
| 51 | * |
| 52 | * @return string The logger name. |
| 53 | */ |
| 54 | protected function getLoggerName(): string |
| 55 | { |
| 56 | return 'Text Summary Generator'; |
| 57 | } |
| 58 | } |