update 2023-07-13 19:31:35
This commit is contained in:
parent
797c64504c
commit
a72d58b701
@ -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
|
||||
|
@ -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'),
|
||||
|
@ -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'),
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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;
|
||||
}
|
@ -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
|
||||
|
@ -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 '';
|
||||
}
|
||||
|
@ -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 '';
|
||||
}
|
||||
|
@ -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
|
||||
```
|
||||
|
@ -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')
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -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')
|
||||
);
|
||||
}
|
@ -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",
|
||||
|
54
src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/README.md
Normal file
54
src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/README.md
Normal file
@ -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)
|
||||
|
78
src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.php
Normal file
78
src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.php
Normal file
@ -0,0 +1,78 @@
|
||||
<?php
|
||||
/**
|
||||
* @package GetBible
|
||||
*
|
||||
* @created 30th May, 2023
|
||||
* @author Llewellyn van der Merwe <https://dev.vdm.io>
|
||||
* @git GetBible <https://git.vdm.dev/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'];
|
||||
}
|
||||
}
|
||||
|
51
src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.power
Normal file
51
src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/code.power
Normal file
@ -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'];
|
||||
}
|
27
src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/settings.json
Normal file
27
src/ed16a9c4-e026-4d16-be60-81892ce7c6a9/settings.json
Normal file
@ -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 <https:\/\/dev.vdm.io>\r\n * @git GetBible <https:\/\/git.vdm.dev\/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": ""
|
||||
}
|
@ -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
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
@ -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"
|
||||
}
|
||||
},
|
||||
|
@ -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",
|
||||
|
Loading…
x
Reference in New Issue
Block a user