From a72d58b7011b4549eb509750ae03f75e7aa3780a Mon Sep 17 00:00:00 2001 From: aB0t Date: Thu, 13 Jul 2023 19:31:35 +0200 Subject: [PATCH] update 2023-07-13 19:31:35 --- README.md | 3 + .../code.php | 1 + .../code.power | 1 + .../README.md | 4 +- .../code.php | 6 +- .../code.power | 6 +- .../README.md | 20 ++++- .../code.php | 61 +++++++++++++-- .../code.power | 61 +++++++++++++-- .../README.md | 69 +++++++++------- .../code.php | 26 ++++++- .../code.power | 26 ++++++- .../README.md | 8 ++ .../code.php | 23 +++++- .../code.power | 22 +++++- .../settings.json | 4 + .../README.md | 54 +++++++++++++ .../code.php | 78 +++++++++++++++++++ .../code.power | 51 ++++++++++++ .../settings.json | 27 +++++++ .../README.md | 10 ++- .../code.php | 47 +++++++---- .../code.power | 44 +++++++---- .../settings.json | 8 +- super-powers.json | 11 +++ 25 files changed, 582 insertions(+), 89 deletions(-) create mode 100644 src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/README.md create mode 100644 src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.php create mode 100644 src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.power create mode 100644 src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/settings.json diff --git a/README.md b/README.md index 303fb31..84c0f49 100644 --- a/README.md +++ b/README.md @@ -33,6 +33,9 @@ This repository contains an index (see below) of all the approved powers within - **final class Watcher** | [Details](src/f815fb33-f721-48a5-a84e-53f1986e8881) | [Code](src/f815fb33-f721-48a5-a84e-53f1986e8881/code.php) | [Settings](src/f815fb33-f721-48a5-a84e-53f1986e8881/settings.json) | Super__f815fb33_f721_48a5_a84e_53f1986e8881__Power - **class Config** | [Details](src/71075f03-4e77-4fc0-840a-ef55fd9260b2) | [Code](src/71075f03-4e77-4fc0-840a-ef55fd9260b2/code.php) | [Settings](src/71075f03-4e77-4fc0-840a-ef55fd9260b2/settings.json) | Super__71075f03_4e77_4fc0_840a_ef55fd9260b2__Power - **class Table** | [Details](src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068) | [Code](src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/code.php) | [Settings](src/ff8d5fdb-2d1f-4178-bd18-a43b8efd1068/settings.json) | Super__ff8d5fdb_2d1f_4178_bd18_a43b8efd1068__Power +- **Namespace**: [VDM\Joomla\GetBible\AI](#vdm-joomla-getbible-ai) + + - **final class Worker** | [Details](src/ed16a9c4-e026-4d16-be60-81892ce7c6a9) | [Code](src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.php) | [Settings](src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/settings.json) | Super__ed16a9c4_e026_4d16_be60_81892ce7c6a9__Power - **Namespace**: [VDM\Joomla\GetBible\Abstraction](#vdm-joomla-getbible-abstraction) - **abstract class Api** | [Details](src/7b490e63-8d1f-46de-a0c4-154272fd5d7f) | [Code](src/7b490e63-8d1f-46de-a0c4-154272fd5d7f/code.php) | [Settings](src/7b490e63-8d1f-46de-a0c4-154272fd5d7f/settings.json) | Super__7b490e63_8d1f_46de_a0c4_154272fd5d7f__Power diff --git a/src/3439e63b-d8f1-42ce-a765-60d56b1fbe21/code.php b/src/3439e63b-d8f1-42ce-a765-60d56b1fbe21/code.php index 4da5019..448c592 100644 --- a/src/3439e63b-d8f1-42ce-a765-60d56b1fbe21/code.php +++ b/src/3439e63b-d8f1-42ce-a765-60d56b1fbe21/code.php @@ -183,6 +183,7 @@ class Data implements ServiceProviderInterface public function getResponse(Container $container): Response { return new Response( + $container->get('GetBible.Translation'), $container->get('GetBible.Chapter'), $container->get('GetBible.Prompt'), $container->get('GetBible.Load'), diff --git a/src/3439e63b-d8f1-42ce-a765-60d56b1fbe21/code.power b/src/3439e63b-d8f1-42ce-a765-60d56b1fbe21/code.power index b890430..55d7288 100644 --- a/src/3439e63b-d8f1-42ce-a765-60d56b1fbe21/code.power +++ b/src/3439e63b-d8f1-42ce-a765-60d56b1fbe21/code.power @@ -150,6 +150,7 @@ public function getResponse(Container $container): Response { return new Response( + $container->get('GetBible.Translation'), $container->get('GetBible.Chapter'), $container->get('GetBible.Prompt'), $container->get('GetBible.Load'), diff --git a/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/README.md b/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/README.md index b5b8df3..e482b53 100644 --- a/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/README.md +++ b/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/README.md @@ -17,7 +17,7 @@ class Prompt << (F,LightGreen) >> #Green { + __construct(Load $load, Config $config) + getIntegration(?string $guid = null) : ?int + getCacheBehaviour(?string $guid = null) : ?int - + getCacheCapacity(?string $guid = null) : ?int + + getCacheCapacity(?string $guid = null) : int + get(?string $guid = null) : ?object - active(?string $guid = null) : bool } @@ -46,7 +46,7 @@ note right of Prompt::getCacheCapacity Get the cache capacity since: 2.0.1 - return: ?int + return: int end note note right of Prompt::get diff --git a/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/code.php b/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/code.php index 85a4f3d..25ecd12 100644 --- a/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/code.php +++ b/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/code.php @@ -102,17 +102,17 @@ final class Prompt * * @param string $guid The prompt guid. * - * @return int|null The number to cache + * @return int The number to cache * @since 2.0.1 */ - public function getCacheCapacity(?string $guid = null): ?int + public function getCacheCapacity(?string $guid = null): int { if ($this->active($guid)) { return (int) $this->get($guid)->cache_capacity; } - return null; + return 1; } /** diff --git a/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/code.power b/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/code.power index b6f2d62..3e352a0 100644 --- a/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/code.power +++ b/src/3f785d63-a592-463d-9f5f-b2b5a8edd561/code.power @@ -77,17 +77,17 @@ * * @param string $guid The prompt guid. * - * @return int|null The number to cache + * @return int The number to cache * @since 2.0.1 */ - public function getCacheCapacity(?string $guid = null): ?int + public function getCacheCapacity(?string $guid = null): int { if ($this->active($guid)) { return (int) $this->get($guid)->cache_capacity; } - return null; + return 1; } /** diff --git a/src/44c15b17-e096-47c0-8769-42ea9b692cb2/README.md b/src/44c15b17-e096-47c0-8769-42ea9b692cb2/README.md index 9b485e3..d09b9de 100644 --- a/src/44c15b17-e096-47c0-8769-42ea9b692cb2/README.md +++ b/src/44c15b17-e096-47c0-8769-42ea9b692cb2/README.md @@ -18,7 +18,9 @@ class Response << (F,LightGreen) >> #Green { # Config $config # array $responses + __construct(Translation $translation, Chapter $chapter, ...) - + get(?string $guid = null) : ?object + + get(?string $guid = null) : ?array + + enough(?string $guid = null) : bool + + total(?string $guid = null) : int } note right of Response::__construct @@ -38,7 +40,21 @@ note right of Response::get Get the responses since: 2.0.1 - return: ?object + return: ?array +end note + +note right of Response::enough + is there enough response messages + + since: 2.0.1 + return: bool +end note + +note right of Response::total + Get the total responses in cache + + since: 2.0.1 + return: int end note @enduml diff --git a/src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.php b/src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.php index 76077c5..2233fd5 100644 --- a/src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.php +++ b/src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.php @@ -99,20 +99,20 @@ final class Response * * @param string|null $guid The prompt guid. * - * @return object|null True on success + * @return array|null True on success * @since 2.0.1 */ - public function get(?string $guid = null): ?object + public function get(?string $guid = null): ?array { // get the cache behaviour - $cache = $this->prompt->getCacheBehaviour(); + $cache = $this->prompt->getCacheBehaviour($guid); if (empty($cache) || ($cache != 1 && $cache != 2)) { return null; } - // get from cache if not found + // load the prompt GUID $guid = $guid ?? $this->config->get('prompt'); if ($guid === null) @@ -124,7 +124,7 @@ final class Response { $this->responses[$guid] = null; - $query = ['prompt' => $guid]; + $query = ['prompt' => $guid, 'published' => 1]; // Basic Caching - Words/Language if ($cache == 1) @@ -143,7 +143,7 @@ final class Response $query['verse'] = $this->chapter->getVerseNumber() ?? 'none__found'; // get the integration - $integration = $this->prompt->getIntegration(); + $integration = $this->prompt->getIntegration($guid); if ($integration == 1 || $integration == 3) { $query['words'] = $this->chapter->getWordNumber() ?? 'none__found'; @@ -157,7 +157,8 @@ final class Response { $response->messages = $this->load->items([ 'prompt' => $guid, - 'open_ai_response' => $response->guid + 'open_ai_response' => $response->guid, + 'published' => 1 ], 'open_ai_message'); } @@ -168,6 +169,52 @@ final class Response } return $this->responses[$guid]; + } + + /** + * is there enough response messages + * + * @param string|null $guid The prompt guid. + * + * @return bool true if there is enough messages + * @since 2.0.1 + */ + public function enough(?string $guid = null): bool + { + return ($this->total($guid) >= $this->prompt->getCacheCapacity($guid)); + } + + /** + * Get the total responses in cache + * + * @param string|null $guid The prompt guid. + * + * @return int Number responses from OpenAI + * @since 2.0.1 + */ + public function total(?string $guid = null): int + { + $total = 0; + if (($responses = $this->get($guid)) === null) + { + return $total; + } + + foreach ($responses as $response) + { + if (!empty($response->messages) && is_array($response->messages)) + { + foreach ($response->messages as $message) + { + if (isset($message->source) && $message->source == 2) + { + $total++; + } + } + } + } + + return $total; } } diff --git a/src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.power b/src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.power index 3e245c6..c08d7e2 100644 --- a/src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.power +++ b/src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.power @@ -71,20 +71,20 @@ * * @param string|null $guid The prompt guid. * - * @return object|null True on success + * @return array|null True on success * @since 2.0.1 */ - public function get(?string $guid = null): ?object + public function get(?string $guid = null): ?array { // get the cache behaviour - $cache = $this->prompt->getCacheBehaviour(); + $cache = $this->prompt->getCacheBehaviour($guid); if (empty($cache) || ($cache != 1 && $cache != 2)) { return null; } - // get from cache if not found + // load the prompt GUID $guid = $guid ?? $this->config->get('prompt'); if ($guid === null) @@ -96,7 +96,7 @@ { $this->responses[$guid] = null; - $query = ['prompt' => $guid]; + $query = ['prompt' => $guid, 'published' => 1]; // Basic Caching - Words/Language if ($cache == 1) @@ -115,7 +115,7 @@ $query['verse'] = $this->chapter->getVerseNumber() ?? 'none__found'; // get the integration - $integration = $this->prompt->getIntegration(); + $integration = $this->prompt->getIntegration($guid); if ($integration == 1 || $integration == 3) { $query['words'] = $this->chapter->getWordNumber() ?? 'none__found'; @@ -129,7 +129,8 @@ { $response->messages = $this->load->items([ 'prompt' => $guid, - 'open_ai_response' => $response->guid + 'open_ai_response' => $response->guid, + 'published' => 1 ], 'open_ai_message'); } @@ -140,4 +141,50 @@ } return $this->responses[$guid]; + } + + /** + * is there enough response messages + * + * @param string|null $guid The prompt guid. + * + * @return bool true if there is enough messages + * @since 2.0.1 + */ + public function enough(?string $guid = null): bool + { + return ($this->total($guid) >= $this->prompt->getCacheCapacity($guid)); + } + + /** + * Get the total responses in cache + * + * @param string|null $guid The prompt guid. + * + * @return int Number responses from OpenAI + * @since 2.0.1 + */ + public function total(?string $guid = null): int + { + $total = 0; + if (($responses = $this->get($guid)) === null) + { + return $total; + } + + foreach ($responses as $response) + { + if (!empty($response->messages) && is_array($response->messages)) + { + foreach ($response->messages as $message) + { + if (isset($message->source) && $message->source == 2) + { + $total++; + } + } + } + } + + return $total; } \ No newline at end of file diff --git a/src/4a4c786d-51f4-421a-aa61-262dfd071880/README.md b/src/4a4c786d-51f4-421a-aa61-262dfd071880/README.md index f132110..e6ed928 100644 --- a/src/4a4c786d-51f4-421a-aa61-262dfd071880/README.md +++ b/src/4a4c786d-51f4-421a-aa61-262dfd071880/README.md @@ -19,6 +19,7 @@ class Chapter << (F,LightGreen) >> #Green { # array $validVerses # array $sequential + __construct(Load $load, Config $config, ...) + + getBookNumber(?string $abbreviation = null, ?int $book = null, ...) : string + getBookName(?string $abbreviation = null, ?int $book = null, ...) : string + getChapterNumber(?string $abbreviation = null, ?int $book = null, ...) : string + getChapterName(?string $abbreviation = null, ?int $book = null, ...) : string @@ -61,7 +62,19 @@ note right of Chapter::__construct StringHelper $stringHelper end note -note left of Chapter::getBookName +note left of Chapter::getBookNumber + Get the book number + + since: 2.0.1 + return: string + + arguments: + ?string $abbreviation = null + ?int $book = null + ?int $chapter = null +end note + +note right of Chapter::getBookName Get the book name since: 2.0.1 @@ -73,7 +86,7 @@ note left of Chapter::getBookName ?int $chapter = null end note -note right of Chapter::getChapterNumber +note left of Chapter::getChapterNumber Get the chapter number since: 2.0.1 @@ -85,7 +98,7 @@ note right of Chapter::getChapterNumber ?int $chapter = null end note -note left of Chapter::getChapterName +note right of Chapter::getChapterName Get the chapter name since: 2.0.1 @@ -97,7 +110,7 @@ note left of Chapter::getChapterName ?int $chapter = null end note -note right of Chapter::getChapterText +note left of Chapter::getChapterText Get the chapter text since: 2.0.1 @@ -109,7 +122,7 @@ note right of Chapter::getChapterText ?int $chapter = null end note -note left of Chapter::getVerseNumber +note right of Chapter::getVerseNumber Get the verse number/s since: 2.0.1 @@ -121,7 +134,7 @@ note left of Chapter::getVerseNumber ?int $chapter = null end note -note right of Chapter::getVerseName +note left of Chapter::getVerseName Get the verse name since: 2.0.1 @@ -133,7 +146,7 @@ note right of Chapter::getVerseName ?int $chapter = null end note -note left of Chapter::getVerseText +note right of Chapter::getVerseText Get the verse text since: 2.0.1 @@ -145,7 +158,7 @@ note left of Chapter::getVerseText ?int $chapter = null end note -note right of Chapter::getWordNumber +note left of Chapter::getWordNumber Get the word number/s since: 2.0.1 @@ -157,7 +170,7 @@ note right of Chapter::getWordNumber ?int $chapter = null end note -note left of Chapter::getWordText +note right of Chapter::getWordText Get the word text since: 2.0.1 @@ -169,7 +182,7 @@ note left of Chapter::getWordText ?int $chapter = null end note -note right of Chapter::get +note left of Chapter::get Get the chapter since: 2.0.1 @@ -181,7 +194,7 @@ note right of Chapter::get ?int $chapter = null end note -note left of Chapter::generateCacheKey +note right of Chapter::generateCacheKey Generates a cache key based on the abbreviation, book, and chapter since: 2.0.1 @@ -193,7 +206,7 @@ note left of Chapter::generateCacheKey int $chapter end note -note right of Chapter::loadChapterData +note left of Chapter::loadChapterData Loads the chapter data from the database and updates the cache since: 2.0.1 @@ -205,7 +218,7 @@ note right of Chapter::loadChapterData int $chapter end note -note left of Chapter::active +note right of Chapter::active Check if this chapter is active since: 2.0.1 @@ -217,7 +230,7 @@ note left of Chapter::active ?int $chapter = null end note -note right of Chapter::processVerses +note left of Chapter::processVerses Processes the verses to extract the verse text since: 2.0.1 @@ -229,7 +242,7 @@ note right of Chapter::processVerses ?int $chapter end note -note left of Chapter::processVersesArray +note right of Chapter::processVersesArray Processes the verses to extract the verse text since: 2.0.1 @@ -241,49 +254,49 @@ note left of Chapter::processVersesArray ?int $chapter = null end note -note right of Chapter::extractVerseNumbers +note left of Chapter::extractVerseNumbers Extracts the verse numbers from the input string since: 2.0.1 return: array end note -note left of Chapter::validateSelectedVerses +note right of Chapter::validateSelectedVerses Validate that these verse numbers exist in chapter since: 2.0.1 return: string end note -note right of Chapter::getValidVerseRange +note left of Chapter::getValidVerseRange Get the valid verse range since: 2.0.1 return: ?array end note -note left of Chapter::isValidWordNumber +note right of Chapter::isValidWordNumber Check if a word exist in a verse since: 2.0.1 return: bool end note -note right of Chapter::getTextFromVerses +note left of Chapter::getTextFromVerses Get the verse text from the verses array based on the verse numbers since: 2.0.1 return: array end note -note left of Chapter::getArrayFromVerses +note right of Chapter::getArrayFromVerses Get the verses array based on the verse numbers since: 2.0.1 return: array end note -note right of Chapter::getWordNumberArray +note left of Chapter::getWordNumberArray Get the word number/s since: 2.0.1 @@ -295,42 +308,42 @@ note right of Chapter::getWordNumberArray ?int $chapter = null end note -note left of Chapter::splitAndTrim +note right of Chapter::splitAndTrim Split verse or words by '-' and trim each element. since: 2.0.1 return: array end note -note right of Chapter::buildWordNumberArray +note left of Chapter::buildWordNumberArray Build word number array from verse and words. since: 2.0.1 return: array end note -note left of Chapter::wordNumberArrayToString +note right of Chapter::wordNumberArrayToString Converts word number array to string. since: 2.0.1 return: string end note -note right of Chapter::buildWordArray +note left of Chapter::buildWordArray Build word array from verse and words. since: 2.0.1 return: array end note -note left of Chapter::wordArrayToString +note right of Chapter::wordArrayToString Converts word array to string. since: 2.0.1 return: string end note -note right of Chapter::isSequential +note left of Chapter::isSequential Check if an array values is sequential. since: 2.0.1 diff --git a/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.php b/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.php index b8589f8..1e4054d 100644 --- a/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.php +++ b/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.php @@ -99,6 +99,26 @@ final class Chapter $this->stringHelper = $stringHelper; } + /** + * Get the book number + * + * @param string|null $abbreviation The translation abbreviation. + * @param int|null $book The book number. + * @param int|null $chapter The chapter number. + * + * @return string The book number + * @since 2.0.1 + */ + public function getBookNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string + { + if ($this->active($abbreviation, $book, $chapter)) + { + return $this->get($abbreviation, $book, $chapter)->book_nr ?? ''; + } + + return ''; + } + /** * Get the book name * @@ -327,7 +347,8 @@ final class Chapter */ public function getWordNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string { - if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || !$this->active($abbreviation, $book, $chapter)) + if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || + !$this->active($abbreviation, $book, $chapter)) { return ''; } @@ -377,7 +398,8 @@ final class Chapter */ public function getWordText(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string { - if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || !$this->active($abbreviation, $book, $chapter)) + if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || + !$this->active($abbreviation, $book, $chapter)) { return ''; } diff --git a/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.power b/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.power index 6ecf03d..67828ba 100644 --- a/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.power +++ b/src/4a4c786d-51f4-421a-aa61-262dfd071880/code.power @@ -72,6 +72,26 @@ $this->stringHelper = $stringHelper; } + /** + * Get the book number + * + * @param string|null $abbreviation The translation abbreviation. + * @param int|null $book The book number. + * @param int|null $chapter The chapter number. + * + * @return string The book number + * @since 2.0.1 + */ + public function getBookNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string + { + if ($this->active($abbreviation, $book, $chapter)) + { + return $this->get($abbreviation, $book, $chapter)->book_nr ?? ''; + } + + return ''; + } + /** * Get the book name * @@ -300,7 +320,8 @@ */ public function getWordNumber(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string { - if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || !$this->active($abbreviation, $book, $chapter)) + if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || + !$this->active($abbreviation, $book, $chapter)) { return ''; } @@ -350,7 +371,8 @@ */ public function getWordText(?string $abbreviation = null,?int $book = null, ?int $chapter = null): string { - if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || !$this->active($abbreviation, $book, $chapter)) + if (($this->prompt->getIntegration() != 1 && $this->prompt->getIntegration() != 3) || + !$this->active($abbreviation, $book, $chapter)) { return ''; } diff --git a/src/b2c9493f-692b-426b-af22-c6865f76c2bb/README.md b/src/b2c9493f-692b-426b-af22-c6865f76c2bb/README.md index 1af1596..731a53f 100644 --- a/src/b2c9493f-692b-426b-af22-c6865f76c2bb/README.md +++ b/src/b2c9493f-692b-426b-af22-c6865f76c2bb/README.md @@ -13,6 +13,7 @@ class AI #Gold { + register(Container $container) : void + getAI(Container $container) : GetBible + + getWorker(Container $container) : Worker } note right of AI::register @@ -28,6 +29,13 @@ note right of AI::getAI since: 3.2.0 return: GetBible end note + +note right of AI::getWorker + Get the Worker AI class + + since: 3.2.0 + return: Worker +end note @enduml ``` diff --git a/src/b2c9493f-692b-426b-af22-c6865f76c2bb/code.php b/src/b2c9493f-692b-426b-af22-c6865f76c2bb/code.php index 78df1aa..fe4c117 100644 --- a/src/b2c9493f-692b-426b-af22-c6865f76c2bb/code.php +++ b/src/b2c9493f-692b-426b-af22-c6865f76c2bb/code.php @@ -15,6 +15,7 @@ namespace VDM\Joomla\GetBible\Service; use Joomla\DI\Container; use Joomla\DI\ServiceProviderInterface; use VDM\Joomla\GetBible\AI as GetBible; +use VDM\Joomla\GetBible\AI\Worker; /** @@ -36,6 +37,9 @@ class AI implements ServiceProviderInterface { $container->alias(GetBible::class, 'GetBible.AI') ->share('GetBible.AI', [$this, 'getAI'], true); + + $container->alias(Worker::class, 'GetBible.AI.Worker') + ->share('GetBible.AI.Worker', [$this, 'getWorker'], true); } /** @@ -50,7 +54,24 @@ class AI implements ServiceProviderInterface { return new GetBible( $container->get('GetBible.Prompt'), - $container->get('GetBible.Placeholders') + $container->get('GetBible.Response'), + $container->get('GetBible.AI.Worker') + ); + } + + /** + * Get the Worker AI class + * + * @param Container $container The DI container. + * + * @return Worker + * @since 3.2.0 + */ + public function getWorker(Container $container): Worker + { + return new Worker( + $container->get('GetBible.Prompt'), + $container->get('GetBible.Response') ); } } diff --git a/src/b2c9493f-692b-426b-af22-c6865f76c2bb/code.power b/src/b2c9493f-692b-426b-af22-c6865f76c2bb/code.power index 598bcf8..7861fcc 100644 --- a/src/b2c9493f-692b-426b-af22-c6865f76c2bb/code.power +++ b/src/b2c9493f-692b-426b-af22-c6865f76c2bb/code.power @@ -10,6 +10,9 @@ { $container->alias(GetBible::class, 'GetBible.AI') ->share('GetBible.AI', [$this, 'getAI'], true); + + $container->alias(Worker::class, 'GetBible.AI.Worker') + ->share('GetBible.AI.Worker', [$this, 'getWorker'], true); } /** @@ -24,6 +27,23 @@ { return new GetBible( $container->get('GetBible.Prompt'), - $container->get('GetBible.Placeholders') + $container->get('GetBible.Response'), + $container->get('GetBible.AI.Worker') + ); + } + + /** + * Get the Worker AI class + * + * @param Container $container The DI container. + * + * @return Worker + * @since 3.2.0 + */ + public function getWorker(Container $container): Worker + { + return new Worker( + $container->get('GetBible.Prompt'), + $container->get('GetBible.Response') ); } \ No newline at end of file diff --git a/src/b2c9493f-692b-426b-af22-c6865f76c2bb/settings.json b/src/b2c9493f-692b-426b-af22-c6865f76c2bb/settings.json index 7530cf0..33df5b3 100644 --- a/src/b2c9493f-692b-426b-af22-c6865f76c2bb/settings.json +++ b/src/b2c9493f-692b-426b-af22-c6865f76c2bb/settings.json @@ -15,6 +15,10 @@ "use_selection0": { "use": "f3757646-bc63-4f11-98c1-a2663180ab5e", "as": "GetBible" + }, + "use_selection1": { + "use": "ed16a9c4-e026-4d16-be60-81892ce7c6a9", + "as": "default" } }, "namespace": "VDM\\Joomla\\GetBible\\Service.AI", diff --git a/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/README.md b/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/README.md new file mode 100644 index 0000000..c868550 --- /dev/null +++ b/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/README.md @@ -0,0 +1,54 @@ +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# final class Worker (Details) +> namespace: **VDM\Joomla\GetBible\AI** +```uml +@startuml +class Worker << (F,LightGreen) >> #Green { + # Prompt $prompt + # Response $response + + __construct(Prompt $prompt, Response $response) + + get() : ?array + + response() : ?array +} + +note right of Worker::__construct + Constructor + + since: 2.0.1 +end note + +note right of Worker::get + Get the Open AI response + + since: 2.0.1 + return: ?array +end note + +note right of Worker::response + Get the Open AI response + + since: 2.0.1 + return: ?array +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.php b/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.php new file mode 100644 index 0000000..6ba0dd2 --- /dev/null +++ b/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.php @@ -0,0 +1,78 @@ + + * @git GetBible + * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved. + * @license GNU General Public License version 2 or later; see LICENSE.txt + */ + +namespace VDM\Joomla\GetBible\AI; + + +use VDM\Joomla\GetBible\Data\Prompt; +use VDM\Joomla\GetBible\Data\Response; + + +/** + * The GetBible AI Worker + * + * @since 2.0.1 + */ +final class Worker +{ + /** + * The Prompt class + * + * @var Prompt + * @since 2.0.1 + */ + protected Prompt $prompt; + + /** + * The Response class + * + * @var Response + * @since 2.0.1 + */ + protected Response $response; + + /** + * Constructor + * + * @param Prompt $prompt The prompt object. + * @param Response $response The response object. + * + * @since 2.0.1 + */ + public function __construct(Prompt $prompt, Response $response) + { + $this->prompt = $prompt; + $this->response = $response; + } + + /** + * Get the Open AI response + * + * @return array|null Array of response messages + * @since 2.0.1 + */ + public function get(): ?array + { + return ['worker:get']; + } + + /** + * Get the Open AI response + * + * @return array|null Array of response messages + * @since 2.0.1 + */ + public function response(): ?array + { + return ['worker:response']; + } +} + diff --git a/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.power b/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.power new file mode 100644 index 0000000..8175d33 --- /dev/null +++ b/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.power @@ -0,0 +1,51 @@ + /** + * The Prompt class + * + * @var Prompt + * @since 2.0.1 + */ + protected Prompt $prompt; + + /** + * The Response class + * + * @var Response + * @since 2.0.1 + */ + protected Response $response; + + /** + * Constructor + * + * @param Prompt $prompt The prompt object. + * @param Response $response The response object. + * + * @since 2.0.1 + */ + public function __construct(Prompt $prompt, Response $response) + { + $this->prompt = $prompt; + $this->response = $response; + } + + /** + * Get the Open AI response + * + * @return array|null Array of response messages + * @since 2.0.1 + */ + public function get(): ?array + { + return ['worker:get']; + } + + /** + * Get the Open AI response + * + * @return array|null Array of response messages + * @since 2.0.1 + */ + public function response(): ?array + { + return ['worker:response']; + } \ No newline at end of file diff --git a/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/settings.json b/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/settings.json new file mode 100644 index 0000000..20b16e2 --- /dev/null +++ b/src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/settings.json @@ -0,0 +1,27 @@ +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "ed16a9c4-e026-4d16-be60-81892ce7c6a9", + "implements": null, + "load_selection": null, + "name": "Worker", + "power_version": "1.0.0", + "system_name": "Joomla.GetBible.AI.Worker", + "type": "final class", + "use_selection": { + "use_selection0": { + "use": "3f785d63-a592-463d-9f5f-b2b5a8edd561", + "as": "default" + }, + "use_selection1": { + "use": "44c15b17-e096-47c0-8769-42ea9b692cb2", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\GetBible\\AI.Worker", + "description": "The GetBible AI Worker\r\n\r\n@since 2.0.1", + "licensing_template": "\/**\r\n * @package GetBible\r\n *\r\n * @created 30th May, 2023\r\n * @author Llewellyn van der Merwe \r\n * @git GetBible \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/f3757646-bc63-4f11-98c1-a2663180ab5e/README.md b/src/f3757646-bc63-4f11-98c1-a2663180ab5e/README.md index e7a9d2c..c45cf8d 100644 --- a/src/f3757646-bc63-4f11-98c1-a2663180ab5e/README.md +++ b/src/f3757646-bc63-4f11-98c1-a2663180ab5e/README.md @@ -12,8 +12,9 @@ @startuml class AI << (F,LightGreen) >> #Green { # Prompt $prompt - # Placeholders $placeholders - + __construct(Prompt $prompt, Placeholders $placeholders) + # Response $response + # Worker $worker + + __construct(Prompt $prompt, Response $response, ...) + get() : ?array } @@ -21,6 +22,11 @@ note right of AI::__construct Constructor since: 2.0.1 + + arguments: + Prompt $prompt + Response $response + Worker $worker end note note right of AI::get diff --git a/src/f3757646-bc63-4f11-98c1-a2663180ab5e/code.php b/src/f3757646-bc63-4f11-98c1-a2663180ab5e/code.php index d174bbb..c79cd0f 100644 --- a/src/f3757646-bc63-4f11-98c1-a2663180ab5e/code.php +++ b/src/f3757646-bc63-4f11-98c1-a2663180ab5e/code.php @@ -13,7 +13,8 @@ namespace VDM\Joomla\GetBible; use VDM\Joomla\GetBible\Data\Prompt; -use VDM\Joomla\GetBible\Data\Placeholders; +use VDM\Joomla\GetBible\Data\Response; +use VDM\Joomla\GetBible\AI\Worker; /** @@ -32,41 +33,59 @@ final class AI protected Prompt $prompt; /** - * The Placeholders class + * The Response class * - * @var Placeholders + * @var Response * @since 2.0.1 */ - protected Placeholders $placeholders; + protected Response $response; + + /** + * The Worker class + * + * @var Worker + * @since 2.0.1 + */ + protected Worker $worker; /** * Constructor * - * @param Prompt $prompt The prompt object. - * @param Placeholders $placeholders The chapter object. + * @param Prompt $prompt The prompt object. + * @param Response $response The response object. + * @param Worker $Worker The worker object. * * @since 2.0.1 */ - public function __construct(Prompt $prompt, Placeholders $placeholders) + public function __construct(Prompt $prompt, Response $response, Worker $worker) { $this->prompt = $prompt; - $this->placeholders = $placeholders; + $this->response = $response; + $this->worker = $worker; } /** * Get the Open AI response * - * @param string $guid The prompt guid. - * * @return array|null Array of response messages * @since 2.0.1 */ public function get(): ?array { - return [ - 'placeholders' => $this->placeholders->get(), - 'prompt' => $this->prompt->get() - ]; + if ($this->response->enough()) + { + return $this->response->get(); + } + // no cache + elseif (empty($this->prompt->getCacheBehaviour())) + { + return $this->worker->get(); + } + // we will use cache + else + { + return $this->worker->response(); + } } } diff --git a/src/f3757646-bc63-4f11-98c1-a2663180ab5e/code.power b/src/f3757646-bc63-4f11-98c1-a2663180ab5e/code.power index 0fcd1c1..f4b8330 100644 --- a/src/f3757646-bc63-4f11-98c1-a2663180ab5e/code.power +++ b/src/f3757646-bc63-4f11-98c1-a2663180ab5e/code.power @@ -7,39 +7,57 @@ protected Prompt $prompt; /** - * The Placeholders class + * The Response class * - * @var Placeholders + * @var Response * @since 2.0.1 */ - protected Placeholders $placeholders; + protected Response $response; + + /** + * The Worker class + * + * @var Worker + * @since 2.0.1 + */ + protected Worker $worker; /** * Constructor * - * @param Prompt $prompt The prompt object. - * @param Placeholders $placeholders The chapter object. + * @param Prompt $prompt The prompt object. + * @param Response $response The response object. + * @param Worker $Worker The worker object. * * @since 2.0.1 */ - public function __construct(Prompt $prompt, Placeholders $placeholders) + public function __construct(Prompt $prompt, Response $response, Worker $worker) { $this->prompt = $prompt; - $this->placeholders = $placeholders; + $this->response = $response; + $this->worker = $worker; } /** * Get the Open AI response * - * @param string $guid The prompt guid. - * * @return array|null Array of response messages * @since 2.0.1 */ public function get(): ?array { - return [ - 'placeholders' => $this->placeholders->get(), - 'prompt' => $this->prompt->get() - ]; + if ($this->response->enough()) + { + return $this->response->get(); + } + // no cache + elseif (empty($this->prompt->getCacheBehaviour())) + { + return $this->worker->get(); + } + // we will use cache + else + { + return $this->worker->response(); + } } \ No newline at end of file diff --git a/src/f3757646-bc63-4f11-98c1-a2663180ab5e/settings.json b/src/f3757646-bc63-4f11-98c1-a2663180ab5e/settings.json index 9bee696..617468a 100644 --- a/src/f3757646-bc63-4f11-98c1-a2663180ab5e/settings.json +++ b/src/f3757646-bc63-4f11-98c1-a2663180ab5e/settings.json @@ -10,12 +10,16 @@ "system_name": "Joomla.GetBible.AI", "type": "final class", "use_selection": { - "use_selection2": { + "use_selection0": { "use": "3f785d63-a592-463d-9f5f-b2b5a8edd561", "as": "default" }, "use_selection1": { - "use": "ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5", + "use": "44c15b17-e096-47c0-8769-42ea9b692cb2", + "as": "default" + }, + "use_selection2": { + "use": "ed16a9c4-e026-4d16-be60-81892ce7c6a9", "as": "default" } }, diff --git a/super-powers.json b/super-powers.json index d65cb0a..7bdf34e 100644 --- a/super-powers.json +++ b/super-powers.json @@ -340,6 +340,17 @@ "spk": "Super__d7a5f0c6_de60_4d31_b3e4_5d668a8f7d2e__Power", "guid": "d7a5f0c6-de60-4d31-b3e4-5d668a8f7d2e" }, + "ed16a9c4-e026-4d16-be60-81892ce7c6a9": { + "name": "Worker", + "type": "final class", + "namespace": "VDM\\Joomla\\GetBible\\AI", + "code": "src\/ed16a9c4-e026-4d16-be60-81892ce7c6a9\/code.php", + "power": "src\/ed16a9c4-e026-4d16-be60-81892ce7c6a9\/code.power", + "settings": "src\/ed16a9c4-e026-4d16-be60-81892ce7c6a9\/settings.json", + "path": "src\/ed16a9c4-e026-4d16-be60-81892ce7c6a9", + "spk": "Super__ed16a9c4_e026_4d16_be60_81892ce7c6a9__Power", + "guid": "ed16a9c4-e026-4d16-be60-81892ce7c6a9" + }, "f3757646-bc63-4f11-98c1-a2663180ab5e": { "name": "AI", "type": "final class",