4
0

update 2023-07-16 05:50:59

This commit is contained in:
Robot 2023-07-16 05:50:59 +02:00
parent a72d58b701
commit 5ef0795a29
Signed by: Robot
GPG Key ID: 14DECD44E7E1BB95
60 changed files with 5158 additions and 2785 deletions

View File

@ -35,7 +35,7 @@ This repository contains an index (see below) of all the approved powers within
- **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
- **final class Engineer** | [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
@ -47,11 +47,15 @@ This repository contains an index (see below) of all the approved powers within
- **final class Verses** | [Details](src/afa508bf-78f8-4616-97cc-f2809584c086) | [Code](src/afa508bf-78f8-4616-97cc-f2809584c086/code.php) | [Settings](src/afa508bf-78f8-4616-97cc-f2809584c086/settings.json) | Super__afa508bf_78f8_4616_97cc_f2809584c086__Power
- **Namespace**: [VDM\Joomla\GetBible\Data](#vdm-joomla-getbible-data)
- **final class Book** | [Details](src/fa776320-65f8-4198-a517-58cd94b3b7b7) | [Code](src/fa776320-65f8-4198-a517-58cd94b3b7b7/code.php) | [Settings](src/fa776320-65f8-4198-a517-58cd94b3b7b7/settings.json) | Super__fa776320_65f8_4198_a517_58cd94b3b7b7__Power
- **final class Chapter** | [Details](src/4a4c786d-51f4-421a-aa61-262dfd071880) | [Code](src/4a4c786d-51f4-421a-aa61-262dfd071880/code.php) | [Settings](src/4a4c786d-51f4-421a-aa61-262dfd071880/settings.json) | Super__4a4c786d_51f4_421a_aa61_262dfd071880__Power
- **final class Placeholders** | [Details](src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5) | [Code](src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/code.php) | [Settings](src/ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5/settings.json) | Super__ba2151c0_8ffa_4a07_ba6e_93f135a3e9d5__Power
- **final class Prompt** | [Details](src/3f785d63-a592-463d-9f5f-b2b5a8edd561) | [Code](src/3f785d63-a592-463d-9f5f-b2b5a8edd561/code.php) | [Settings](src/3f785d63-a592-463d-9f5f-b2b5a8edd561/settings.json) | Super__3f785d63_a592_463d_9f5f_b2b5a8edd561__Power
- **final class Response** | [Details](src/44c15b17-e096-47c0-8769-42ea9b692cb2) | [Code](src/44c15b17-e096-47c0-8769-42ea9b692cb2/code.php) | [Settings](src/44c15b17-e096-47c0-8769-42ea9b692cb2/settings.json) | Super__44c15b17_e096_47c0_8769_42ea9b692cb2__Power
- **final class Scripture** | [Details](src/17d87374-2953-4d6c-9fdd-4220d6ad1564) | [Code](src/17d87374-2953-4d6c-9fdd-4220d6ad1564/code.php) | [Settings](src/17d87374-2953-4d6c-9fdd-4220d6ad1564/settings.json) | Super__17d87374_2953_4d6c_9fdd_4220d6ad1564__Power
- **final class Translation** | [Details](src/c4098e1a-46dd-4d60-9277-b3668a09edc8) | [Code](src/c4098e1a-46dd-4d60-9277-b3668a09edc8/code.php) | [Settings](src/c4098e1a-46dd-4d60-9277-b3668a09edc8/settings.json) | Super__c4098e1a_46dd_4d60_9277_b3668a09edc8__Power
- **final class Verse** | [Details](src/e3798c7e-aae1-4e38-ba78-6018ce94630b) | [Code](src/e3798c7e-aae1-4e38-ba78-6018ce94630b/code.php) | [Settings](src/e3798c7e-aae1-4e38-ba78-6018ce94630b/settings.json) | Super__e3798c7e_aae1_4e38_ba78_6018ce94630b__Power
- **final class Word** | [Details](src/899551ac-943e-4f81-becd-7e15c41f1081) | [Code](src/899551ac-943e-4f81-becd-7e15c41f1081/code.php) | [Settings](src/899551ac-943e-4f81-becd-7e15c41f1081/settings.json) | Super__899551ac_943e_4f81_becd_7e15c41f1081__Power
- **Namespace**: [VDM\Joomla\GetBible\Database](#vdm-joomla-getbible-database)
- **final class Insert** | [Details](src/a07d90f6-6ff2-40a1-99c1-0f2cf33c9adf) | [Code](src/a07d90f6-6ff2-40a1-99c1-0f2cf33c9adf/code.php) | [Settings](src/a07d90f6-6ff2-40a1-99c1-0f2cf33c9adf/settings.json) | Super__a07d90f6_6ff2_40a1_99c1_0f2cf33c9adf__Power

View File

@ -0,0 +1,65 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Scripture (Details)
> namespace: **VDM\Joomla\GetBible\Data**
```uml
@startuml
class Scripture << (F,LightGreen) >> #Green {
# Translation $translation
# Book $book
# Chapter $chapter
# Verse $verse
# Word $word
# ?object $scripture
+ __construct(Translation $translation, Book $book, ...)
+ get(string $key, mixed $default = null) : mixed
- getScripture() : object
}
note right of Scripture::__construct
Constructor
since: 2.0.1
arguments:
Translation $translation
Book $book
Chapter $chapter
Verse $verse
Word $word
end note
note right of Scripture::get
Get the Open AI response
since: 2.0.1
return: mixed
end note
note right of Scripture::getScripture
Get all related scripture values
since: 2.0.1
return: object
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,154 @@
<?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\Data;
use VDM\Joomla\GetBible\Data\Translation;
use VDM\Joomla\GetBible\Data\Book;
use VDM\Joomla\GetBible\Data\Chapter;
use VDM\Joomla\GetBible\Data\Verse;
use VDM\Joomla\GetBible\Data\Word;
/**
* The GetBible Scripture
*
* @since 2.0.1
*/
final class Scripture
{
/**
* The Translation class
*
* @var Translation
* @since 2.0.1
*/
protected Translation $translation;
/**
* The Book class
*
* @var Book
* @since 2.0.1
*/
protected Book $book;
/**
* The Chapter class
*
* @var Chapter
* @since 2.0.1
*/
protected Chapter $chapter;
/**
* The Verse class
*
* @var Verse
* @since 2.0.1
*/
protected Verse $verse;
/**
* The Word class
*
* @var Word
* @since 2.0.1
*/
protected Word $word;
/**
* The Scripture object
*
* @var object
* @since 2.0.1
*/
protected ?object $scripture;
/**
* Constructor
*
* @param Translation $translation The translation object.
* @param Book $book The book object.
* @param Chapter $chapter The chapter object.
* @param Verse $verse The verse object.
* @param Word $word The word object.
*
* @since 2.0.1
*/
public function __construct(
Translation $translation,
Book $book,
Chapter $chapter,
Verse $verse,
Word $word)
{
$this->translation = $translation;
$this->book = $book;
$this->chapter = $chapter;
$this->verse = $verse;
$this->word = $word;
}
/**
* Get the Open AI response
*
* @param string $key The value key.
* @param mixed $default The default value.
*
* @return mixed Scripture Values
* @since 2.0.1
*/
public function get(string $key, $default = null)
{
if (empty($this->scripture))
{
$this->scripture = $this->getScripture();
}
return $this->scripture->{$key} ?? $default;
}
/**
* Get all related scripture values
*
* @return object Object of Scripture Values
* @since 2.0.1
*/
private function getScripture(): object
{
/**
* do not change these keys !!!
* this is an easy mapping
* so called bad practice
* that we use to simplify
* access to these values
*/
return (object) [
'translation_name' => $this->translation->getName(),
'translation_language' => $this->translation->getLanguage(),
'translation_lcsh' => $this->translation->getLcsh(),
'translation_abbreviation' => $this->translation->getAbbreviation(),
'book_number' => $this->book->getNumber(),
'book_name' => $this->book->getName(),
'chapter_number' => $this->chapter->getNumber(),
'chapter_name' => $this->chapter->getName(),
'chapter_text' => $this->chapter->getText(),
'verse_number' => $this->verse->getNumber(),
'verse_name' => $this->verse->getName(),
'verse_text' => $this->verse->getText(),
'selected_word_number' => $this->word->getNumber(),
'selected_word_text' => $this->word->getText()
];
}
}

View File

@ -0,0 +1,124 @@
/**
* The Translation class
*
* @var Translation
* @since 2.0.1
*/
protected Translation $translation;
/**
* The Book class
*
* @var Book
* @since 2.0.1
*/
protected Book $book;
/**
* The Chapter class
*
* @var Chapter
* @since 2.0.1
*/
protected Chapter $chapter;
/**
* The Verse class
*
* @var Verse
* @since 2.0.1
*/
protected Verse $verse;
/**
* The Word class
*
* @var Word
* @since 2.0.1
*/
protected Word $word;
/**
* The Scripture object
*
* @var object
* @since 2.0.1
*/
protected ?object $scripture;
/**
* Constructor
*
* @param Translation $translation The translation object.
* @param Book $book The book object.
* @param Chapter $chapter The chapter object.
* @param Verse $verse The verse object.
* @param Word $word The word object.
*
* @since 2.0.1
*/
public function __construct(
Translation $translation,
Book $book,
Chapter $chapter,
Verse $verse,
Word $word)
{
$this->translation = $translation;
$this->book = $book;
$this->chapter = $chapter;
$this->verse = $verse;
$this->word = $word;
}
/**
* Get the Open AI response
*
* @param string $key The value key.
* @param mixed $default The default value.
*
* @return mixed Scripture Values
* @since 2.0.1
*/
public function get(string $key, $default = null)
{
if (empty($this->scripture))
{
$this->scripture = $this->getScripture();
}
return $this->scripture->{$key} ?? $default;
}
/**
* Get all related scripture values
*
* @return object Object of Scripture Values
* @since 2.0.1
*/
private function getScripture(): object
{
/**
* do not change these keys !!!
* this is an easy mapping
* so called bad practice
* that we use to simplify
* access to these values
*/
return (object) [
'translation_name' => $this->translation->getName(),
'translation_language' => $this->translation->getLanguage(),
'translation_lcsh' => $this->translation->getLcsh(),
'translation_abbreviation' => $this->translation->getAbbreviation(),
'book_number' => $this->book->getNumber(),
'book_name' => $this->book->getName(),
'chapter_number' => $this->chapter->getNumber(),
'chapter_name' => $this->chapter->getName(),
'chapter_text' => $this->chapter->getText(),
'verse_number' => $this->verse->getNumber(),
'verse_name' => $this->verse->getName(),
'verse_text' => $this->verse->getText(),
'selected_word_number' => $this->word->getNumber(),
'selected_word_text' => $this->word->getText()
];
}

View File

@ -0,0 +1,39 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "17d87374-2953-4d6c-9fdd-4220d6ad1564",
"implements": null,
"load_selection": null,
"name": "Scripture",
"power_version": "1.0.0",
"system_name": "Joomla.GetBible.Data.Scripture",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "c4098e1a-46dd-4d60-9277-b3668a09edc8",
"as": "default"
},
"use_selection1": {
"use": "fa776320-65f8-4198-a517-58cd94b3b7b7",
"as": "default"
},
"use_selection2": {
"use": "4a4c786d-51f4-421a-aa61-262dfd071880",
"as": "default"
},
"use_selection3": {
"use": "e3798c7e-aae1-4e38-ba78-6018ce94630b",
"as": "default"
},
"use_selection4": {
"use": "899551ac-943e-4f81-becd-7e15c41f1081",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\GetBible\\Data.Scripture",
"description": "The GetBible Scripture\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": ""
}

View File

@ -15,9 +15,13 @@ class Data #Gold {
+ getConfig(Container $container) : Config
+ getTable(Container $container) : Table
+ getString(Container $container) : StringHelper
+ getTranslation(Container $container) : Translation
+ getChapter(Container $container) : Chapter
+ getPrompt(Container $container) : Prompt
+ getScripture(Container $container) : Scripture
+ getTranslation(Container $container) : Translation
+ getBook(Container $container) : Book
+ getChapter(Container $container) : Chapter
+ getVerse(Container $container) : Verse
+ getWord(Container $container) : Word
+ getPlaceholders(Container $container) : Placeholders
+ getResponse(Container $container) : Response
}
@ -50,6 +54,20 @@ note left of Data::getString
return: StringHelper
end note
note right of Data::getPrompt
Get the Prompt class
since: 3.2.0
return: Prompt
end note
note left of Data::getScripture
Get the Scripture class
since: 3.2.0
return: Scripture
end note
note right of Data::getTranslation
Get the Translation class
@ -57,18 +75,32 @@ note right of Data::getTranslation
return: Translation
end note
note left of Data::getChapter
note left of Data::getBook
Get the Book class
since: 3.2.0
return: Book
end note
note right of Data::getChapter
Get the Chapter class
since: 3.2.0
return: Chapter
end note
note right of Data::getPrompt
Get the Prompt class
note left of Data::getVerse
Get the Verse class
since: 3.2.0
return: Prompt
return: Verse
end note
note right of Data::getWord
Get the Word class
since: 3.2.0
return: Word
end note
note left of Data::getPlaceholders

View File

@ -17,8 +17,12 @@ use Joomla\DI\ServiceProviderInterface;
use VDM\Joomla\GetBible\Openai\Config;
use VDM\Joomla\GetBible\Table;
use VDM\Joomla\GetBible\Utilities\StringHelper;
use VDM\Joomla\GetBible\Data\Scripture;
use VDM\Joomla\GetBible\Data\Translation;
use VDM\Joomla\GetBible\Data\Book;
use VDM\Joomla\GetBible\Data\Chapter;
use VDM\Joomla\GetBible\Data\Verse;
use VDM\Joomla\GetBible\Data\Word;
use VDM\Joomla\GetBible\Data\Prompt;
use VDM\Joomla\GetBible\Data\Placeholders;
use VDM\Joomla\GetBible\Data\Response;
@ -50,14 +54,26 @@ class Data implements ServiceProviderInterface
$container->alias(StringHelper::class, 'GetBible.Utilities.String')
->share('GetBible.Utilities.String', [$this, 'getString'], true);
$container->alias(Prompt::class, 'GetBible.Prompt')
->share('GetBible.Prompt', [$this, 'getPrompt'], true);
$container->alias(Scripture::class, 'GetBible.Scripture')
->share('GetBible.Scripture', [$this, 'getScripture'], true);
$container->alias(Translation::class, 'GetBible.Translation')
->share('GetBible.Translation', [$this, 'getTranslation'], true);
$container->alias(Book::class, 'GetBible.Book')
->share('GetBible.Book', [$this, 'getBook'], true);
$container->alias(Chapter::class, 'GetBible.Chapter')
->share('GetBible.Chapter', [$this, 'getChapter'], true);
$container->alias(Prompt::class, 'GetBible.Prompt')
->share('GetBible.Prompt', [$this, 'getPrompt'], true);
$container->alias(Verse::class, 'GetBible.Verse')
->share('GetBible.Verse', [$this, 'getVerse'], true);
$container->alias(Word::class, 'GetBible.Word')
->share('GetBible.Word', [$this, 'getWord'], true);
$container->alias(Placeholders::class, 'GetBible.Placeholders')
->share('GetBible.Placeholders', [$this, 'getPlaceholders'], true);
@ -105,6 +121,41 @@ class Data implements ServiceProviderInterface
return new StringHelper();
}
/**
* Get the Prompt class
*
* @param Container $container The DI container.
*
* @return Prompt
* @since 3.2.0
*/
public function getPrompt(Container $container): Prompt
{
return new Prompt(
$container->get('GetBible.Load'),
$container->get('GetBible.Config')
);
}
/**
* Get the Scripture class
*
* @param Container $container The DI container.
*
* @return Scripture
* @since 3.2.0
*/
public function getScripture(Container $container): Scripture
{
return new Scripture(
$container->get('GetBible.Translation'),
$container->get('GetBible.Book'),
$container->get('GetBible.Chapter'),
$container->get('GetBible.Verse'),
$container->get('GetBible.Word'),
);
}
/**
* Get the Translation class
*
@ -121,6 +172,22 @@ class Data implements ServiceProviderInterface
);
}
/**
* Get the Book class
*
* @param Container $container The DI container.
*
* @return Book
* @since 3.2.0
*/
public function getBook(Container $container): Book
{
return new Book(
$container->get('GetBible.Load'),
$container->get('GetBible.Config')
);
}
/**
* Get the Chapter class
*
@ -133,6 +200,22 @@ class Data implements ServiceProviderInterface
{
return new Chapter(
$container->get('GetBible.Load'),
$container->get('GetBible.Config')
);
}
/**
* Get the Verse class
*
* @param Container $container The DI container.
*
* @return Verse
* @since 3.2.0
*/
public function getVerse(Container $container): Verse
{
return new Verse(
$container->get('GetBible.Chapter'),
$container->get('GetBible.Config'),
$container->get('GetBible.Prompt'),
$container->get('GetBible.Utilities.String')
@ -140,18 +223,19 @@ class Data implements ServiceProviderInterface
}
/**
* Get the Prompt class
* Get the Word class
*
* @param Container $container The DI container.
*
* @return Prompt
* @return Word
* @since 3.2.0
*/
public function getPrompt(Container $container): Prompt
public function getWord(Container $container): Word
{
return new Prompt(
$container->get('GetBible.Load'),
$container->get('GetBible.Config')
return new Word(
$container->get('GetBible.Verse'),
$container->get('GetBible.Config'),
$container->get('GetBible.Prompt')
);
}
@ -166,8 +250,7 @@ class Data implements ServiceProviderInterface
public function getPlaceholders(Container $container): Placeholders
{
return new Placeholders(
$container->get('GetBible.Translation'),
$container->get('GetBible.Chapter'),
$container->get('GetBible.Scripture'),
$container->get('GetBible.Prompt')
);
}
@ -183,8 +266,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.Scripture'),
$container->get('GetBible.Prompt'),
$container->get('GetBible.Load'),
$container->get('GetBible.Config')

View File

@ -17,14 +17,26 @@
$container->alias(StringHelper::class, 'GetBible.Utilities.String')
->share('GetBible.Utilities.String', [$this, 'getString'], true);
$container->alias(Prompt::class, 'GetBible.Prompt')
->share('GetBible.Prompt', [$this, 'getPrompt'], true);
$container->alias(Scripture::class, 'GetBible.Scripture')
->share('GetBible.Scripture', [$this, 'getScripture'], true);
$container->alias(Translation::class, 'GetBible.Translation')
->share('GetBible.Translation', [$this, 'getTranslation'], true);
$container->alias(Book::class, 'GetBible.Book')
->share('GetBible.Book', [$this, 'getBook'], true);
$container->alias(Chapter::class, 'GetBible.Chapter')
->share('GetBible.Chapter', [$this, 'getChapter'], true);
$container->alias(Prompt::class, 'GetBible.Prompt')
->share('GetBible.Prompt', [$this, 'getPrompt'], true);
$container->alias(Verse::class, 'GetBible.Verse')
->share('GetBible.Verse', [$this, 'getVerse'], true);
$container->alias(Word::class, 'GetBible.Word')
->share('GetBible.Word', [$this, 'getWord'], true);
$container->alias(Placeholders::class, 'GetBible.Placeholders')
->share('GetBible.Placeholders', [$this, 'getPlaceholders'], true);
@ -72,6 +84,41 @@
return new StringHelper();
}
/**
* Get the Prompt class
*
* @param Container $container The DI container.
*
* @return Prompt
* @since 3.2.0
*/
public function getPrompt(Container $container): Prompt
{
return new Prompt(
$container->get('GetBible.Load'),
$container->get('GetBible.Config')
);
}
/**
* Get the Scripture class
*
* @param Container $container The DI container.
*
* @return Scripture
* @since 3.2.0
*/
public function getScripture(Container $container): Scripture
{
return new Scripture(
$container->get('GetBible.Translation'),
$container->get('GetBible.Book'),
$container->get('GetBible.Chapter'),
$container->get('GetBible.Verse'),
$container->get('GetBible.Word'),
);
}
/**
* Get the Translation class
*
@ -88,6 +135,22 @@
);
}
/**
* Get the Book class
*
* @param Container $container The DI container.
*
* @return Book
* @since 3.2.0
*/
public function getBook(Container $container): Book
{
return new Book(
$container->get('GetBible.Load'),
$container->get('GetBible.Config')
);
}
/**
* Get the Chapter class
*
@ -100,6 +163,22 @@
{
return new Chapter(
$container->get('GetBible.Load'),
$container->get('GetBible.Config')
);
}
/**
* Get the Verse class
*
* @param Container $container The DI container.
*
* @return Verse
* @since 3.2.0
*/
public function getVerse(Container $container): Verse
{
return new Verse(
$container->get('GetBible.Chapter'),
$container->get('GetBible.Config'),
$container->get('GetBible.Prompt'),
$container->get('GetBible.Utilities.String')
@ -107,18 +186,19 @@
}
/**
* Get the Prompt class
* Get the Word class
*
* @param Container $container The DI container.
*
* @return Prompt
* @return Word
* @since 3.2.0
*/
public function getPrompt(Container $container): Prompt
public function getWord(Container $container): Word
{
return new Prompt(
$container->get('GetBible.Load'),
$container->get('GetBible.Config')
return new Word(
$container->get('GetBible.Verse'),
$container->get('GetBible.Config'),
$container->get('GetBible.Prompt')
);
}
@ -133,8 +213,7 @@
public function getPlaceholders(Container $container): Placeholders
{
return new Placeholders(
$container->get('GetBible.Translation'),
$container->get('GetBible.Chapter'),
$container->get('GetBible.Scripture'),
$container->get('GetBible.Prompt')
);
}
@ -150,8 +229,7 @@
public function getResponse(Container $container): Response
{
return new Response(
$container->get('GetBible.Translation'),
$container->get('GetBible.Chapter'),
$container->get('GetBible.Scripture'),
$container->get('GetBible.Prompt'),
$container->get('GetBible.Load'),
$container->get('GetBible.Config')

View File

@ -24,23 +24,39 @@
"use": "a5b32737-207d-4cf6-b8ae-ee815612c3a0",
"as": "default"
},
"use_selection11": {
"use": "17d87374-2953-4d6c-9fdd-4220d6ad1564",
"as": "default"
},
"use_selection3": {
"use": "c4098e1a-46dd-4d60-9277-b3668a09edc8",
"as": "default"
},
"use_selection4": {
"use": "4a4c786d-51f4-421a-aa61-262dfd071880",
"use": "fa776320-65f8-4198-a517-58cd94b3b7b7",
"as": "default"
},
"use_selection5": {
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"use": "4a4c786d-51f4-421a-aa61-262dfd071880",
"as": "default"
},
"use_selection6": {
"use": "ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5",
"use": "e3798c7e-aae1-4e38-ba78-6018ce94630b",
"as": "default"
},
"use_selection7": {
"use": "899551ac-943e-4f81-becd-7e15c41f1081",
"as": "default"
},
"use_selection8": {
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"as": "default"
},
"use_selection9": {
"use": "ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5",
"as": "default"
},
"use_selection10": {
"use": "44c15b17-e096-47c0-8769-42ea9b692cb2",
"as": "default"
}

View File

@ -20,6 +20,17 @@ class Config #Gold {
# getChapter() : ?int
# getVerse() : ?string
# getWords() : ?string
# getEnableopenai() : bool
# getEnableopenaiorg() : bool
# getToken() : ?string
# getOrgToken() : ?string
# getModel() : ?string
# getMaxtokens() : ?int
# getTemperature() : ?float
# getTopp() : ?float
# getN() : ?int
# getPresencepenalty() : ?float
# getFrequencypenalty() : ?float
}
note right of Config::__construct
@ -28,7 +39,7 @@ note right of Config::__construct
since: 3.2.0
end note
note right of Config::getPrompt
note left of Config::getPrompt
get Prompt GUID
since: 2.0.1
@ -42,7 +53,7 @@ note right of Config::getTranslation
return: ?string
end note
note right of Config::getBook
note left of Config::getBook
get Book Number
since: 2.0.1
@ -56,7 +67,7 @@ note right of Config::getChapter
return: ?int
end note
note right of Config::getVerse
note left of Config::getVerse
get Verse Number/s
since: 2.0.1
@ -69,6 +80,83 @@ note right of Config::getWords
since: 2.0.1
return: ?string
end note
note left of Config::getEnableopenai
get Enable Open AI
since: 2.0.1
return: bool
end note
note right of Config::getEnableopenaiorg
get Enable Open AI Organisation
since: 2.0.1
return: bool
end note
note left of Config::getToken
get User Token
since: 2.0.1
return: ?string
end note
note right of Config::getOrgToken
get Org Token
since: 2.0.1
return: ?string
end note
note left of Config::getModel
get Open AI Model name
since: 2.0.1
return: ?string
end note
note right of Config::getMaxtokens
get Max Tokens
since: 2.0.1
return: ?int
end note
note left of Config::getTemperature
get Temperature
since: 2.0.1
return: ?float
end note
note right of Config::getTopp
get Top P
since: 2.0.1
return: ?float
end note
note left of Config::getN
get N (number of results)
since: 2.0.1
return: ?int
end note
note right of Config::getPresencepenalty
get Presence Penalty
since: 2.0.1
return: ?float
end note
note left of Config::getFrequencypenalty
get Frequency Penalty
since: 2.0.1
return: ?float
end note
@enduml
```

View File

@ -12,8 +12,8 @@
namespace VDM\Joomla\GetBible\Openai;
use Joomla\Registry\Registry as JoomlaRegistry;
use Joomla\CMS\Factory as JoomlaFactory;
use Joomla\Registry\Registry as JoomlaRegistry;
use Joomla\Input\Input;
use VDM\Joomla\Utilities\Component\Helper;
use VDM\Joomla\Abstraction\BaseConfig;
@ -45,8 +45,8 @@ class Config extends BaseConfig
/**
* Constructor
*
* @param Input|null $input Input
* @param Registry|null $params The component parameters
* @param Input|null $input Input
* @param JoomlaRegistry|null $params The component parameters
*
* @throws \Exception
* @since 3.2.0
@ -124,6 +124,182 @@ class Config extends BaseConfig
protected function getWords(): ?string
{
return $this->input->getString('words');
}
/**
* get Enable Open AI
*
* @return bool The switch to enable open AI
* @since 2.0.1
*/
protected function getEnableopenai(): bool
{
if ($this->params->get('enable_open_ai', 0) == 1)
{
return true;
}
return false;
}
/**
* get Enable Open AI Organisation
*
* @return bool The switch to enable open AI Organisation
* @since 2.0.1
*/
protected function getEnableopenaiorg(): bool
{
if ($this->params->get('enable_open_ai_org', 0) == 1)
{
return true;
}
return false;
}
/**
* get User Token
*
* @return string|null The token
* @since 2.0.1
*/
protected function getToken(): ?string
{
if (!$this->enable_open_ai)
{
return null;
}
return $this->params->get('openai_token');
}
/**
* get Org Token
*
* @return string|null The org token
* @since 2.0.1
*/
protected function getOrgToken(): ?string
{
if (!$this->enable_open_ai || !$this->enable_open_ai_org)
{
return null;
}
return $this->params->get('openai_org_token');
}
/**
* get Open AI Model name
*
* @return string|null The model name
* @since 2.0.1
*/
protected function getModel(): ?string
{
if (!$this->enable_open_ai)
{die;
return null;
}
return $this->params->get('openai_model');
}
/**
* get Max Tokens
*
* @return int|null The max tokens
* @since 2.0.1
*/
protected function getMaxtokens(): ?int
{
if (!$this->enable_open_ai)
{
return null;
}
return (int) $this->params->get('openai_max_tokens', 300);
}
/**
* get Temperature
*
* @return float|null The temperature
* @since 2.0.1
*/
protected function getTemperature(): ?float
{
if (!$this->enable_open_ai)
{
return null;
}
return (float) $this->params->get('openai_temperature', 1);
}
/**
* get Top P
*
* @return float|null The top p
* @since 2.0.1
*/
protected function getTopp(): ?float
{
if (!$this->enable_open_ai)
{
return null;
}
return (float) $this->params->get('openai_top_p', 1);
}
/**
* get N (number of results)
*
* @return int|null The number of results
* @since 2.0.1
*/
protected function getN(): ?int
{
if (!$this->enable_open_ai)
{
return null;
}
return (int) $this->params->get('openai_n', 1);
}
/**
* get Presence Penalty
*
* @return float|null The presence penalty
* @since 2.0.1
*/
protected function getPresencepenalty(): ?float
{
if (!$this->enable_open_ai)
{
return null;
}
return (float) $this->params->get('openai_presence_penalty', 0);
}
/**
* get Frequency Penalty
*
* @return float|null The frequency penalty
* @since 2.0.1
*/
protected function getFrequencypenalty(): ?float
{
if (!$this->enable_open_ai)
{
return null;
}
return (float) $this->params->get('openai_frequency_penalty', 0);
}
}

View File

@ -17,8 +17,8 @@
/**
* Constructor
*
* @param Input|null $input Input
* @param Registry|null $params The component parameters
* @param Input|null $input Input
* @param JoomlaRegistry|null $params The component parameters
*
* @throws \Exception
* @since 3.2.0
@ -96,4 +96,180 @@
protected function getWords(): ?string
{
return $this->input->getString('words');
}
/**
* get Enable Open AI
*
* @return bool The switch to enable open AI
* @since 2.0.1
*/
protected function getEnableopenai(): bool
{
if ($this->params->get('enable_open_ai', 0) == 1)
{
return true;
}
return false;
}
/**
* get Enable Open AI Organisation
*
* @return bool The switch to enable open AI Organisation
* @since 2.0.1
*/
protected function getEnableopenaiorg(): bool
{
if ($this->params->get('enable_open_ai_org', 0) == 1)
{
return true;
}
return false;
}
/**
* get User Token
*
* @return string|null The token
* @since 2.0.1
*/
protected function getToken(): ?string
{
if (!$this->enable_open_ai)
{
return null;
}
return $this->params->get('openai_token');
}
/**
* get Org Token
*
* @return string|null The org token
* @since 2.0.1
*/
protected function getOrgToken(): ?string
{
if (!$this->enable_open_ai || !$this->enable_open_ai_org)
{
return null;
}
return $this->params->get('openai_org_token');
}
/**
* get Open AI Model name
*
* @return string|null The model name
* @since 2.0.1
*/
protected function getModel(): ?string
{
if (!$this->enable_open_ai)
{die;
return null;
}
return $this->params->get('openai_model');
}
/**
* get Max Tokens
*
* @return int|null The max tokens
* @since 2.0.1
*/
protected function getMaxtokens(): ?int
{
if (!$this->enable_open_ai)
{
return null;
}
return (int) $this->params->get('openai_max_tokens', 300);
}
/**
* get Temperature
*
* @return float|null The temperature
* @since 2.0.1
*/
protected function getTemperature(): ?float
{
if (!$this->enable_open_ai)
{
return null;
}
return (float) $this->params->get('openai_temperature', 1);
}
/**
* get Top P
*
* @return float|null The top p
* @since 2.0.1
*/
protected function getTopp(): ?float
{
if (!$this->enable_open_ai)
{
return null;
}
return (float) $this->params->get('openai_top_p', 1);
}
/**
* get N (number of results)
*
* @return int|null The number of results
* @since 2.0.1
*/
protected function getN(): ?int
{
if (!$this->enable_open_ai)
{
return null;
}
return (int) $this->params->get('openai_n', 1);
}
/**
* get Presence Penalty
*
* @return float|null The presence penalty
* @since 2.0.1
*/
protected function getPresencepenalty(): ?float
{
if (!$this->enable_open_ai)
{
return null;
}
return (float) $this->params->get('openai_presence_penalty', 0);
}
/**
* get Frequency Penalty
*
* @return float|null The frequency penalty
* @since 2.0.1
*/
protected function getFrequencypenalty(): ?float
{
if (!$this->enable_open_ai)
{
return null;
}
return (float) $this->params->get('openai_frequency_penalty', 0);
}

View File

@ -18,6 +18,6 @@
"namespace": "VDM\\Joomla\\GetBible\\Openai.Config",
"description": "GetBible Openai Configurations\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": "use Joomla\\Registry\\Registry as JoomlaRegistry;\r\nuse Joomla\\CMS\\Factory as JoomlaFactory;\r\nuse Joomla\\Input\\Input;",
"head": "use Joomla\\CMS\\Factory as JoomlaFactory;\r\nuse Joomla\\Registry\\Registry as JoomlaRegistry;\r\nuse Joomla\\Input\\Input;",
"composer": ""
}

View File

@ -15,11 +15,21 @@ class Prompt << (F,LightGreen) >> #Green {
# Config $config
# array $prompts
+ __construct(Load $load, Config $config)
+ getIntegration(?string $guid = null) : ?int
+ getCacheBehaviour(?string $guid = null) : ?int
+ getCacheCapacity(?string $guid = null) : int
+ get(?string $guid = null) : ?object
- active(?string $guid = null) : bool
+ getGuid() : string
+ getToken() : ?string
+ getOrgToken() : ?string
+ getModel() : ?string
+ getMaxTokens() : ?int
+ getTemperature() : ?float
+ getTopP() : ?float
+ getN() : ?int
+ getPresencePenalty() : ?float
+ getFrequencyPenalty() : ?float
+ getIntegration() : ?int
+ getCacheBehaviour() : ?int
+ getCacheCapacity() : int
+ getMessages() : ?array
# get() : ?object
}
note right of Prompt::__construct
@ -28,7 +38,77 @@ note right of Prompt::__construct
since: 2.0.1
end note
note right of Prompt::getIntegration
note left of Prompt::getGuid
Get prompt guid
since: 2.0.1
return: string
end note
note right of Prompt::getToken
Get open ai token
since: 2.0.1
return: ?string
end note
note left of Prompt::getOrgToken
Get open ai organisation token
since: 2.0.1
return: ?string
end note
note right of Prompt::getModel
Get open ai model name
since: 2.0.1
return: ?string
end note
note left of Prompt::getMaxTokens
Get the max tokens
since: 2.0.1
return: ?int
end note
note right of Prompt::getTemperature
Get the temperature
since: 2.0.1
return: ?float
end note
note left of Prompt::getTopP
Get the top p
since: 2.0.1
return: ?float
end note
note right of Prompt::getN
Get the number of results
since: 2.0.1
return: ?int
end note
note left of Prompt::getPresencePenalty
Get presence penalty
since: 2.0.1
return: ?float
end note
note right of Prompt::getFrequencyPenalty
Get frequency penalty
since: 2.0.1
return: ?float
end note
note left of Prompt::getIntegration
Get the integration
since: 2.0.1
@ -42,26 +122,26 @@ note right of Prompt::getCacheBehaviour
return: ?int
end note
note right of Prompt::getCacheCapacity
note left of Prompt::getCacheCapacity
Get the cache capacity
since: 2.0.1
return: int
end note
note right of Prompt::get
note right of Prompt::getMessages
Get the prompt messages
since: 2.0.1
return: ?array
end note
note left of Prompt::get
Get the prompt
since: 2.0.1
return: ?object
end note
note right of Prompt::active
Check if this prompt is active
since: 2.0.1
return: bool
end note
@enduml
```

View File

@ -62,106 +62,266 @@ final class Prompt
}
/**
* Get the integration
* Get prompt guid
*
* @param string $guid The prompt guid.
* @return string The global unique id
* @since 2.0.1
*/
public function getGuid(): string
{
$prompt = $this->get();
return $prompt ? $prompt->guid ?? '' : '';
}
/**
* Get open ai token
*
* @return string|null The token
* @since 2.0.1
*/
public function getToken(): ?string
{
$default = $this->config->get('token');
$prompt = $this->get();
if (!$prompt || !isset($prompt->token_override) ||
$prompt->token_override != 1)
{
return $default;
}
return $prompt->token ?? $default;
}
/**
* Get open ai organisation token
*
* @return string|null The token
* @since 2.0.1
*/
public function getOrgToken(): ?string
{
$default = $this->config->get('org_token');
$prompt = $this->get();
if (!$prompt || !isset($prompt->ai_org_token_override) ||
$prompt->ai_org_token_override != 1)
{
return $default;
}
return $prompt->org_token ?? $default;
}
/**
* Get open ai model name
*
* @return string|null The model name
* @since 2.0.1
*/
public function getModel(): ?string
{
$default = $this->config->get('model');
$prompt = $this->get();
return $prompt ? $prompt->model ?? $default : $default;
}
/**
* Get the max tokens
*
* @return int|null The max tokens
* @since 2.0.1
*/
public function getMaxTokens(): ?int
{
$default = $this->config->get('max_tokens');
$prompt = $this->get();
if (!$prompt || !isset($prompt->max_tokens_override) ||
$prompt->max_tokens_override != 1)
{
return $default;
}
return $prompt->max_tokens ?? $default;
}
/**
* Get the temperature
*
* @return float|null The temperature
* @since 2.0.1
*/
public function getTemperature(): ?float
{
$default = $this->config->get('temperature');
$prompt = $this->get();
if (!$prompt || !isset($prompt->temperature_override) ||
$prompt->temperature_override != 1)
{
return $default;
}
return $prompt->temperature ?? $default;
}
/**
* Get the top p
*
* @return float|null The top p
* @since 2.0.1
*/
public function getTopP(): ?float
{
$default = $this->config->get('top_p');
$prompt = $this->get();
if (!$prompt || !isset($prompt->top_p_override) ||
$prompt->top_p_override != 1)
{
return $default;
}
return $prompt->top_p ?? $default;
}
/**
* Get the number of results
*
* @return int|null The number of results
* @since 2.0.1
*/
public function getN(): ?int
{
$default = $this->config->get('n');
$prompt = $this->get();
if (!$prompt || !isset($prompt->n_override) ||
$prompt->n_override != 1)
{
return $default;
}
return $prompt->n ?? $default;
}
/**
* Get presence penalty
*
* @return float|null The presence penalty
* @since 2.0.1
*/
public function getPresencePenalty(): ?float
{
$default = $this->config->get('presence_penalty');
$prompt = $this->get();
if (!$prompt || !isset($prompt->presence_penalty_override) ||
$prompt->presence_penalty_override != 1)
{
return $default;
}
return $prompt->presence_penalty ?? $default;
}
/**
* Get frequency penalty
*
* @return float|null The frequency penalty
* @since 2.0.1
*/
public function getFrequencyPenalty(): ?float
{
$default = $this->config->get('frequency_penalty');
$prompt = $this->get();
if (!$prompt || !isset($prompt->frequency_penalty_override) ||
$prompt->frequency_penalty_override != 1)
{
return $default;
}
return $prompt->frequency_penalty ?? $default;
}
/**
* Get the integration
*
* @return int|null 1 = Word-Based, 2 = Verse-Based, 3 = Selection-Based
* @since 2.0.1
*/
public function getIntegration(?string $guid = null): ?int
public function getIntegration(): ?int
{
if ($this->active($guid))
{
return (int) $this->get($guid)->integration;
}
return null;
$prompt = $this->get();
return $prompt ? $prompt->integration ?? null : null;
}
/**
* Get the cache behaviour
*
* @param string $guid The prompt guid.
*
* @return int|null 0 = None, 2 = Basic, 3 = Advanced
* @return int|null 0 = Persistently, 2 = Basic, 3 = Advanced
* @since 2.0.1
*/
public function getCacheBehaviour(?string $guid = null): ?int
public function getCacheBehaviour(): ?int
{
if ($this->active($guid))
{
return (int) $this->get($guid)->cache_behaviour;
}
return null;
$prompt = $this->get();
return $prompt ? $prompt->cache_behaviour ?? null : null;
}
/**
* Get the cache capacity
*
* @param string $guid The prompt guid.
*
* @return int The number to cache
* @since 2.0.1
*/
public function getCacheCapacity(?string $guid = null): int
public function getCacheCapacity(): int
{
if ($this->active($guid))
{
return (int) $this->get($guid)->cache_capacity;
}
$prompt = $this->get();
return $prompt ? $prompt->cache_capacity ?? 1 : 1;
}
return 1;
/**
* Get the prompt messages
*
* @return array|null The array of massage
* @since 2.0.1
*/
public function getMessages(): ?array
{
$prompt = $this->get();
return $prompt ? $prompt->messages ?? null : null;
}
/**
* Get the prompt
*
* @param string $guid The prompt guid.
*
* @return object|null True on success
* @since 2.0.1
*/
public function get(?string $guid = null): ?object
protected function get(): ?object
{
// get from cache if not found
$guid = $guid ?? $this->config->get('prompt');
$guid = $this->config->get('prompt');
if ($guid === null)
if (empty($guid))
{
return null;
}
if (!isset($this->responses[$guid]))
if (!isset($this->prompts[$guid]))
{
$this->prompts[$guid] = $this->load->item(['guid' => $guid], 'prompt');
$this->prompts[$guid] = $this->load->item(['guid' => $guid, 'published' => 1], 'prompt');
if ($this->prompts[$guid] !== null && is_object($this->prompts[$guid]))
if ($this->prompts[$guid] && isset($this->prompts[$guid]->messages) && is_object($this->prompts[$guid]->messages))
{
$this->config->set('prompt', $guid);
$this->prompts[$guid]->messages = array_values((array) $this->prompts[$guid]->messages);
}
}
return $this->prompts[$guid];
}
/**
* Check if this prompt is active
*
* @param string $guid The prompt guid.
*
* @return bool true if active
* @since 2.0.1
*/
private function active(?string $guid = null): bool
{
if ($this->get($guid))
{
return true;
}
return false;
}
}

View File

@ -37,104 +37,264 @@
}
/**
* Get the integration
* Get prompt guid
*
* @param string $guid The prompt guid.
* @return string The global unique id
* @since 2.0.1
*/
public function getGuid(): string
{
$prompt = $this->get();
return $prompt ? $prompt->guid ?? '' : '';
}
/**
* Get open ai token
*
* @return string|null The token
* @since 2.0.1
*/
public function getToken(): ?string
{
$default = $this->config->get('token');
$prompt = $this->get();
if (!$prompt || !isset($prompt->token_override) ||
$prompt->token_override != 1)
{
return $default;
}
return $prompt->token ?? $default;
}
/**
* Get open ai organisation token
*
* @return string|null The token
* @since 2.0.1
*/
public function getOrgToken(): ?string
{
$default = $this->config->get('org_token');
$prompt = $this->get();
if (!$prompt || !isset($prompt->ai_org_token_override) ||
$prompt->ai_org_token_override != 1)
{
return $default;
}
return $prompt->org_token ?? $default;
}
/**
* Get open ai model name
*
* @return string|null The model name
* @since 2.0.1
*/
public function getModel(): ?string
{
$default = $this->config->get('model');
$prompt = $this->get();
return $prompt ? $prompt->model ?? $default : $default;
}
/**
* Get the max tokens
*
* @return int|null The max tokens
* @since 2.0.1
*/
public function getMaxTokens(): ?int
{
$default = $this->config->get('max_tokens');
$prompt = $this->get();
if (!$prompt || !isset($prompt->max_tokens_override) ||
$prompt->max_tokens_override != 1)
{
return $default;
}
return $prompt->max_tokens ?? $default;
}
/**
* Get the temperature
*
* @return float|null The temperature
* @since 2.0.1
*/
public function getTemperature(): ?float
{
$default = $this->config->get('temperature');
$prompt = $this->get();
if (!$prompt || !isset($prompt->temperature_override) ||
$prompt->temperature_override != 1)
{
return $default;
}
return $prompt->temperature ?? $default;
}
/**
* Get the top p
*
* @return float|null The top p
* @since 2.0.1
*/
public function getTopP(): ?float
{
$default = $this->config->get('top_p');
$prompt = $this->get();
if (!$prompt || !isset($prompt->top_p_override) ||
$prompt->top_p_override != 1)
{
return $default;
}
return $prompt->top_p ?? $default;
}
/**
* Get the number of results
*
* @return int|null The number of results
* @since 2.0.1
*/
public function getN(): ?int
{
$default = $this->config->get('n');
$prompt = $this->get();
if (!$prompt || !isset($prompt->n_override) ||
$prompt->n_override != 1)
{
return $default;
}
return $prompt->n ?? $default;
}
/**
* Get presence penalty
*
* @return float|null The presence penalty
* @since 2.0.1
*/
public function getPresencePenalty(): ?float
{
$default = $this->config->get('presence_penalty');
$prompt = $this->get();
if (!$prompt || !isset($prompt->presence_penalty_override) ||
$prompt->presence_penalty_override != 1)
{
return $default;
}
return $prompt->presence_penalty ?? $default;
}
/**
* Get frequency penalty
*
* @return float|null The frequency penalty
* @since 2.0.1
*/
public function getFrequencyPenalty(): ?float
{
$default = $this->config->get('frequency_penalty');
$prompt = $this->get();
if (!$prompt || !isset($prompt->frequency_penalty_override) ||
$prompt->frequency_penalty_override != 1)
{
return $default;
}
return $prompt->frequency_penalty ?? $default;
}
/**
* Get the integration
*
* @return int|null 1 = Word-Based, 2 = Verse-Based, 3 = Selection-Based
* @since 2.0.1
*/
public function getIntegration(?string $guid = null): ?int
public function getIntegration(): ?int
{
if ($this->active($guid))
{
return (int) $this->get($guid)->integration;
}
return null;
$prompt = $this->get();
return $prompt ? $prompt->integration ?? null : null;
}
/**
* Get the cache behaviour
*
* @param string $guid The prompt guid.
*
* @return int|null 0 = None, 2 = Basic, 3 = Advanced
* @return int|null 0 = Persistently, 2 = Basic, 3 = Advanced
* @since 2.0.1
*/
public function getCacheBehaviour(?string $guid = null): ?int
public function getCacheBehaviour(): ?int
{
if ($this->active($guid))
{
return (int) $this->get($guid)->cache_behaviour;
}
return null;
$prompt = $this->get();
return $prompt ? $prompt->cache_behaviour ?? null : null;
}
/**
* Get the cache capacity
*
* @param string $guid The prompt guid.
*
* @return int The number to cache
* @since 2.0.1
*/
public function getCacheCapacity(?string $guid = null): int
public function getCacheCapacity(): int
{
if ($this->active($guid))
{
return (int) $this->get($guid)->cache_capacity;
}
$prompt = $this->get();
return $prompt ? $prompt->cache_capacity ?? 1 : 1;
}
return 1;
/**
* Get the prompt messages
*
* @return array|null The array of massage
* @since 2.0.1
*/
public function getMessages(): ?array
{
$prompt = $this->get();
return $prompt ? $prompt->messages ?? null : null;
}
/**
* Get the prompt
*
* @param string $guid The prompt guid.
*
* @return object|null True on success
* @since 2.0.1
*/
public function get(?string $guid = null): ?object
protected function get(): ?object
{
// get from cache if not found
$guid = $guid ?? $this->config->get('prompt');
$guid = $this->config->get('prompt');
if ($guid === null)
if (empty($guid))
{
return null;
}
if (!isset($this->responses[$guid]))
if (!isset($this->prompts[$guid]))
{
$this->prompts[$guid] = $this->load->item(['guid' => $guid], 'prompt');
$this->prompts[$guid] = $this->load->item(['guid' => $guid, 'published' => 1], 'prompt');
if ($this->prompts[$guid] !== null && is_object($this->prompts[$guid]))
if ($this->prompts[$guid] && isset($this->prompts[$guid]->messages) && is_object($this->prompts[$guid]->messages))
{
$this->config->set('prompt', $guid);
$this->prompts[$guid]->messages = array_values((array) $this->prompts[$guid]->messages);
}
}
return $this->prompts[$guid];
}
/**
* Check if this prompt is active
*
* @param string $guid The prompt guid.
*
* @return bool true if active
* @since 2.0.1
*/
private function active(?string $guid = null): bool
{
if ($this->get($guid))
{
return true;
}
return false;
}

View File

@ -11,16 +11,16 @@
```uml
@startuml
class Response << (F,LightGreen) >> #Green {
# Translation $translation
# Chapter $chapter
# Scripture $scripture
# Prompt $prompt
# Load $load
# Config $config
# array $responses
+ __construct(Translation $translation, Chapter $chapter, ...)
+ get(?string $guid = null) : ?array
+ enough(?string $guid = null) : bool
+ total(?string $guid = null) : int
# int $total
+ __construct(Scripture $scripture, Prompt $prompt, ...)
+ get() : ?array
+ isEnough() : bool
+ getTotal() : int
}
note right of Response::__construct
@ -29,8 +29,7 @@ note right of Response::__construct
since: 2.0.1
arguments:
Translation $translation
Chapter $chapter
Scripture $scripture
Prompt $prompt
Load $load
Config $config
@ -43,14 +42,14 @@ note right of Response::get
return: ?array
end note
note right of Response::enough
note right of Response::isEnough
is there enough response messages
since: 2.0.1
return: bool
end note
note right of Response::total
note right of Response::getTotal
Get the total responses in cache
since: 2.0.1

View File

@ -12,8 +12,7 @@
namespace VDM\Joomla\GetBible\Data;
use VDM\Joomla\GetBible\Data\Translation;
use VDM\Joomla\GetBible\Data\Chapter;
use VDM\Joomla\GetBible\Data\Scripture;
use VDM\Joomla\GetBible\Data\Prompt;
use VDM\Joomla\GetBible\Database\Load;
use VDM\Joomla\GetBible\Openai\Config;
@ -27,20 +26,12 @@ use VDM\Joomla\GetBible\Openai\Config;
final class Response
{
/**
* The Translation class
* The Scripture class
*
* @var Translation
* @var Scripture
* @since 2.0.1
*/
protected Translation $translation;
/**
* The Chapter class
*
* @var Chapter
* @since 2.0.1
*/
protected Chapter $chapter;
protected Scripture $scripture;
/**
* The Prompt class
@ -74,21 +65,31 @@ final class Response
*/
protected array $responses = [];
/**
* The total responses
*
* @var int
* @since 2.0.1
*/
protected int $total = 0;
/**
* Constructor
*
* @param Translation $translation The translation object.
* @param Chapter $chapter The chapter object.
* @param Prompt $prompt The prompt object.
* @param Load $load The load object.
* @param Config $config The config object.
* @param Scripture $scripture The scripture object.
* @param Prompt $prompt The prompt object.
* @param Load $load The load object.
* @param Config $config The config object.
*
* @since 2.0.1
*/
public function __construct(Translation $translation, Chapter $chapter, Prompt $prompt, Load $load, Config $config)
public function __construct(
Scripture $scripture,
Prompt $prompt,
Load $load,
Config $config)
{
$this->translation = $translation;
$this->chapter = $chapter;
$this->scripture = $scripture;
$this->prompt = $prompt;
$this->load = $load;
$this->config = $config;
@ -97,15 +98,13 @@ final class Response
/**
* Get the responses
*
* @param string|null $guid The prompt guid.
*
* @return array|null True on success
* @since 2.0.1
*/
public function get(?string $guid = null): ?array
public function get(): ?array
{
// get the cache behaviour
$cache = $this->prompt->getCacheBehaviour($guid);
$cache = $this->prompt->getCacheBehaviour();
if (empty($cache) || ($cache != 1 && $cache != 2))
{
@ -113,7 +112,7 @@ final class Response
}
// load the prompt GUID
$guid = $guid ?? $this->config->get('prompt');
$guid = $this->config->get('prompt');
if ($guid === null)
{
@ -130,23 +129,23 @@ final class Response
if ($cache == 1)
{
// any empty string so cause no value to be returned
$query['language'] = $this->translation->getLanguage() ?? 'none__found';
$query['selected_words'] = $this->chapter->getWordText() ?? 'none__found';
$query['language'] = $this->scripture->get('translation_language', 'none__found');
$query['selected_word'] = $this->scripture->get('selected_word_text', 'none__found');
}
// Advanced Caching - Verse/Contex
else
{
// any empty string so cause no value to be returned
$query['abbreviation'] = $this->translation->getAbbreviation() ?? 'none__found';
$query['book'] = $this->chapter->getBookNumber() ?? 'none__found';
$query['chapter'] = $this->chapter->getChapterNumber() ?? 'none__found';
$query['verse'] = $this->chapter->getVerseNumber() ?? 'none__found';
$query['abbreviation'] = $this->scripture->get('translation_abbreviation', 'none__found');
$query['book'] = $this->scripture->get('book_number', 'none__found');
$query['chapter'] = $this->scripture->get('chapter_number', 'none__found');
$query['verse'] = $this->scripture->get('verse_number', 'none__found');
// get the integration
$integration = $this->prompt->getIntegration($guid);
$integration = $this->prompt->getIntegration();
if ($integration == 1 || $integration == 3)
{
$query['words'] = $this->chapter->getWordNumber() ?? 'none__found';
$query['word'] = $this->scripture->get('selected_word_number', 'none__found');
}
}
$bucket = $this->load->items($query, 'open_ai_response');
@ -157,14 +156,12 @@ final class Response
{
$response->messages = $this->load->items([
'prompt' => $guid,
'open_ai_response' => $response->guid,
'open_ai_response' => $response->response_id,
'published' => 1
], 'open_ai_message');
}
$this->responses[$guid] = $bucket;
$this->config->set('prompt', $guid);
}
}
@ -174,47 +171,30 @@ final class Response
/**
* 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
public function isEnough(): bool
{
return ($this->total($guid) >= $this->prompt->getCacheCapacity($guid));
return ($this->getTotal() >= $this->prompt->getCacheCapacity());
}
/**
* 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
public function getTotal(): int
{
$total = 0;
if (($responses = $this->get($guid)) === null)
if ($this->total > 0 || ($responses = $this->get()) === null)
{
return $total;
return $this->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++;
}
}
}
}
$this->total = count((array) $responses);
return $total;
return $this->total;
}
}

View File

@ -1,18 +1,10 @@
/**
* The Translation class
* The Scripture class
*
* @var Translation
* @var Scripture
* @since 2.0.1
*/
protected Translation $translation;
/**
* The Chapter class
*
* @var Chapter
* @since 2.0.1
*/
protected Chapter $chapter;
protected Scripture $scripture;
/**
* The Prompt class
@ -46,21 +38,31 @@
*/
protected array $responses = [];
/**
* The total responses
*
* @var int
* @since 2.0.1
*/
protected int $total = 0;
/**
* Constructor
*
* @param Translation $translation The translation object.
* @param Chapter $chapter The chapter object.
* @param Prompt $prompt The prompt object.
* @param Load $load The load object.
* @param Config $config The config object.
* @param Scripture $scripture The scripture object.
* @param Prompt $prompt The prompt object.
* @param Load $load The load object.
* @param Config $config The config object.
*
* @since 2.0.1
*/
public function __construct(Translation $translation, Chapter $chapter, Prompt $prompt, Load $load, Config $config)
public function __construct(
Scripture $scripture,
Prompt $prompt,
Load $load,
Config $config)
{
$this->translation = $translation;
$this->chapter = $chapter;
$this->scripture = $scripture;
$this->prompt = $prompt;
$this->load = $load;
$this->config = $config;
@ -69,15 +71,13 @@
/**
* Get the responses
*
* @param string|null $guid The prompt guid.
*
* @return array|null True on success
* @since 2.0.1
*/
public function get(?string $guid = null): ?array
public function get(): ?array
{
// get the cache behaviour
$cache = $this->prompt->getCacheBehaviour($guid);
$cache = $this->prompt->getCacheBehaviour();
if (empty($cache) || ($cache != 1 && $cache != 2))
{
@ -85,7 +85,7 @@
}
// load the prompt GUID
$guid = $guid ?? $this->config->get('prompt');
$guid = $this->config->get('prompt');
if ($guid === null)
{
@ -102,23 +102,23 @@
if ($cache == 1)
{
// any empty string so cause no value to be returned
$query['language'] = $this->translation->getLanguage() ?? 'none__found';
$query['selected_words'] = $this->chapter->getWordText() ?? 'none__found';
$query['language'] = $this->scripture->get('translation_language', 'none__found');
$query['selected_word'] = $this->scripture->get('selected_word_text', 'none__found');
}
// Advanced Caching - Verse/Contex
else
{
// any empty string so cause no value to be returned
$query['abbreviation'] = $this->translation->getAbbreviation() ?? 'none__found';
$query['book'] = $this->chapter->getBookNumber() ?? 'none__found';
$query['chapter'] = $this->chapter->getChapterNumber() ?? 'none__found';
$query['verse'] = $this->chapter->getVerseNumber() ?? 'none__found';
$query['abbreviation'] = $this->scripture->get('translation_abbreviation', 'none__found');
$query['book'] = $this->scripture->get('book_number', 'none__found');
$query['chapter'] = $this->scripture->get('chapter_number', 'none__found');
$query['verse'] = $this->scripture->get('verse_number', 'none__found');
// get the integration
$integration = $this->prompt->getIntegration($guid);
$integration = $this->prompt->getIntegration();
if ($integration == 1 || $integration == 3)
{
$query['words'] = $this->chapter->getWordNumber() ?? 'none__found';
$query['word'] = $this->scripture->get('selected_word_number', 'none__found');
}
}
$bucket = $this->load->items($query, 'open_ai_response');
@ -129,14 +129,12 @@
{
$response->messages = $this->load->items([
'prompt' => $guid,
'open_ai_response' => $response->guid,
'open_ai_response' => $response->response_id,
'published' => 1
], 'open_ai_message');
}
$this->responses[$guid] = $bucket;
$this->config->set('prompt', $guid);
}
}
@ -146,45 +144,28 @@
/**
* 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
public function isEnough(): bool
{
return ($this->total($guid) >= $this->prompt->getCacheCapacity($guid));
return ($this->getTotal() >= $this->prompt->getCacheCapacity());
}
/**
* 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
public function getTotal(): int
{
$total = 0;
if (($responses = $this->get($guid)) === null)
if ($this->total > 0 || ($responses = $this->get()) === null)
{
return $total;
return $this->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++;
}
}
}
}
$this->total = count((array) $responses);
return $total;
return $this->total;
}

View File

@ -11,22 +11,18 @@
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "c4098e1a-46dd-4d60-9277-b3668a09edc8",
"use": "17d87374-2953-4d6c-9fdd-4220d6ad1564",
"as": "default"
},
"use_selection1": {
"use": "4a4c786d-51f4-421a-aa61-262dfd071880",
"as": "default"
},
"use_selection2": {
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"as": "default"
},
"use_selection3": {
"use_selection2": {
"use": "c03b9c61-17d3-4774-a335-783903719f83",
"as": "default"
},
"use_selection4": {
"use_selection3": {
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
"as": "default"
}

View File

@ -13,173 +13,50 @@
class Chapter << (F,LightGreen) >> #Green {
# Load $load
# Config $config
# Prompt $prompt
# StringHelper $stringHelper
# array $chapters
# 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
+ getChapterText(?string $abbreviation = null, ?int $book = null, ...) : string
+ getVerseNumber(?string $abbreviation = null, ?int $book = null, ...) : string
+ getVerseName(?string $abbreviation = null, ?int $book = null, ...) : string
+ getVerseText(?string $abbreviation = null, ?int $book = null, ...) : string
+ getWordNumber(?string $abbreviation = null, ?int $book = null, ...) : string
+ getWordText(?string $abbreviation = null, ?int $book = null, ...) : string
+ get(?string $abbreviation = null, ?int $book = null, ...) : ?object
- generateCacheKey(string $abbreviation, int $book, ...) : string
+ __construct(Load $load, Config $config)
+ getNumber() : string
+ getName() : string
+ getText() : string
+ getVerses() : ?array
- get() : ?object
- loadChapterData(string $abbreviation, int $book, ...) : ?object
- active(?string $abbreviation = null, ?int $book = null, ...) : bool
- processVerses(?string $abbreviation, ?int $book, ...) : string
- processVersesArray(?string $abbreviation = null, ?int $book = null, ...) : ?array
- extractVerseNumbers(string $verseNumber) : array
- validateSelectedVerses(array $verseNumbers) : string
- getValidVerseRange() : ?array
- isValidWordNumber(int $verseNumber, int $wordNumber) : bool
- getTextFromVerses(array $verses, array $verseNumber) : array
- getArrayFromVerses(array $verses, array $verseNumber) : array
- getWordNumberArray(?string $abbreviation = null, ?int $book = null, ...) : ?array
- splitAndTrim(string $str) : array
- buildWordNumberArray(array $verse, array $words) : array
- wordNumberArrayToString(array $wordNumberArray) : string
- buildWordArray(array $verses, array $words) : array
- wordArrayToString(array $wordArray) : string
- isSequential(array $arr) : bool
- convertVersesToText(array $verses) : string
- generateCacheKey(string $abbreviation, int $book, ...) : string
}
note right of Chapter::__construct
Constructor
since: 2.0.1
arguments:
Load $load
Config $config
Prompt $prompt
StringHelper $stringHelper
end note
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
return: string
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note left of Chapter::getChapterNumber
note left of Chapter::getNumber
Get the chapter number
since: 2.0.1
return: string
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note right of Chapter::getChapterName
note right of Chapter::getName
Get the chapter name
since: 2.0.1
return: string
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note left of Chapter::getChapterText
note left of Chapter::getText
Get the chapter text
since: 2.0.1
return: string
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note right of Chapter::getVerseNumber
Get the verse number/s
note right of Chapter::getVerses
Get the chapter verses
since: 2.0.1
return: string
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note left of Chapter::getVerseName
Get the verse name
since: 2.0.1
return: string
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note right of Chapter::getVerseText
Get the verse text
since: 2.0.1
return: string
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note left of Chapter::getWordNumber
Get the word number/s
since: 2.0.1
return: string
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note right of Chapter::getWordText
Get the word text
since: 2.0.1
return: string
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
return: ?array
end note
note left of Chapter::get
@ -187,11 +64,25 @@ note left of Chapter::get
since: 2.0.1
return: ?object
end note
note right of Chapter::loadChapterData
Loads the chapter data from the database and updates the cache
since: 2.0.1
return: ?object
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
string $abbreviation
int $book
int $chapter
end note
note left of Chapter::convertVersesToText
Convert verses to text
since: 2.0.1
return: string
end note
note right of Chapter::generateCacheKey
@ -205,150 +96,6 @@ note right of Chapter::generateCacheKey
int $book
int $chapter
end note
note left of Chapter::loadChapterData
Loads the chapter data from the database and updates the cache
since: 2.0.1
return: ?object
arguments:
string $abbreviation
int $book
int $chapter
end note
note right of Chapter::active
Check if this chapter is active
since: 2.0.1
return: bool
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note left of Chapter::processVerses
Processes the verses to extract the verse text
since: 2.0.1
return: string
arguments:
?string $abbreviation
?int $book
?int $chapter
end note
note right of Chapter::processVersesArray
Processes the verses to extract the verse text
since: 2.0.1
return: ?array
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note left of Chapter::extractVerseNumbers
Extracts the verse numbers from the input string
since: 2.0.1
return: array
end note
note right of Chapter::validateSelectedVerses
Validate that these verse numbers exist in chapter
since: 2.0.1
return: string
end note
note left of Chapter::getValidVerseRange
Get the valid verse range
since: 2.0.1
return: ?array
end note
note right of Chapter::isValidWordNumber
Check if a word exist in a verse
since: 2.0.1
return: bool
end note
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 right of Chapter::getArrayFromVerses
Get the verses array based on the verse numbers
since: 2.0.1
return: array
end note
note left of Chapter::getWordNumberArray
Get the word number/s
since: 2.0.1
return: ?array
arguments:
?string $abbreviation = null
?int $book = null
?int $chapter = null
end note
note right of Chapter::splitAndTrim
Split verse or words by '-' and trim each element.
since: 2.0.1
return: array
end note
note left of Chapter::buildWordNumberArray
Build word number array from verse and words.
since: 2.0.1
return: array
end note
note right of Chapter::wordNumberArrayToString
Converts word number array to string.
since: 2.0.1
return: string
end note
note left of Chapter::buildWordArray
Build word array from verse and words.
since: 2.0.1
return: array
end note
note right of Chapter::wordArrayToString
Converts word array to string.
since: 2.0.1
return: string
end note
note left of Chapter::isSequential
Check if an array values is sequential.
since: 2.0.1
return: bool
end note
@enduml
```

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@ -17,14 +17,6 @@
"use_selection1": {
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
"as": "default"
},
"use_selection2": {
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"as": "default"
},
"use_selection3": {
"use": "a5b32737-207d-4cf6-b8ae-ee815612c3a0",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\GetBible\\Data.Chapter",

View File

@ -0,0 +1,156 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Word (Details)
> namespace: **VDM\Joomla\GetBible\Data**
```uml
@startuml
class Word << (F,LightGreen) >> #Green {
# Verse $verse
# Config $config
# Prompt $prompt
# array $words
# array $sequential
# ?array $verses
# ?array $valid
+ __construct(Verse $verse, Config $config, ...)
+ getNumber() : string
+ getText() : string
- get() : ?object
- loadWordData(string $cacheKey, string $verses, ...) : ?object
- selectedWordNumbers(string $verse, string $words) : array
- selectedWordNumbersToString(array $wordNumberArray) : string
- selectedWord(array $words) : array
- selectedWordToString(array $wordArray) : string
- splitAndTrim(string $str) : array
- isValidWordNumber(int $verseNumber, int $wordNumber) : bool
- isSequential(array $arr) : bool
- generateCacheKey(string $abbreviation, int $book, ...) : string
}
note right of Word::__construct
Constructor
since: 2.0.1
arguments:
Verse $verse
Config $config
Prompt $prompt
end note
note left of Word::getNumber
Get the word number/s
since: 2.0.1
return: string
end note
note right of Word::getText
Get the word text
since: 2.0.1
return: string
end note
note left of Word::get
Get the words
since: 2.0.1
return: ?object
end note
note right of Word::loadWordData
Loads the word data
since: 2.0.1
return: ?object
arguments:
string $cacheKey
string $verses
string $words
end note
note left of Word::selectedWordNumbers
Build word number array from verse and words.
since: 2.0.1
return: array
end note
note right of Word::selectedWordNumbersToString
Converts word number array to string.
since: 2.0.1
return: string
end note
note left of Word::selectedWord
Build word array from verse and words.
since: 2.0.1
return: array
end note
note right of Word::selectedWordToString
Converts word array to string.
since: 2.0.1
return: string
end note
note left of Word::splitAndTrim
Split string by '-' and trim each element.
since: 2.0.1
return: array
end note
note right of Word::isValidWordNumber
Check if a word exist in a verse
since: 2.0.1
return: bool
end note
note left of Word::isSequential
Check if an array values is sequential.
since: 2.0.1
return: bool
end note
note right of Word::generateCacheKey
Generates a cache key based on the abbreviation, book, chapter, verses, and words
since: 2.0.1
return: string
arguments:
string $abbreviation
int $book
int $chapter
string $verses
string $words
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,391 @@
<?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\Data;
use VDM\Joomla\GetBible\Data\Verse;
use VDM\Joomla\GetBible\Openai\Config;
use VDM\Joomla\GetBible\Data\Prompt;
/**
* The GetBible Word Data
*
* @since 2.0.1
*/
final class Word
{
/**
* The Verse class
*
* @var Verse
* @since 2.0.1
*/
protected Verse $verse;
/**
* The Config class
*
* @var Config
* @since 2.0.1
*/
protected Config $config;
/**
* The Prompt class
*
* @var Prompt
* @since 2.0.1
*/
protected Prompt $prompt;
/**
* The words
*
* @var array
* @since 2.0.1
*/
protected array $words = [];
/**
* The check if words are sequential
*
* @var array
* @since 2.0.1
*/
protected array $sequential = [];
/**
* The active verses
*
* @var array|null
* @since 2.0.1
*/
protected ?array $verses = null;
/**
* The valid verse numbers
*
* @var array|null
* @since 2.0.1
*/
protected ?array $valid = null;
/**
* Constructor
*
* @param Verse $verse The verse object.
* @param Config $config The config object.
* @param Prompt $prompt The prompt object.
*
* @since 2.0.1
*/
public function __construct(Verse $verse, Config $config, Prompt $prompt)
{
$this->verse = $verse;
$this->config = $config;
$this->prompt = $prompt;
}
/**
* Get the word number/s
*
* @return string The word number/s
* @since 2.0.1
*/
public function getNumber(): string
{
$word = $this->get();
return $word ? $word->number ?? '' : '';
}
/**
* Get the word text
*
* @return string The verse text
* @since 2.0.1
*/
public function getText(): string
{
$word = $this->get();
return $word ? $word->text ?? '' : '';
}
/**
* Get the words
*
* @return object|null True on success
* @since 2.0.1
*/
private function get(): ?object
{
$abbreviation = $this->config->get('translation');
$book = $this->config->get('book');
$chapter = $this->config->get('chapter');
$verse = $this->config->get('verse');
$words = $this->config->get('words');
if (empty($abbreviation) || empty($book) || empty($chapter) || empty($verse) || empty($words))
{
return null;
}
$cacheKey = $this->generateCacheKey($abbreviation, $book, $chapter, $verse, $words);
if (isset($this->words[$cacheKey]))
{
return $this->words[$cacheKey];
}
return $this->loadWordData($cacheKey, $verse, $words);
}
/**
* Loads the word data
*
* @param string $cacheKey The cache key.
* @param string $verses The selected verses.
* @param string $words The selected words.
*
* @return object|null The loaded word data, or null if not found or an error occurred.
* @since 2.0.1
*/
private function loadWordData(string $cacheKey, string $verses, string $words): ?object
{
$this->valid = $this->verse->getValid();
$this->verses = $this->verse->getVerse();
if (empty($this->verses) || empty($this->valid))
{
$this->words[$cacheKey] = null;
return null;
}
$data = new \stdClass();
$data->number_array = $this->selectedWordNumbers($verses, $words);
if (empty($data->number_array))
{
$this->words[$cacheKey] = null;
return null;
}
$data->number = $this->selectedWordNumbersToString($data->number_array);
$data->text_array = $this->selectedWord($data->number_array);
if (empty($data->text_array))
{
$this->words[$cacheKey] = null;
return null;
}
$data->text = $this->selectedWordToString($data->text_array);
$this->words[$cacheKey] = $data;
return $this->words[$cacheKey];
}
/**
* Build word number array from verse and words.
*
* @param string $verse The verse selected.
* @param string $words The words words.
*
* @return array The word number array.
* @since 2.0.1
*/
private function selectedWordNumbers(string $verse, string $words): array
{
$verse = $this->splitAndTrim($verse);
$words = $this->splitAndTrim($words);
$array = [];
$integration = $this->prompt->getIntegration();
$this->sequential = [];
foreach ($verse as $key => $verse)
{
if (isset($words[$key]) && in_array($verse, $this->valid) &&
$this->isValidWordNumber($verse, $words[$key]))
{
$array[$verse][] = $words[$key];
if ($integration == 1)
{
break;
}
}
}
return $array;
}
/**
* Converts word number array to string.
*
* @param array $wordNumberArray The word number array.
*
* @return string The word number string.
* @since 2.0.1
*/
private function selectedWordNumbersToString(array $wordNumberArray): string
{
$word_number = [];
if (count($wordNumberArray) == 1)
{
$word_number[] = implode(',', array_values($wordNumberArray)[0]);
}
else
{
foreach ($wordNumberArray as $verse => $words)
{
$word_number[] = $verse . ':' . implode(',', $words);
}
}
return implode(';', $word_number);
}
/**
* Build word array from verse and words.
*
* @param array $words The words array.
*
* @return array The word array.
* @since 2.0.1
*/
private function selectedWord(array $words): array
{
$word_array = [];
foreach ($words as $verse => $word_numbers)
{
foreach ($word_numbers as $word)
{
if (isset($this->verses[$verse][$word]))
{
$word_array[$verse][] = $this->verses[$verse][$word];
}
}
}
return $word_array;
}
/**
* Converts word array to string.
*
* @param array $wordArray The word array.
*
* @return string The word string.
* @since 2.0.1
*/
private function selectedWordToString(array $wordArray): string
{
$word_number = [];
foreach ($wordArray as $verse => $words)
{
$word_number[] = implode(' ', $words);
}
return implode(' ', $word_number);
}
/**
* Split string by '-' and trim each element.
*
* @param string $str The string to be split.
*
* @return array The splitted and trimmed array.
* @since 2.0.1
*/
private function splitAndTrim(string $str): array
{
if (strpos($str, '-') !== false)
{
$array = array_map('trim', explode('-', $str));
sort($array);
return $array;
}
return [trim($str)];
}
/**
* Check if a word exist in a verse
*
* @param int $verseNumber The verse number.
* @param int $wordNumber The word number.
*
* @return bool True on success
* @since 2.0.1
*/
private function isValidWordNumber(int $verseNumber, int $wordNumber): bool
{
// we add the next word number to check sequential selection of words
$this->sequential[$verseNumber][$wordNumber] = $wordNumber;
if (count($this->sequential[$verseNumber]) > 1 && !$this->isSequential($this->sequential[$verseNumber]))
{
return false;
}
return isset($this->verses[$verseNumber][$wordNumber]);
}
/**
* Check if an array values is sequential.
*
* @param array $arr The number array.
*
* @return bool true if sequential
* @since 2.0.1
*/
private function isSequential(array $arr): bool
{
$arr = array_values($arr); // Reset keys
for ($i = 0, $len = count($arr) - 1; $i < $len; $i++)
{
if ($arr[$i] + 1 !== $arr[$i + 1])
{
return false;
}
}
return true;
}
/**
* Generates a cache key based on the abbreviation, book, chapter, verses, and words
*
* @param string $abbreviation The translation abbreviation.
* @param int $book The book number.
* @param int $chapter The chapter number.
* @param string $verses The selected verses.
* @param string $words The selected words.
*
* @return string The generated cache key.
* @since 2.0.1
*/
private function generateCacheKey($abbreviation, $book, int $chapter, string $verses, string $words): string
{
return $abbreviation . '_' . $book . '_' . $chapter . '_' . $verses . '_' . $words;
}
}

View File

@ -0,0 +1,363 @@
/**
* The Verse class
*
* @var Verse
* @since 2.0.1
*/
protected Verse $verse;
/**
* The Config class
*
* @var Config
* @since 2.0.1
*/
protected Config $config;
/**
* The Prompt class
*
* @var Prompt
* @since 2.0.1
*/
protected Prompt $prompt;
/**
* The words
*
* @var array
* @since 2.0.1
*/
protected array $words = [];
/**
* The check if words are sequential
*
* @var array
* @since 2.0.1
*/
protected array $sequential = [];
/**
* The active verses
*
* @var array|null
* @since 2.0.1
*/
protected ?array $verses = null;
/**
* The valid verse numbers
*
* @var array|null
* @since 2.0.1
*/
protected ?array $valid = null;
/**
* Constructor
*
* @param Verse $verse The verse object.
* @param Config $config The config object.
* @param Prompt $prompt The prompt object.
*
* @since 2.0.1
*/
public function __construct(Verse $verse, Config $config, Prompt $prompt)
{
$this->verse = $verse;
$this->config = $config;
$this->prompt = $prompt;
}
/**
* Get the word number/s
*
* @return string The word number/s
* @since 2.0.1
*/
public function getNumber(): string
{
$word = $this->get();
return $word ? $word->number ?? '' : '';
}
/**
* Get the word text
*
* @return string The verse text
* @since 2.0.1
*/
public function getText(): string
{
$word = $this->get();
return $word ? $word->text ?? '' : '';
}
/**
* Get the words
*
* @return object|null True on success
* @since 2.0.1
*/
private function get(): ?object
{
$abbreviation = $this->config->get('translation');
$book = $this->config->get('book');
$chapter = $this->config->get('chapter');
$verse = $this->config->get('verse');
$words = $this->config->get('words');
if (empty($abbreviation) || empty($book) || empty($chapter) || empty($verse) || empty($words))
{
return null;
}
$cacheKey = $this->generateCacheKey($abbreviation, $book, $chapter, $verse, $words);
if (isset($this->words[$cacheKey]))
{
return $this->words[$cacheKey];
}
return $this->loadWordData($cacheKey, $verse, $words);
}
/**
* Loads the word data
*
* @param string $cacheKey The cache key.
* @param string $verses The selected verses.
* @param string $words The selected words.
*
* @return object|null The loaded word data, or null if not found or an error occurred.
* @since 2.0.1
*/
private function loadWordData(string $cacheKey, string $verses, string $words): ?object
{
$this->valid = $this->verse->getValid();
$this->verses = $this->verse->getVerse();
if (empty($this->verses) || empty($this->valid))
{
$this->words[$cacheKey] = null;
return null;
}
$data = new \stdClass();
$data->number_array = $this->selectedWordNumbers($verses, $words);
if (empty($data->number_array))
{
$this->words[$cacheKey] = null;
return null;
}
$data->number = $this->selectedWordNumbersToString($data->number_array);
$data->text_array = $this->selectedWord($data->number_array);
if (empty($data->text_array))
{
$this->words[$cacheKey] = null;
return null;
}
$data->text = $this->selectedWordToString($data->text_array);
$this->words[$cacheKey] = $data;
return $this->words[$cacheKey];
}
/**
* Build word number array from verse and words.
*
* @param string $verse The verse selected.
* @param string $words The words words.
*
* @return array The word number array.
* @since 2.0.1
*/
private function selectedWordNumbers(string $verse, string $words): array
{
$verse = $this->splitAndTrim($verse);
$words = $this->splitAndTrim($words);
$array = [];
$integration = $this->prompt->getIntegration();
$this->sequential = [];
foreach ($verse as $key => $verse)
{
if (isset($words[$key]) && in_array($verse, $this->valid) &&
$this->isValidWordNumber($verse, $words[$key]))
{
$array[$verse][] = $words[$key];
if ($integration == 1)
{
break;
}
}
}
return $array;
}
/**
* Converts word number array to string.
*
* @param array $wordNumberArray The word number array.
*
* @return string The word number string.
* @since 2.0.1
*/
private function selectedWordNumbersToString(array $wordNumberArray): string
{
$word_number = [];
if (count($wordNumberArray) == 1)
{
$word_number[] = implode(',', array_values($wordNumberArray)[0]);
}
else
{
foreach ($wordNumberArray as $verse => $words)
{
$word_number[] = $verse . ':' . implode(',', $words);
}
}
return implode(';', $word_number);
}
/**
* Build word array from verse and words.
*
* @param array $words The words array.
*
* @return array The word array.
* @since 2.0.1
*/
private function selectedWord(array $words): array
{
$word_array = [];
foreach ($words as $verse => $word_numbers)
{
foreach ($word_numbers as $word)
{
if (isset($this->verses[$verse][$word]))
{
$word_array[$verse][] = $this->verses[$verse][$word];
}
}
}
return $word_array;
}
/**
* Converts word array to string.
*
* @param array $wordArray The word array.
*
* @return string The word string.
* @since 2.0.1
*/
private function selectedWordToString(array $wordArray): string
{
$word_number = [];
foreach ($wordArray as $verse => $words)
{
$word_number[] = implode(' ', $words);
}
return implode(' ', $word_number);
}
/**
* Split string by '-' and trim each element.
*
* @param string $str The string to be split.
*
* @return array The splitted and trimmed array.
* @since 2.0.1
*/
private function splitAndTrim(string $str): array
{
if (strpos($str, '-') !== false)
{
$array = array_map('trim', explode('-', $str));
sort($array);
return $array;
}
return [trim($str)];
}
/**
* Check if a word exist in a verse
*
* @param int $verseNumber The verse number.
* @param int $wordNumber The word number.
*
* @return bool True on success
* @since 2.0.1
*/
private function isValidWordNumber(int $verseNumber, int $wordNumber): bool
{
// we add the next word number to check sequential selection of words
$this->sequential[$verseNumber][$wordNumber] = $wordNumber;
if (count($this->sequential[$verseNumber]) > 1 && !$this->isSequential($this->sequential[$verseNumber]))
{
return false;
}
return isset($this->verses[$verseNumber][$wordNumber]);
}
/**
* Check if an array values is sequential.
*
* @param array $arr The number array.
*
* @return bool true if sequential
* @since 2.0.1
*/
private function isSequential(array $arr): bool
{
$arr = array_values($arr); // Reset keys
for ($i = 0, $len = count($arr) - 1; $i < $len; $i++)
{
if ($arr[$i] + 1 !== $arr[$i + 1])
{
return false;
}
}
return true;
}
/**
* Generates a cache key based on the abbreviation, book, chapter, verses, and words
*
* @param string $abbreviation The translation abbreviation.
* @param int $book The book number.
* @param int $chapter The chapter number.
* @param string $verses The selected verses.
* @param string $words The selected words.
*
* @return string The generated cache key.
* @since 2.0.1
*/
private function generateCacheKey($abbreviation, $book, int $chapter, string $verses, string $words): string
{
return $abbreviation . '_' . $book . '_' . $chapter . '_' . $verses . '_' . $words;
}

View File

@ -0,0 +1,31 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "899551ac-943e-4f81-becd-7e15c41f1081",
"implements": null,
"load_selection": null,
"name": "Word",
"power_version": "1.0.0",
"system_name": "Joomla.GetBible.Data.Word",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "e3798c7e-aae1-4e38-ba78-6018ce94630b",
"as": "default"
},
"use_selection1": {
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
"as": "default"
},
"use_selection2": {
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\GetBible\\Data.Word",
"description": "The GetBible Word Data\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": ""
}

View File

@ -12,7 +12,7 @@
namespace VDM\Joomla\GetBible\Model;
use VDM\Joomla\GetBible\Config;
use VDM\Joomla\Abstraction\BaseConfig as Config;
use VDM\Joomla\GetBible\Table;
use VDM\Joomla\Utilities\ObjectHelper;
use VDM\Joomla\Interfaces\ModelInterface;

View File

@ -13,14 +13,14 @@
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "71075f03-4e77-4fc0-840a-ef55fd9260b2",
"as": "default"
"use": "ffbd4e1f-a342-4080-ab7d-1de3741bf319",
"as": "Config"
},
"use_selection1": {
"use": "ff8d5fdb-2d1f-4178-bd18-a43b8efd1068",
"as": "default"
},
"use_selection4": {
"use_selection2": {
"use": "91004529-94a9-4590-b842-e7c6b624ecf5",
"as": "default"
}

View File

@ -57,7 +57,8 @@ final class StringHelper
public function splitToWords(string $text, bool $punctuation = true): array
{
$words = array_filter($this->split($text), function($word) {
if ($this->hasLength($word)) {
$plain_word = preg_replace('/[^\p{L}\p{N}\s]/u', '', $word);
if ($this->hasLength($plain_word)) {
return true;
} return false;
});

View File

@ -36,7 +36,8 @@
public function splitToWords(string $text, bool $punctuation = true): array
{
$words = array_filter($this->split($text), function($word) {
if ($this->hasLength($word)) {
$plain_word = preg_replace('/[^\p{L}\p{N}\s]/u', '', $word);
if ($this->hasLength($plain_word)) {
return true;
} return false;
});

View File

@ -13,7 +13,7 @@
class AI #Gold {
+ register(Container $container) : void
+ getAI(Container $container) : GetBible
+ getWorker(Container $container) : Worker
+ getEngineer(Container $container) : Engineer
}
note right of AI::register
@ -30,11 +30,11 @@ note right of AI::getAI
return: GetBible
end note
note right of AI::getWorker
Get the Worker AI class
note right of AI::getEngineer
Get the Engineer AI class
since: 3.2.0
return: Worker
return: Engineer
end note
@enduml

View File

@ -15,7 +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;
use VDM\Joomla\GetBible\AI\Engineer;
/**
@ -38,8 +38,8 @@ 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);
$container->alias(Engineer::class, 'GetBible.AI.Engineer')
->share('GetBible.AI.Engineer', [$this, 'getEngineer'], true);
}
/**
@ -53,25 +53,28 @@ class AI implements ServiceProviderInterface
public function getAI(Container $container): GetBible
{
return new GetBible(
$container->get('GetBible.Prompt'),
$container->get('GetBible.Config'),
$container->get('GetBible.Response'),
$container->get('GetBible.AI.Worker')
$container->get('GetBible.AI.Engineer')
);
}
/**
* Get the Worker AI class
* Get the Engineer AI class
*
* @param Container $container The DI container.
*
* @return Worker
* @return Engineer
* @since 3.2.0
*/
public function getWorker(Container $container): Worker
public function getEngineer(Container $container): Engineer
{
return new Worker(
return new Engineer(
$container->get('GetBible.Scripture'),
$container->get('GetBible.Prompt'),
$container->get('GetBible.Response')
$container->get('GetBible.Placeholders'),
$container->get('Openai.Chat'),
$container->get('GetBible.Insert')
);
}
}

View File

@ -11,8 +11,8 @@
$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);
$container->alias(Engineer::class, 'GetBible.AI.Engineer')
->share('GetBible.AI.Engineer', [$this, 'getEngineer'], true);
}
/**
@ -26,24 +26,27 @@
public function getAI(Container $container): GetBible
{
return new GetBible(
$container->get('GetBible.Prompt'),
$container->get('GetBible.Config'),
$container->get('GetBible.Response'),
$container->get('GetBible.AI.Worker')
$container->get('GetBible.AI.Engineer')
);
}
/**
* Get the Worker AI class
* Get the Engineer AI class
*
* @param Container $container The DI container.
*
* @return Worker
* @return Engineer
* @since 3.2.0
*/
public function getWorker(Container $container): Worker
public function getEngineer(Container $container): Engineer
{
return new Worker(
return new Engineer(
$container->get('GetBible.Scripture'),
$container->get('GetBible.Prompt'),
$container->get('GetBible.Response')
$container->get('GetBible.Placeholders'),
$container->get('Openai.Chat'),
$container->get('GetBible.Insert')
);
}

View File

@ -11,10 +11,9 @@
```uml
@startuml
class Placeholders << (F,LightGreen) >> #Green {
# Translation $translation
# Chapter $chapter
# Scripture $scripture
# Prompt $prompt
+ __construct(Translation $translation, Chapter $chapter, ...)
+ __construct(Scripture $scripture, Prompt $prompt)
+ get() : array
- all() : array
- without() : array
@ -25,11 +24,6 @@ note right of Placeholders::__construct
Constructor
since: 2.0.1
arguments:
Translation $translation
Chapter $chapter
Prompt $prompt
end note
note right of Placeholders::get

View File

@ -12,8 +12,7 @@
namespace VDM\Joomla\GetBible\Data;
use VDM\Joomla\GetBible\Data\Translation;
use VDM\Joomla\GetBible\Data\Chapter;
use VDM\Joomla\GetBible\Data\Scripture;
use VDM\Joomla\GetBible\Data\Prompt;
@ -25,20 +24,12 @@ use VDM\Joomla\GetBible\Data\Prompt;
final class Placeholders
{
/**
* The Translation class
* The Scripture class
*
* @var Translation
* @var Scripture
* @since 2.0.1
*/
protected Translation $translation;
/**
* The Chapter class
*
* @var Chapter
* @since 2.0.1
*/
protected Chapter $chapter;
protected Scripture $scripture;
/**
* The Prompt class
@ -51,25 +42,23 @@ final class Placeholders
/**
* Constructor
*
* @param Translation $translation The translation object.
* @param Chapter $chapter The chapter object.
* @param Prompt $prompt The prompt object.
* @param Scripture $scripture The scripture object.
* @param Prompt $prompt The prompt object.
*
* @since 2.0.1
*/
public function __construct(Translation $translation, Chapter $chapter, Prompt $prompt)
public function __construct(
Scripture $scripture,
Prompt $prompt)
{
$this->translation = $translation;
$this->chapter = $chapter;
$this->scripture = $scripture;
$this->prompt = $prompt;
}
/**
* Get the Open AI response
*
* @param string $guid The prompt guid.
*
* @return array|null Array of response messages
* @return array Array of response messages
* @since 2.0.1
*/
public function get(): array
@ -103,19 +92,20 @@ final class Placeholders
private function all(): array
{
return [
'[translation_name]' => $this->translation->getName(),
'[translation_language]' => $this->translation->getLanguage(),
'[translation_lcsh]' => $this->translation->getLcsh(),
'[translation_abbreviation]' => $this->translation->getAbbreviation(),
'[book_name]' => $this->chapter->getBookName(),
'[chapter_number]' => $this->chapter->getChapterNumber(),
'[chapter_name]' => $this->chapter->getChapterName(),
'[chapter_text]' => $this->chapter->getChapterText(),
'[verse_number]' => $this->chapter->getVerseNumber(),
'[verse_name]' => $this->chapter->getVerseName(),
'[verse_text]' => $this->chapter->getVerseText(),
'[selected_words_number]' => $this->chapter->getWordNumber(),
'[selected_word]' => $this->chapter->getWordText()
'[translation_name]' => $this->scripture->get('translation_name', ''),
'[translation_language]' => $this->scripture->get('translation_language', ''),
'[translation_lcsh]' => $this->scripture->get('translation_lcsh', ''),
'[translation_abbreviation]' => $this->scripture->get('translation_abbreviation', ''),
'[book_number]' => $this->scripture->get('book_number', ''),
'[book_name]' => $this->scripture->get('book_name', ''),
'[chapter_number]' => $this->scripture->get('chapter_number', ''),
'[chapter_name]' => $this->scripture->get('chapter_name', ''),
'[chapter_text]' => $this->scripture->get('chapter_text', ''),
'[verse_number]' => $this->scripture->get('verse_number', ''),
'[verse_name]' => $this->scripture->get('verse_name', ''),
'[verse_text]' => $this->scripture->get('verse_text', ''),
'[selected_word_number]' => $this->scripture->get('selected_word_number', ''),
'[selected_word_text]' => $this->scripture->get('selected_word_text', '')
];
}
@ -128,17 +118,18 @@ final class Placeholders
private function without(): array
{
return [
'[translation_name]' => $this->translation->getName(),
'[translation_language]' => $this->translation->getLanguage(),
'[translation_lcsh]' => $this->translation->getLcsh(),
'[translation_abbreviation]' => $this->translation->getAbbreviation(),
'[book_name]' => $this->chapter->getBookName(),
'[chapter_number]' => $this->chapter->getChapterNumber(),
'[chapter_name]' => $this->chapter->getChapterName(),
'[chapter_text]' => $this->chapter->getChapterText(),
'[verse_number]' => $this->chapter->getVerseNumber(),
'[verse_name]' => $this->chapter->getVerseName(),
'[verse_text]' => $this->chapter->getVerseText()
'[translation_name]' => $this->scripture->get('translation_name', ''),
'[translation_language]' => $this->scripture->get('translation_language', ''),
'[translation_lcsh]' => $this->scripture->get('translation_lcsh', ''),
'[translation_abbreviation]' => $this->scripture->get('translation_abbreviation', ''),
'[book_number]' => $this->scripture->get('book_number', ''),
'[book_name]' => $this->scripture->get('book_name', ''),
'[chapter_number]' => $this->scripture->get('chapter_number', ''),
'[chapter_name]' => $this->scripture->get('chapter_name', ''),
'[chapter_text]' => $this->scripture->get('chapter_text', ''),
'[verse_number]' => $this->scripture->get('verse_number', ''),
'[verse_name]' => $this->scripture->get('verse_name', ''),
'[verse_text]' => $this->scripture->get('verse_text', '')
];
}
@ -151,9 +142,9 @@ final class Placeholders
private function words(): array
{
return [
'[translation_language]' => $this->translation->getLanguage(),
'[translation_lcsh]' => $this->translation->getLcsh(),
'[selected_word]' => $this->chapter->getWordText()
'[translation_language]' => $this->scripture->get('translation_language', ''),
'[translation_lcsh]' => $this->scripture->get('translation_lcsh', ''),
'[selected_word_text]' => $this->scripture->get('selected_word_text', '')
];
}
}

View File

@ -1,18 +1,10 @@
/**
* The Translation class
* The Scripture class
*
* @var Translation
* @var Scripture
* @since 2.0.1
*/
protected Translation $translation;
/**
* The Chapter class
*
* @var Chapter
* @since 2.0.1
*/
protected Chapter $chapter;
protected Scripture $scripture;
/**
* The Prompt class
@ -25,25 +17,23 @@
/**
* Constructor
*
* @param Translation $translation The translation object.
* @param Chapter $chapter The chapter object.
* @param Prompt $prompt The prompt object.
* @param Scripture $scripture The scripture object.
* @param Prompt $prompt The prompt object.
*
* @since 2.0.1
*/
public function __construct(Translation $translation, Chapter $chapter, Prompt $prompt)
public function __construct(
Scripture $scripture,
Prompt $prompt)
{
$this->translation = $translation;
$this->chapter = $chapter;
$this->scripture = $scripture;
$this->prompt = $prompt;
}
/**
* Get the Open AI response
*
* @param string $guid The prompt guid.
*
* @return array|null Array of response messages
* @return array Array of response messages
* @since 2.0.1
*/
public function get(): array
@ -77,19 +67,20 @@
private function all(): array
{
return [
'[translation_name]' => $this->translation->getName(),
'[translation_language]' => $this->translation->getLanguage(),
'[translation_lcsh]' => $this->translation->getLcsh(),
'[translation_abbreviation]' => $this->translation->getAbbreviation(),
'[book_name]' => $this->chapter->getBookName(),
'[chapter_number]' => $this->chapter->getChapterNumber(),
'[chapter_name]' => $this->chapter->getChapterName(),
'[chapter_text]' => $this->chapter->getChapterText(),
'[verse_number]' => $this->chapter->getVerseNumber(),
'[verse_name]' => $this->chapter->getVerseName(),
'[verse_text]' => $this->chapter->getVerseText(),
'[selected_words_number]' => $this->chapter->getWordNumber(),
'[selected_word]' => $this->chapter->getWordText()
'[translation_name]' => $this->scripture->get('translation_name', ''),
'[translation_language]' => $this->scripture->get('translation_language', ''),
'[translation_lcsh]' => $this->scripture->get('translation_lcsh', ''),
'[translation_abbreviation]' => $this->scripture->get('translation_abbreviation', ''),
'[book_number]' => $this->scripture->get('book_number', ''),
'[book_name]' => $this->scripture->get('book_name', ''),
'[chapter_number]' => $this->scripture->get('chapter_number', ''),
'[chapter_name]' => $this->scripture->get('chapter_name', ''),
'[chapter_text]' => $this->scripture->get('chapter_text', ''),
'[verse_number]' => $this->scripture->get('verse_number', ''),
'[verse_name]' => $this->scripture->get('verse_name', ''),
'[verse_text]' => $this->scripture->get('verse_text', ''),
'[selected_word_number]' => $this->scripture->get('selected_word_number', ''),
'[selected_word_text]' => $this->scripture->get('selected_word_text', '')
];
}
@ -102,17 +93,18 @@
private function without(): array
{
return [
'[translation_name]' => $this->translation->getName(),
'[translation_language]' => $this->translation->getLanguage(),
'[translation_lcsh]' => $this->translation->getLcsh(),
'[translation_abbreviation]' => $this->translation->getAbbreviation(),
'[book_name]' => $this->chapter->getBookName(),
'[chapter_number]' => $this->chapter->getChapterNumber(),
'[chapter_name]' => $this->chapter->getChapterName(),
'[chapter_text]' => $this->chapter->getChapterText(),
'[verse_number]' => $this->chapter->getVerseNumber(),
'[verse_name]' => $this->chapter->getVerseName(),
'[verse_text]' => $this->chapter->getVerseText()
'[translation_name]' => $this->scripture->get('translation_name', ''),
'[translation_language]' => $this->scripture->get('translation_language', ''),
'[translation_lcsh]' => $this->scripture->get('translation_lcsh', ''),
'[translation_abbreviation]' => $this->scripture->get('translation_abbreviation', ''),
'[book_number]' => $this->scripture->get('book_number', ''),
'[book_name]' => $this->scripture->get('book_name', ''),
'[chapter_number]' => $this->scripture->get('chapter_number', ''),
'[chapter_name]' => $this->scripture->get('chapter_name', ''),
'[chapter_text]' => $this->scripture->get('chapter_text', ''),
'[verse_number]' => $this->scripture->get('verse_number', ''),
'[verse_name]' => $this->scripture->get('verse_name', ''),
'[verse_text]' => $this->scripture->get('verse_text', '')
];
}
@ -125,8 +117,8 @@
private function words(): array
{
return [
'[translation_language]' => $this->translation->getLanguage(),
'[translation_lcsh]' => $this->translation->getLcsh(),
'[selected_word]' => $this->chapter->getWordText()
'[translation_language]' => $this->scripture->get('translation_language', ''),
'[translation_lcsh]' => $this->scripture->get('translation_lcsh', ''),
'[selected_word_text]' => $this->scripture->get('selected_word_text', '')
];
}

View File

@ -11,14 +11,10 @@
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "c4098e1a-46dd-4d60-9277-b3668a09edc8",
"use": "17d87374-2953-4d6c-9fdd-4220d6ad1564",
"as": "default"
},
"use_selection1": {
"use": "4a4c786d-51f4-421a-aa61-262dfd071880",
"as": "default"
},
"use_selection2": {
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"as": "default"
}

View File

@ -15,12 +15,11 @@ class Translation << (F,LightGreen) >> #Green {
# Config $config
# array $translations
+ __construct(Load $load, Config $config)
+ getName(?string $abbreviation = null) : string
+ getLanguage(?string $abbreviation = null) : string
+ getLcsh(?string $abbreviation = null) : string
+ getAbbreviation(?string $abbreviation = null) : string
+ get(?string $abbreviation = null) : ?object
- active(?string $abbreviation = null) : bool
+ getName() : string
+ getLanguage() : string
+ getLcsh() : string
+ getAbbreviation() : string
+ get() : ?object
}
note right of Translation::__construct
@ -63,13 +62,6 @@ note right of Translation::get
since: 2.0.1
return: ?object
end note
note right of Translation::active
Check if the language is active
since: 2.0.1
return: bool
end note
@enduml
```

View File

@ -64,90 +64,64 @@ final class Translation
/**
* Get the translation name
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return string The translation name
* @since 2.0.1
*/
public function getName(?string $abbreviation = null): string
public function getName(): string
{
if ($this->active($abbreviation))
{
return $this->get($abbreviation)->translation ?? '';
}
return '';
$translation = $this->get();
return $translation ? $translation->translation ?? '' : '';
}
/**
* Get the translation language
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return string The translation language
* @since 2.0.1
*/
public function getLanguage(?string $abbreviation = null): string
public function getLanguage(): string
{
if ($this->active($abbreviation))
{
$lang = trim(preg_replace('/Bible\.?/', '', $this->get($abbreviation)->distribution_lcsh));
return $this->get($abbreviation)->language ?? $lang;
}
return '';
$translation = $this->get();
$lang = trim(preg_replace('/Bible\.?/', '', $this->getLcsh()));
return $translation ? $translation->language ?? $lang : '';
}
/**
* Get the translation distribution lcsh
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return string The translation lcsh
* @since 2.0.1
*/
public function getLcsh(?string $abbreviation = null): string
public function getLcsh(): string
{
if ($this->active($abbreviation))
{
return $this->get($abbreviation)->distribution_lcsh ?? '';
}
return '';
$translation = $this->get();
return $translation ? $translation->distribution_lcsh ?? '' : '';
}
/**
* Get the translation abbreviation
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return string The translation abbreviation
* @since 2.0.1
*/
public function getAbbreviation(?string $abbreviation = null): string
public function getAbbreviation(): string
{
if ($this->active($abbreviation))
{
return $this->get($abbreviation)->abbreviation ?? '';
}
return '';
$translation = $this->get();
return $translation ? $translation->abbreviation ?? '' : '';
}
/**
* Get the translation
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return object|null True on success
* @since 2.0.1
*/
public function get(?string $abbreviation = null): ?object
public function get(): ?object
{
// get from cache if not found
$abbreviation = $abbreviation ?? $this->config->get('translation');
// get selected translation abbreviation
$abbreviation = $this->config->get('translation');
if ($abbreviation === null)
if (empty($abbreviation))
{
return null;
}
@ -155,36 +129,12 @@ final class Translation
if (!isset($this->translations[$abbreviation]))
{
$this->translations[$abbreviation] = $this->load->item(
['abbreviation' => $abbreviation],
['abbreviation' => $abbreviation, 'published' => 1],
'translation'
);
// set to cache for later
if ($this->translations[$abbreviation] !== null)
{
$this->config->set('translation', $abbreviation);
}
}
return $this->translations[$abbreviation];
}
/**
* Check if the language is active
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return bool true if active
* @since 2.0.1
*/
private function active(?string $abbreviation = null): bool
{
if ($this->get($abbreviation))
{
return true;
}
return false;
}
}

View File

@ -39,90 +39,64 @@
/**
* Get the translation name
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return string The translation name
* @since 2.0.1
*/
public function getName(?string $abbreviation = null): string
public function getName(): string
{
if ($this->active($abbreviation))
{
return $this->get($abbreviation)->translation ?? '';
}
return '';
$translation = $this->get();
return $translation ? $translation->translation ?? '' : '';
}
/**
* Get the translation language
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return string The translation language
* @since 2.0.1
*/
public function getLanguage(?string $abbreviation = null): string
public function getLanguage(): string
{
if ($this->active($abbreviation))
{
$lang = trim(preg_replace('/Bible\.?/', '', $this->get($abbreviation)->distribution_lcsh));
return $this->get($abbreviation)->language ?? $lang;
}
return '';
$translation = $this->get();
$lang = trim(preg_replace('/Bible\.?/', '', $this->getLcsh()));
return $translation ? $translation->language ?? $lang : '';
}
/**
* Get the translation distribution lcsh
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return string The translation lcsh
* @since 2.0.1
*/
public function getLcsh(?string $abbreviation = null): string
public function getLcsh(): string
{
if ($this->active($abbreviation))
{
return $this->get($abbreviation)->distribution_lcsh ?? '';
}
return '';
$translation = $this->get();
return $translation ? $translation->distribution_lcsh ?? '' : '';
}
/**
* Get the translation abbreviation
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return string The translation abbreviation
* @since 2.0.1
*/
public function getAbbreviation(?string $abbreviation = null): string
public function getAbbreviation(): string
{
if ($this->active($abbreviation))
{
return $this->get($abbreviation)->abbreviation ?? '';
}
return '';
$translation = $this->get();
return $translation ? $translation->abbreviation ?? '' : '';
}
/**
* Get the translation
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return object|null True on success
* @since 2.0.1
*/
public function get(?string $abbreviation = null): ?object
public function get(): ?object
{
// get from cache if not found
$abbreviation = $abbreviation ?? $this->config->get('translation');
// get selected translation abbreviation
$abbreviation = $this->config->get('translation');
if ($abbreviation === null)
if (empty($abbreviation))
{
return null;
}
@ -130,34 +104,10 @@
if (!isset($this->translations[$abbreviation]))
{
$this->translations[$abbreviation] = $this->load->item(
['abbreviation' => $abbreviation],
['abbreviation' => $abbreviation, 'published' => 1],
'translation'
);
// set to cache for later
if ($this->translations[$abbreviation] !== null)
{
$this->config->set('translation', $abbreviation);
}
}
return $this->translations[$abbreviation];
}
/**
* Check if the language is active
*
* @param string|null $abbreviation The translation abbreviation.
*
* @return bool true if active
* @since 2.0.1
*/
private function active(?string $abbreviation = null): bool
{
if ($this->get($abbreviation))
{
return true;
}
return false;
}

View File

@ -0,0 +1,165 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Verse (Details)
> namespace: **VDM\Joomla\GetBible\Data**
```uml
@startuml
class Verse << (F,LightGreen) >> #Green {
# Chapter $chapter
# Config $config
# Prompt $prompt
# StringHelper $stringHelper
# array $verses
+ __construct(Chapter $chapter, Config $config, ...)
+ getNumber() : string
+ getName() : string
+ getText() : string
+ getVerse() : ?array
+ getValid() : ?array
- get() : ?object
- loadVerseData(string $cacheKey, string $verses) : ?object
- selectedVersesRange(string $verses) : array
- splitAndTrim(string $str) : array
- validateSelectedVersesNumbers(array $verses, array $chapter) : ?string
- getVersesString(array $verses, array $chapter) : ?string
- getVersesArray(array $verses, array $chapter) : ?array
- validVerseNumbers(array $range) : ?array
- generateCacheKey(string $abbreviation, int $book, ...) : string
}
note right of Verse::__construct
Constructor
since: 2.0.1
arguments:
Chapter $chapter
Config $config
Prompt $prompt
StringHelper $stringHelper
end note
note left of Verse::getNumber
Get the verse number/s
since: 2.0.1
return: string
end note
note right of Verse::getName
Get the verse name
since: 2.0.1
return: string
end note
note left of Verse::getText
Get the verse text
since: 2.0.1
return: string
end note
note right of Verse::getVerse
Get the verse array
since: 2.0.1
return: ?array
end note
note left of Verse::getValid
Get the valid verse numbers
since: 2.0.1
return: ?array
end note
note right of Verse::get
Get the verse
since: 2.0.1
return: ?object
end note
note left of Verse::loadVerseData
Loads the verse data
since: 2.0.1
return: ?object
end note
note right of Verse::selectedVersesRange
Get the range of verses selected
since: 2.0.1
return: array
end note
note left of Verse::splitAndTrim
Split string by '-' and trim each element.
since: 2.0.1
return: array
end note
note right of Verse::validateSelectedVersesNumbers
Validate that these verse numbers exist in chapter
since: 2.0.1
return: ?string
end note
note left of Verse::getVersesString
Get the verses selected as text string
since: 2.0.1
return: ?string
end note
note right of Verse::getVersesArray
Get the verses selected as multidimensional array
since: 2.0.1
return: ?array
end note
note left of Verse::validVerseNumbers
Get all valid verse numbers
since: 2.0.1
return: ?array
end note
note right of Verse::generateCacheKey
Generates a cache key based on the abbreviation, book, chapter, and verses
since: 2.0.1
return: string
arguments:
string $abbreviation
int $book
int $chapter
string $verses
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,453 @@
<?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\Data;
use VDM\Joomla\GetBible\Data\Chapter;
use VDM\Joomla\GetBible\Openai\Config;
use VDM\Joomla\GetBible\Data\Prompt;
use VDM\Joomla\GetBible\Utilities\StringHelper;
/**
* The GetBible Verse Data
*
* @since 2.0.1
*/
final class Verse
{
/**
* The Chapter class
*
* @var Chapter
* @since 2.0.1
*/
protected Chapter $chapter;
/**
* The Config class
*
* @var Config
* @since 2.0.1
*/
protected Config $config;
/**
* The Prompt class
*
* @var Prompt
* @since 2.0.1
*/
protected Prompt $prompt;
/**
* The StringHelper class
*
* @var StringHelper
* @since 2.0.1
*/
protected StringHelper $stringHelper;
/**
* The verses
*
* @var array
* @since 2.0.1
*/
protected array $verses = [];
/**
* Constructor
*
* @param Chapter $chapter The chapter object.
* @param Config $config The config object.
* @param Prompt $prompt The prompt object.
* @param StringHelper $stringHelper The string helper object.
*
* @since 2.0.1
*/
public function __construct(Chapter $chapter, Config $config, Prompt $prompt, StringHelper $stringHelper)
{
$this->chapter = $chapter;
$this->config = $config;
$this->prompt = $prompt;
$this->stringHelper = $stringHelper;
}
/**
* Get the verse number/s
*
* @return string The verse number/s
* @since 2.0.1
*/
public function getNumber(): string
{
$verse = $this->get();
return $verse ? $verse->number ?? '' : '';
}
/**
* Get the verse name
*
* @return string The verse name
* @since 2.0.1
*/
public function getName(): string
{
$verse = $this->get();
return $verse ? $verse->name ?? '' : '';
}
/**
* Get the verse text
*
* @return string The verse text
* @since 2.0.1
*/
public function getText(): string
{
$verse = $this->get();
return $verse ? $verse->text ?? '' : '';
}
/**
* Get the verse array
*
* @return array|null The verse array
* @since 2.0.1
*/
public function getVerse(): ?array
{
$verse = $this->get();
return $verse ? $verse->verse ?? null : null;
}
/**
* Get the valid verse numbers
*
* @return array|null The verse number array
* @since 2.0.1
*/
public function getValid(): ?array
{
$verse = $this->get();
return $verse ? $verse->valid ?? null : null;
}
/**
* Get the verse
*
* @return object|null True on success
* @since 2.0.1
*/
private function get(): ?object
{
$abbreviation = $this->config->get('translation');
$book = $this->config->get('book');
$chapter = $this->config->get('chapter');
$verse = $this->config->get('verse');
if (empty($abbreviation) || empty($book) || empty($chapter) || empty($verse))
{
return null;
}
$cacheKey = $this->generateCacheKey($abbreviation, $book, $chapter, $verse);
if (isset($this->verses[$cacheKey]))
{
return $this->verses[$cacheKey];
}
return $this->loadVerseData($cacheKey, $verse);
}
/**
* Loads the verse data
*
* @param string $cacheKey The cache key.
* @param string $verses The selected verses.
*
* @return object|null The loaded verse data, or null if not found or an error occurred.
* @since 2.0.1
*/
private function loadVerseData(string $cacheKey, string $verses): ?object
{
$chapter = $this->chapter->getVerses();
if (empty($chapter))
{
$this->verses[$cacheKey] = null;
return null;
}
$data = new \stdClass();
$data->range = $this->selectedVersesRange($verses);
$data->number = $this->validateSelectedVersesNumbers($data->range, $chapter);
$chapter_name = $this->chapter->getName();
if (empty($data->number) || empty($chapter_name))
{
$this->verses[$cacheKey] = null;
return null;
}
$data->name = $chapter_name . ':' . $data->number;
$data->text = $this->getVersesString($data->range, $chapter);
$data->verse = $this->getVersesArray($data->range, $chapter);
if (empty($data->text) || empty($data->verse))
{
$this->verses[$cacheKey] = null;
return null;
}
$data->valid = $this->validVerseNumbers($data->range);
$this->verses[$cacheKey] = $data;
return $this->verses[$cacheKey];
}
/**
* Get the range of verses selected
*
* @param string $verses The selected verses
*
* @return array The the raw selected verses
* @since 2.0.1
*/
private function selectedVersesRange(string $verses): array
{
$bucket = [];
if (strpos($verses, '-') !== false)
{
$_verses = $this->splitAndTrim($verses);
$min_verse = min($_verses);
$max_verse = max($_verses);
$bucket[] = $min_verse;
if ($min_verse != $max_verse && $this->prompt->getIntegration() == 2)
{
$bucket[] = $max_verse;
}
}
else
{
$bucket[] = trim($verses);
}
return $bucket;
}
/**
* Split string by '-' and trim each element.
*
* @param string $str The string to be split.
*
* @return array The splitted and trimmed array.
* @since 2.0.1
*/
private function splitAndTrim(string $str): array
{
if (strpos($str, '-') !== false)
{
$array = array_map('trim', explode('-', $str));
sort($array);
return $array;
}
return [trim($str)];
}
/**
* Validate that these verse numbers exist in chapter
*
* @param array $verses The selected verse numbers
* @param array $chapter The chapter verses
*
* @return string|null The the valid verse numbers or empty string
* @since 2.0.1
*/
private function validateSelectedVersesNumbers(array &$verses, array $chapter): ?string
{
$valid = [];
foreach ($chapter as $verse)
{
if (isset($verses[0]) && $verse->verse == $verses[0])
{
$valid[0] = $verses[0];
}
elseif (isset($verses[1]) && $verse->verse == $verses[1])
{
$valid[1] = $verses[1];
}
}
if ($valid !== [])
{
// update the verse array to its valid state
$verses = $valid;
return implode('-', $valid);
}
$verses = [];
return null;
}
/**
* Get the verses selected as text string
*
* @param array $verses The valid selected verse numbers
* @param array $chapter The chapter verses
*
* @return string|null The selected verses as a string
* @since 2.0.1
*/
private function getVersesString(array $verses, array $chapter): ?string
{
$text = [];
$add = false;
foreach ($chapter as $verse)
{
if ($verse->verse == $verses[0])
{
$add = true;
}
elseif (!isset($verses[1]))
{
$add = false;
}
if ($add)
{
$text[] = trim($verse->verse) . ' ' . trim($verse->text);
}
if (isset($verses[1]) && $verse->verse == $verses[1])
{
$add = false;
}
}
if (empty($text))
{
return null;
}
return implode(' ', $text);
}
/**
* Get the verses selected as multidimensional array
*
* @param array $verses The valid selected verse numbers
* @param array $chapter The chapter verses
*
* @return array|null The selected verses as an array
* @since 2.0.1
*/
private function getVersesArray(array $verses, array $chapter): ?array
{
$text = [];
$add = false;
foreach ($chapter as $verse)
{
if ($verse->verse == $verses[0])
{
$add = true;
}
elseif (!isset($verses[1]))
{
$add = false;
}
if ($add)
{
$text[$verse->verse] = $this->stringHelper->splitToWords(trim($verse->text), false);
}
if (isset($verses[1]) && $verse->verse == $verses[1])
{
$add = false;
}
}
if (empty($text))
{
return null;
}
return $text;
}
/**
* Get all valid verse numbers
*
* @param array $verses The verse range
*
* @return array|null The the valid verses
* @since 2.0.1
*/
private function validVerseNumbers(array $range): ?array
{
if(count($range) == 1)
{
return $range;
}
elseif(count($range) == 2)
{
// sort the array in ascending order to make sure the range goes from lower to higher
sort($range);
return range($range[0], $range[1]);
}
return null;
}
/**
* Generates a cache key based on the abbreviation, book, chapter, and verses
*
* @param string $abbreviation The translation abbreviation.
* @param int $book The book number.
* @param int $chapter The chapter number.
* @param string $verses The selected verses.
*
* @return string The generated cache key.
* @since 2.0.1
*/
private function generateCacheKey($abbreviation, $book, int $chapter, string $verses): string
{
return $abbreviation . '_' . $book . '_' . $chapter . '_' . $verses;
}
}

View File

@ -0,0 +1,424 @@
/**
* The Chapter class
*
* @var Chapter
* @since 2.0.1
*/
protected Chapter $chapter;
/**
* The Config class
*
* @var Config
* @since 2.0.1
*/
protected Config $config;
/**
* The Prompt class
*
* @var Prompt
* @since 2.0.1
*/
protected Prompt $prompt;
/**
* The StringHelper class
*
* @var StringHelper
* @since 2.0.1
*/
protected StringHelper $stringHelper;
/**
* The verses
*
* @var array
* @since 2.0.1
*/
protected array $verses = [];
/**
* Constructor
*
* @param Chapter $chapter The chapter object.
* @param Config $config The config object.
* @param Prompt $prompt The prompt object.
* @param StringHelper $stringHelper The string helper object.
*
* @since 2.0.1
*/
public function __construct(Chapter $chapter, Config $config, Prompt $prompt, StringHelper $stringHelper)
{
$this->chapter = $chapter;
$this->config = $config;
$this->prompt = $prompt;
$this->stringHelper = $stringHelper;
}
/**
* Get the verse number/s
*
* @return string The verse number/s
* @since 2.0.1
*/
public function getNumber(): string
{
$verse = $this->get();
return $verse ? $verse->number ?? '' : '';
}
/**
* Get the verse name
*
* @return string The verse name
* @since 2.0.1
*/
public function getName(): string
{
$verse = $this->get();
return $verse ? $verse->name ?? '' : '';
}
/**
* Get the verse text
*
* @return string The verse text
* @since 2.0.1
*/
public function getText(): string
{
$verse = $this->get();
return $verse ? $verse->text ?? '' : '';
}
/**
* Get the verse array
*
* @return array|null The verse array
* @since 2.0.1
*/
public function getVerse(): ?array
{
$verse = $this->get();
return $verse ? $verse->verse ?? null : null;
}
/**
* Get the valid verse numbers
*
* @return array|null The verse number array
* @since 2.0.1
*/
public function getValid(): ?array
{
$verse = $this->get();
return $verse ? $verse->valid ?? null : null;
}
/**
* Get the verse
*
* @return object|null True on success
* @since 2.0.1
*/
private function get(): ?object
{
$abbreviation = $this->config->get('translation');
$book = $this->config->get('book');
$chapter = $this->config->get('chapter');
$verse = $this->config->get('verse');
if (empty($abbreviation) || empty($book) || empty($chapter) || empty($verse))
{
return null;
}
$cacheKey = $this->generateCacheKey($abbreviation, $book, $chapter, $verse);
if (isset($this->verses[$cacheKey]))
{
return $this->verses[$cacheKey];
}
return $this->loadVerseData($cacheKey, $verse);
}
/**
* Loads the verse data
*
* @param string $cacheKey The cache key.
* @param string $verses The selected verses.
*
* @return object|null The loaded verse data, or null if not found or an error occurred.
* @since 2.0.1
*/
private function loadVerseData(string $cacheKey, string $verses): ?object
{
$chapter = $this->chapter->getVerses();
if (empty($chapter))
{
$this->verses[$cacheKey] = null;
return null;
}
$data = new \stdClass();
$data->range = $this->selectedVersesRange($verses);
$data->number = $this->validateSelectedVersesNumbers($data->range, $chapter);
$chapter_name = $this->chapter->getName();
if (empty($data->number) || empty($chapter_name))
{
$this->verses[$cacheKey] = null;
return null;
}
$data->name = $chapter_name . ':' . $data->number;
$data->text = $this->getVersesString($data->range, $chapter);
$data->verse = $this->getVersesArray($data->range, $chapter);
if (empty($data->text) || empty($data->verse))
{
$this->verses[$cacheKey] = null;
return null;
}
$data->valid = $this->validVerseNumbers($data->range);
$this->verses[$cacheKey] = $data;
return $this->verses[$cacheKey];
}
/**
* Get the range of verses selected
*
* @param string $verses The selected verses
*
* @return array The the raw selected verses
* @since 2.0.1
*/
private function selectedVersesRange(string $verses): array
{
$bucket = [];
if (strpos($verses, '-') !== false)
{
$_verses = $this->splitAndTrim($verses);
$min_verse = min($_verses);
$max_verse = max($_verses);
$bucket[] = $min_verse;
if ($min_verse != $max_verse && $this->prompt->getIntegration() == 2)
{
$bucket[] = $max_verse;
}
}
else
{
$bucket[] = trim($verses);
}
return $bucket;
}
/**
* Split string by '-' and trim each element.
*
* @param string $str The string to be split.
*
* @return array The splitted and trimmed array.
* @since 2.0.1
*/
private function splitAndTrim(string $str): array
{
if (strpos($str, '-') !== false)
{
$array = array_map('trim', explode('-', $str));
sort($array);
return $array;
}
return [trim($str)];
}
/**
* Validate that these verse numbers exist in chapter
*
* @param array $verses The selected verse numbers
* @param array $chapter The chapter verses
*
* @return string|null The the valid verse numbers or empty string
* @since 2.0.1
*/
private function validateSelectedVersesNumbers(array &$verses, array $chapter): ?string
{
$valid = [];
foreach ($chapter as $verse)
{
if (isset($verses[0]) && $verse->verse == $verses[0])
{
$valid[0] = $verses[0];
}
elseif (isset($verses[1]) && $verse->verse == $verses[1])
{
$valid[1] = $verses[1];
}
}
if ($valid !== [])
{
// update the verse array to its valid state
$verses = $valid;
return implode('-', $valid);
}
$verses = [];
return null;
}
/**
* Get the verses selected as text string
*
* @param array $verses The valid selected verse numbers
* @param array $chapter The chapter verses
*
* @return string|null The selected verses as a string
* @since 2.0.1
*/
private function getVersesString(array $verses, array $chapter): ?string
{
$text = [];
$add = false;
foreach ($chapter as $verse)
{
if ($verse->verse == $verses[0])
{
$add = true;
}
elseif (!isset($verses[1]))
{
$add = false;
}
if ($add)
{
$text[] = trim($verse->verse) . ' ' . trim($verse->text);
}
if (isset($verses[1]) && $verse->verse == $verses[1])
{
$add = false;
}
}
if (empty($text))
{
return null;
}
return implode(' ', $text);
}
/**
* Get the verses selected as multidimensional array
*
* @param array $verses The valid selected verse numbers
* @param array $chapter The chapter verses
*
* @return array|null The selected verses as an array
* @since 2.0.1
*/
private function getVersesArray(array $verses, array $chapter): ?array
{
$text = [];
$add = false;
foreach ($chapter as $verse)
{
if ($verse->verse == $verses[0])
{
$add = true;
}
elseif (!isset($verses[1]))
{
$add = false;
}
if ($add)
{
$text[$verse->verse] = $this->stringHelper->splitToWords(trim($verse->text), false);
}
if (isset($verses[1]) && $verse->verse == $verses[1])
{
$add = false;
}
}
if (empty($text))
{
return null;
}
return $text;
}
/**
* Get all valid verse numbers
*
* @param array $verses The verse range
*
* @return array|null The the valid verses
* @since 2.0.1
*/
private function validVerseNumbers(array $range): ?array
{
if(count($range) == 1)
{
return $range;
}
elseif(count($range) == 2)
{
// sort the array in ascending order to make sure the range goes from lower to higher
sort($range);
return range($range[0], $range[1]);
}
return null;
}
/**
* Generates a cache key based on the abbreviation, book, chapter, and verses
*
* @param string $abbreviation The translation abbreviation.
* @param int $book The book number.
* @param int $chapter The chapter number.
* @param string $verses The selected verses.
*
* @return string The generated cache key.
* @since 2.0.1
*/
private function generateCacheKey($abbreviation, $book, int $chapter, string $verses): string
{
return $abbreviation . '_' . $book . '_' . $chapter . '_' . $verses;
}

View File

@ -0,0 +1,35 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "e3798c7e-aae1-4e38-ba78-6018ce94630b",
"implements": null,
"load_selection": null,
"name": "Verse",
"power_version": "1.0.0",
"system_name": "Joomla.GetBible.Data.Verse",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "4a4c786d-51f4-421a-aa61-262dfd071880",
"as": "default"
},
"use_selection1": {
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
"as": "default"
},
"use_selection2": {
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"as": "default"
},
"use_selection3": {
"use": "a5b32737-207d-4cf6-b8ae-ee815612c3a0",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\GetBible\\Data.Verse",
"description": "The GetBible Verse Data\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": ""
}

View File

@ -6,34 +6,86 @@
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Worker (Details)
# final class Engineer (Details)
> namespace: **VDM\Joomla\GetBible\AI**
```uml
@startuml
class Worker << (F,LightGreen) >> #Green {
class Engineer << (F,LightGreen) >> #Green {
# Scripture $scripture
# Prompt $prompt
# Response $response
+ __construct(Prompt $prompt, Response $response)
# Placeholders $placeholders
# Chat $chat
# Insert $insert
# ?array $messages
# ?object $response
+ __construct(Scripture $scripture, Prompt $prompt, ...)
+ get() : ?array
+ response() : ?array
- saveMessages() : bool
- saveResponse() : bool
- modelResponse() : bool
- modelMessages() : bool
- getResponse() : bool
- getMessages() : ?array
}
note right of Worker::__construct
note right of Engineer::__construct
Constructor
since: 2.0.1
arguments:
Scripture $scripture
Prompt $prompt
Placeholders $placeholders
Chat $chat
Insert $insert
end note
note right of Worker::get
Get the Open AI response
note left of Engineer::get
Return the current data state
since: 2.0.1
return: ?array
end note
note right of Worker::response
note right of Engineer::saveMessages
Save the messages
since: 2.0.1
return: bool
end note
note left of Engineer::saveResponse
Save the response
since: 2.0.1
return: bool
end note
note right of Engineer::modelResponse
Prep the response data
since: 2.0.1
return: bool
end note
note left of Engineer::modelMessages
Prep the messages
since: 2.0.1
return: bool
end note
note right of Engineer::getResponse
Get the Open AI response
since: 2.0.1
return: bool
end note
note left of Engineer::getMessages
Get the ready to use prompt messages
since: 2.0.1
return: ?array
end note

View File

@ -12,17 +12,28 @@
namespace VDM\Joomla\GetBible\AI;
use VDM\Joomla\GetBible\Data\Scripture;
use VDM\Joomla\GetBible\Data\Prompt;
use VDM\Joomla\GetBible\Data\Response;
use VDM\Joomla\GetBible\Data\Placeholders;
use VDM\Joomla\Openai\Chat;
use VDM\Joomla\GetBible\Database\Insert;
/**
* The GetBible AI Worker
* The GetBible AI Engineer
*
* @since 2.0.1
*/
final class Worker
final class Engineer
{
/**
* The Scripture class
*
* @var Scripture
* @since 2.0.1
*/
protected Scripture $scripture;
/**
* The Prompt class
*
@ -32,47 +43,266 @@ final class Worker
protected Prompt $prompt;
/**
* The Response class
* The Placeholders class
*
* @var Response
* @var Placeholders
* @since 2.0.1
*/
protected Response $response;
protected Placeholders $placeholders;
/**
* The Chat class
*
* @var Chat
* @since 2.0.1
*/
protected Chat $chat;
/**
* The Insert class
*
* @var Insert
* @since 2.0.1
*/
protected Insert $insert;
/**
* The request messages
*
* @var array|null
* @since 2.0.1
*/
protected ?array $messages = null;
/**
* The response object
*
* @var object|null
* @since 2.0.1
*/
protected ?object $response = null;
/**
* Constructor
*
* @param Prompt $prompt The prompt object.
* @param Response $response The response object.
* @param Scripture $scripture The scripture object.
* @param Prompt $prompt The prompt object.
* @param Placeholders $placeholders The placeholders object.
* @param Chat $chat The chat object.
* @param Insert $insert The insert object.
*
* @since 2.0.1
*/
public function __construct(Prompt $prompt, Response $response)
public function __construct(
Scripture $scripture,
Prompt $prompt,
Placeholders $placeholders,
Chat $chat,
Insert $insert)
{
$this->scripture = $scripture;
$this->prompt = $prompt;
$this->response = $response;
$this->placeholders = $placeholders;
$this->chat = $chat;
$this->insert = $insert;
}
/**
* Get the Open AI response
* Return the current data state
*
* @return array|null Array of response messages
* @return array|null True on success
* @since 2.0.1
*/
public function get(): ?array
{
return ['worker:get'];
if ($this->getResponse() && $this->modelMessages() && $this->modelResponse()
&& $this->saveResponse() && $this->saveMessages())
{
// add this response's messages
$this->response->messages = $this->messages ?? '';
return [
$this->response
];
}
return null;
}
/**
* Save the messages
*
* @return bool True on success
* @since 2.0.1
*/
private function saveMessages(): bool
{
return $this->insert->items($this->messages, 'open_ai_message');
}
/**
* Save the response
*
* @return bool True on success
* @since 2.0.1
*/
private function saveResponse(): bool
{
return $this->insert->item($this->response, 'open_ai_response');
}
/**
* Prep the response data
*
* @return bool True on success
* @since 2.0.1
*/
private function modelResponse(): bool
{
if ($this->response)
{
$data = new \stdClass();
// Bible link
$data->abbreviation = $this->scripture->get('translation_abbreviation', '');
$data->language = $this->scripture->get('translation_language', '');
$data->lcsh = $this->scripture->get('translation_lcsh', '');
$data->book = $this->scripture->get('book_number', '');
$data->chapter = $this->scripture->get('chapter_number', '');
$data->verse = $this->scripture->get('verse_number', '');
$data->word = $this->scripture->get('selected_word_number', '');
$data->selected_word = $this->scripture->get('selected_word_text', '');
// Prompt data
$data->prompt = $this->prompt->getGuid();
$data->model = $this->prompt->getModel();
$data->max_tokens = $this->prompt->getMaxTokens();
$data->temperature = $this->prompt->getTemperature();
$data->top_p = $this->prompt->getTopP();
$data->presence_penalty = $this->prompt->getPresencePenalty();
$data->frequency_penalty = $this->prompt->getFrequencyPenalty();
$data->n = '';
// Response data
$data->response_id = $this->response->id ?? '';
$data->response_object = $this->response->object ?? '';
$data->response_model = $this->response->model ?? '';
$data->response_created = $this->response->created ?? '';
$data->prompt_tokens = $this->response->usage->prompt_tokens ?? '';
$data->completion_tokens = $this->response->usage->completion_tokens ?? '';
$data->total_tokens = $this->response->usage->total_tokens ?? '';
$this->response = $data;
return true;
}
return false;
}
/**
* Prep the messages
*
* @return bool True on success
* @since 2.0.1
*/
private function modelMessages(): bool
{
if (isset($this->response->choices) &&
is_array($this->response->choices) &&
$this->response->choices !== [])
{
// set some global keys
$open_ai_response = $this->response->id ?? '';
$prompt = $this->prompt->getGuid();
// if Persistently we archive this response
$cache_type = $this->prompt->getCacheBehaviour();
$state = ($cache_type == 0) ? 2 : 1;
// update the system messages
$index = (int) 0 - count($this->messages);
foreach ($this->messages as $n => &$message)
{
$message->prompt = $prompt;
$message->open_ai_response = $open_ai_response;
$message->source = 1; // prompt as source
$message->index = $index;
$message->published = $state;
$index++;
}
// now add the response messages
foreach ($this->response->choices as $choice)
{
$choice->message->prompt = $prompt;
$choice->message->open_ai_response = $open_ai_response;
$choice->message->source = 2; // open AI as source
$choice->message->index = $choice->index;
$choice->message->name = 'getBible-Open-AI';
$choice->message->published = $state;
$this->messages[] = $choice->message;
}
// we remove it from the response object
unset($this->response->choices);
return true;
}
return false;
}
/**
* Get the Open AI response
*
* @return array|null Array of response messages
* @return bool True on success
* @since 2.0.1
*/
public function response(): ?array
private function getResponse(): bool
{
return ['worker:response'];
if (($this->messages = $this->getMessages()) !== null)
{
$this->response = $this->chat->create(
$this->prompt->getModel(),
$this->messages,
$this->prompt->getMaxTokens(),
$this->prompt->getTemperature(),
$this->prompt->getTopP(),
$this->prompt->getN(),
null,
null,
$this->prompt->getPresencePenalty(),
$this->prompt->getFrequencyPenalty(),
null
);
return true;
}
return false;
}
/**
* Get the ready to use prompt messages
*
* @return array|null Array of prompt messages
* @since 2.0.1
*/
private function getMessages(): ?array
{
if (($placeholders = $this->placeholders->get()) !== null &&
($messages = $this->prompt->getMessages()) !== null)
{
return array_map(function ($message) use($placeholders) {
$message->content = str_replace(
array_keys($placeholders),
array_values($placeholders),
$message->content
);
return $message;
}, $messages);
}
return null;
}
}

View File

@ -1,3 +1,11 @@
/**
* The Scripture class
*
* @var Scripture
* @since 2.0.1
*/
protected Scripture $scripture;
/**
* The Prompt class
*
@ -7,45 +15,264 @@
protected Prompt $prompt;
/**
* The Response class
* The Placeholders class
*
* @var Response
* @var Placeholders
* @since 2.0.1
*/
protected Response $response;
protected Placeholders $placeholders;
/**
* The Chat class
*
* @var Chat
* @since 2.0.1
*/
protected Chat $chat;
/**
* The Insert class
*
* @var Insert
* @since 2.0.1
*/
protected Insert $insert;
/**
* The request messages
*
* @var array|null
* @since 2.0.1
*/
protected ?array $messages = null;
/**
* The response object
*
* @var object|null
* @since 2.0.1
*/
protected ?object $response = null;
/**
* Constructor
*
* @param Prompt $prompt The prompt object.
* @param Response $response The response object.
* @param Scripture $scripture The scripture object.
* @param Prompt $prompt The prompt object.
* @param Placeholders $placeholders The placeholders object.
* @param Chat $chat The chat object.
* @param Insert $insert The insert object.
*
* @since 2.0.1
*/
public function __construct(Prompt $prompt, Response $response)
public function __construct(
Scripture $scripture,
Prompt $prompt,
Placeholders $placeholders,
Chat $chat,
Insert $insert)
{
$this->scripture = $scripture;
$this->prompt = $prompt;
$this->response = $response;
$this->placeholders = $placeholders;
$this->chat = $chat;
$this->insert = $insert;
}
/**
* Get the Open AI response
* Return the current data state
*
* @return array|null Array of response messages
* @return array|null True on success
* @since 2.0.1
*/
public function get(): ?array
{
return ['worker:get'];
if ($this->getResponse() && $this->modelMessages() && $this->modelResponse()
&& $this->saveResponse() && $this->saveMessages())
{
// add this response's messages
$this->response->messages = $this->messages ?? '';
return [
$this->response
];
}
return null;
}
/**
* Save the messages
*
* @return bool True on success
* @since 2.0.1
*/
private function saveMessages(): bool
{
return $this->insert->items($this->messages, 'open_ai_message');
}
/**
* Save the response
*
* @return bool True on success
* @since 2.0.1
*/
private function saveResponse(): bool
{
return $this->insert->item($this->response, 'open_ai_response');
}
/**
* Prep the response data
*
* @return bool True on success
* @since 2.0.1
*/
private function modelResponse(): bool
{
if ($this->response)
{
$data = new \stdClass();
// Bible link
$data->abbreviation = $this->scripture->get('translation_abbreviation', '');
$data->language = $this->scripture->get('translation_language', '');
$data->lcsh = $this->scripture->get('translation_lcsh', '');
$data->book = $this->scripture->get('book_number', '');
$data->chapter = $this->scripture->get('chapter_number', '');
$data->verse = $this->scripture->get('verse_number', '');
$data->word = $this->scripture->get('selected_word_number', '');
$data->selected_word = $this->scripture->get('selected_word_text', '');
// Prompt data
$data->prompt = $this->prompt->getGuid();
$data->model = $this->prompt->getModel();
$data->max_tokens = $this->prompt->getMaxTokens();
$data->temperature = $this->prompt->getTemperature();
$data->top_p = $this->prompt->getTopP();
$data->presence_penalty = $this->prompt->getPresencePenalty();
$data->frequency_penalty = $this->prompt->getFrequencyPenalty();
$data->n = '';
// Response data
$data->response_id = $this->response->id ?? '';
$data->response_object = $this->response->object ?? '';
$data->response_model = $this->response->model ?? '';
$data->response_created = $this->response->created ?? '';
$data->prompt_tokens = $this->response->usage->prompt_tokens ?? '';
$data->completion_tokens = $this->response->usage->completion_tokens ?? '';
$data->total_tokens = $this->response->usage->total_tokens ?? '';
$this->response = $data;
return true;
}
return false;
}
/**
* Prep the messages
*
* @return bool True on success
* @since 2.0.1
*/
private function modelMessages(): bool
{
if (isset($this->response->choices) &&
is_array($this->response->choices) &&
$this->response->choices !== [])
{
// set some global keys
$open_ai_response = $this->response->id ?? '';
$prompt = $this->prompt->getGuid();
// if Persistently we archive this response
$cache_type = $this->prompt->getCacheBehaviour();
$state = ($cache_type == 0) ? 2 : 1;
// update the system messages
$index = (int) 0 - count($this->messages);
foreach ($this->messages as $n => &$message)
{
$message->prompt = $prompt;
$message->open_ai_response = $open_ai_response;
$message->source = 1; // prompt as source
$message->index = $index;
$message->published = $state;
$index++;
}
// now add the response messages
foreach ($this->response->choices as $choice)
{
$choice->message->prompt = $prompt;
$choice->message->open_ai_response = $open_ai_response;
$choice->message->source = 2; // open AI as source
$choice->message->index = $choice->index;
$choice->message->name = 'getBible-Open-AI';
$choice->message->published = $state;
$this->messages[] = $choice->message;
}
// we remove it from the response object
unset($this->response->choices);
return true;
}
return false;
}
/**
* Get the Open AI response
*
* @return array|null Array of response messages
* @return bool True on success
* @since 2.0.1
*/
public function response(): ?array
private function getResponse(): bool
{
return ['worker:response'];
if (($this->messages = $this->getMessages()) !== null)
{
$this->response = $this->chat->create(
$this->prompt->getModel(),
$this->messages,
$this->prompt->getMaxTokens(),
$this->prompt->getTemperature(),
$this->prompt->getTopP(),
$this->prompt->getN(),
null,
null,
$this->prompt->getPresencePenalty(),
$this->prompt->getFrequencyPenalty(),
null
);
return true;
}
return false;
}
/**
* Get the ready to use prompt messages
*
* @return array|null Array of prompt messages
* @since 2.0.1
*/
private function getMessages(): ?array
{
if (($placeholders = $this->placeholders->get()) !== null &&
($messages = $this->prompt->getMessages()) !== null)
{
return array_map(function ($message) use($placeholders) {
$message->content = str_replace(
array_keys($placeholders),
array_values($placeholders),
$message->content
);
return $message;
}, $messages);
}
return null;
}

View File

@ -5,22 +5,34 @@
"guid": "ed16a9c4-e026-4d16-be60-81892ce7c6a9",
"implements": null,
"load_selection": null,
"name": "Worker",
"name": "Engineer",
"power_version": "1.0.0",
"system_name": "Joomla.GetBible.AI.Worker",
"system_name": "Joomla.GetBible.AI.Engineer",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"use": "17d87374-2953-4d6c-9fdd-4220d6ad1564",
"as": "default"
},
"use_selection1": {
"use": "44c15b17-e096-47c0-8769-42ea9b692cb2",
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"as": "default"
},
"use_selection2": {
"use": "ba2151c0-8ffa-4a07-ba6e-93f135a3e9d5",
"as": "default"
},
"use_selection3": {
"use": "c54c92da-2dd7-4136-81c9-1785f2fa0af5",
"as": "default"
},
"use_selection4": {
"use": "a07d90f6-6ff2-40a1-99c1-0f2cf33c9adf",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\GetBible\\AI.Worker",
"description": "The GetBible AI Worker\r\n\r\n@since 2.0.1",
"namespace": "VDM\\Joomla\\GetBible\\AI.Engineer",
"description": "The GetBible AI Engineer\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": ""

View File

@ -11,10 +11,10 @@
```uml
@startuml
class AI << (F,LightGreen) >> #Green {
# Prompt $prompt
# Config $config
# Response $response
# Worker $worker
+ __construct(Prompt $prompt, Response $response, ...)
# Engineer $engineer
+ __construct(Config $config, Response $response, ...)
+ get() : ?array
}
@ -24,9 +24,9 @@ note right of AI::__construct
since: 2.0.1
arguments:
Prompt $prompt
Config $config
Response $response
Worker $worker
Engineer $engineer
end note
note right of AI::get

View File

@ -12,9 +12,9 @@
namespace VDM\Joomla\GetBible;
use VDM\Joomla\GetBible\Data\Prompt;
use VDM\Joomla\GetBible\Openai\Config;
use VDM\Joomla\GetBible\Data\Response;
use VDM\Joomla\GetBible\AI\Worker;
use VDM\Joomla\GetBible\AI\Engineer;
/**
@ -25,12 +25,12 @@ use VDM\Joomla\GetBible\AI\Worker;
final class AI
{
/**
* The Prompt class
* The Config class
*
* @var Prompt
* @var Config
* @since 2.0.1
*/
protected Prompt $prompt;
protected Config $config;
/**
* The Response class
@ -41,27 +41,27 @@ final class AI
protected Response $response;
/**
* The Worker class
* The Engineer class
*
* @var Worker
* @var Engineer
* @since 2.0.1
*/
protected Worker $worker;
protected Engineer $engineer;
/**
* Constructor
*
* @param Prompt $prompt The prompt object.
* @param Response $response The response object.
* @param Worker $Worker The worker object.
* @param Config $config The response object.
* @param Response $response The response object.
* @param Engineer $engineer The engineer object.
*
* @since 2.0.1
*/
public function __construct(Prompt $prompt, Response $response, Worker $worker)
public function __construct(Config $config, Response $response, Engineer $engineer)
{
$this->prompt = $prompt;
$this->config = $config;
$this->response = $response;
$this->worker = $worker;
$this->engineer = $engineer;
}
/**
@ -72,20 +72,33 @@ final class AI
*/
public function get(): ?array
{
if ($this->response->enough())
// If Open AI isn't enabled in the config, we return null right away.
if (!$this->config->get('enable_open_ai'))
{
return $this->response->get();
return null;
}
// no cache
elseif (empty($this->prompt->getCacheBehaviour()))
// If we have enough responses already, return them.
$response = $this->response->get();
if ($this->response->isEnough())
{
return $this->worker->get();
return $response;
}
// we will use cache
else
// If there is no existing response and engineer has any response, return it.
if (empty($response))
{
return $this->worker->response();
return $this->engineer->get();
}
// If there are existing responses, we append the first response from the engineer (if any).
$_response = $this->engineer->get();
if (!empty($_response))
{
$response[] = $_response[0];
}
return $response;
}
}

View File

@ -1,10 +1,10 @@
/**
* The Prompt class
* The Config class
*
* @var Prompt
* @var Config
* @since 2.0.1
*/
protected Prompt $prompt;
protected Config $config;
/**
* The Response class
@ -15,27 +15,27 @@
protected Response $response;
/**
* The Worker class
* The Engineer class
*
* @var Worker
* @var Engineer
* @since 2.0.1
*/
protected Worker $worker;
protected Engineer $engineer;
/**
* Constructor
*
* @param Prompt $prompt The prompt object.
* @param Response $response The response object.
* @param Worker $Worker The worker object.
* @param Config $config The response object.
* @param Response $response The response object.
* @param Engineer $engineer The engineer object.
*
* @since 2.0.1
*/
public function __construct(Prompt $prompt, Response $response, Worker $worker)
public function __construct(Config $config, Response $response, Engineer $engineer)
{
$this->prompt = $prompt;
$this->config = $config;
$this->response = $response;
$this->worker = $worker;
$this->engineer = $engineer;
}
/**
@ -46,18 +46,31 @@
*/
public function get(): ?array
{
if ($this->response->enough())
// If Open AI isn't enabled in the config, we return null right away.
if (!$this->config->get('enable_open_ai'))
{
return $this->response->get();
return null;
}
// no cache
elseif (empty($this->prompt->getCacheBehaviour()))
// If we have enough responses already, return them.
$response = $this->response->get();
if ($this->response->isEnough())
{
return $this->worker->get();
return $response;
}
// we will use cache
else
// If there is no existing response and engineer has any response, return it.
if (empty($response))
{
return $this->worker->response();
return $this->engineer->get();
}
// If there are existing responses, we append the first response from the engineer (if any).
$_response = $this->engineer->get();
if (!empty($_response))
{
$response[] = $_response[0];
}
return $response;
}

View File

@ -11,7 +11,7 @@
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "3f785d63-a592-463d-9f5f-b2b5a8edd561",
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
"as": "default"
},
"use_selection1": {

View File

@ -0,0 +1,79 @@
```
██████╗ ██████╗ ██╗ ██╗███████╗██████╗
██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗
██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝
██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗
██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║
╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝
```
# final class Book (Details)
> namespace: **VDM\Joomla\GetBible\Data**
```uml
@startuml
class Book << (F,LightGreen) >> #Green {
# Load $load
# Config $config
# array $books
+ __construct(Load $load, Config $config)
+ getNumber() : string
+ getName() : string
- get() : ?object
- loadBookData(string $abbreviation, int $book) : ?object
- generateCacheKey(string $abbreviation, int $book) : string
}
note right of Book::__construct
Constructor
since: 2.0.1
end note
note right of Book::getNumber
Get the book number
since: 2.0.1
return: string
end note
note right of Book::getName
Get the book name
since: 2.0.1
return: string
end note
note right of Book::get
Get the book
since: 2.0.1
return: ?object
end note
note right of Book::loadBookData
Loads the book data from the database and updates the cache
since: 2.0.1
return: ?object
end note
note right of Book::generateCacheKey
Generates a cache key based on the abbreviation, and book
since: 2.0.1
return: string
end note
@enduml
```
---
```
██╗ ██████╗██████╗
██║██╔════╝██╔══██╗
██║██║ ██████╔╝
██ ██║██║ ██╔══██╗
╚█████╔╝╚██████╗██████╔╝
╚════╝ ╚═════╝╚═════╝
```
> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)

View File

@ -0,0 +1,156 @@
<?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\Data;
use VDM\Joomla\GetBible\Database\Load;
use VDM\Joomla\GetBible\Openai\Config;
/**
* The GetBible Book Data
*
* @since 2.0.1
*/
final class Book
{
/**
* The Load class
*
* @var Load
* @since 2.0.1
*/
protected Load $load;
/**
* The Config class
*
* @var Config
* @since 2.0.1
*/
protected Config $config;
/**
* The books
*
* @var array
* @since 2.0.1
*/
protected array $books = [];
/**
* Constructor
*
* @param Load $load The load object.
* @param Config $config The config object.
*
* @since 2.0.1
*/
public function __construct(Load $load, Config $config)
{
$this->load = $load;
$this->config = $config;
}
/**
* Get the book number
*
* @return string The book number
* @since 2.0.1
*/
public function getNumber(): string
{
$book = $this->get();
return $book ? $book->nr ?? '' : '';
}
/**
* Get the book name
*
* @return string The book name
* @since 2.0.1
*/
public function getName(): string
{
$book = $this->get();
return $book ? $book->name ?? '' : '';
}
/**
* Get the book
*
* @return object|null True on success
* @since 2.0.1
*/
private function get(): ?object
{
$abbreviation = $this->config->get('translation');
$book = $this->config->get('book');
if (empty($abbreviation) || empty($book))
{
return null;
}
$cacheKey = $this->generateCacheKey($abbreviation, $book);
if (isset($this->books[$cacheKey]))
{
return $this->books[$cacheKey];
}
return $this->loadBookData($abbreviation, $book);
}
/**
* Loads the book data from the database and updates the cache
*
* @param string $abbreviation The translation abbreviation.
* @param int $book The book number.
*
* @return object|null The loaded book data, or null if not found or an error occurred.
* @since 2.0.1
*/
private function loadBookData(string $abbreviation, int $book): ?object
{
$data = $this->load->item(
['abbreviation' => $abbreviation, 'nr' => $book],
'book'
);
if (!is_object($data))
{
return null;
}
$cacheKey = $this->generateCacheKey($abbreviation, $book);
$this->books[$cacheKey] = $data;
return $this->books[$cacheKey];
}
/**
* Generates a cache key based on the abbreviation, and book
*
* @param string $abbreviation The translation abbreviation.
* @param int $book The book number.
*
* @return string The generated cache key.
* @since 2.0.1
*/
private function generateCacheKey(string $abbreviation, int $book): string
{
return $abbreviation . $book;
}
}

View File

@ -0,0 +1,129 @@
/**
* The Load class
*
* @var Load
* @since 2.0.1
*/
protected Load $load;
/**
* The Config class
*
* @var Config
* @since 2.0.1
*/
protected Config $config;
/**
* The books
*
* @var array
* @since 2.0.1
*/
protected array $books = [];
/**
* Constructor
*
* @param Load $load The load object.
* @param Config $config The config object.
*
* @since 2.0.1
*/
public function __construct(Load $load, Config $config)
{
$this->load = $load;
$this->config = $config;
}
/**
* Get the book number
*
* @return string The book number
* @since 2.0.1
*/
public function getNumber(): string
{
$book = $this->get();
return $book ? $book->nr ?? '' : '';
}
/**
* Get the book name
*
* @return string The book name
* @since 2.0.1
*/
public function getName(): string
{
$book = $this->get();
return $book ? $book->name ?? '' : '';
}
/**
* Get the book
*
* @return object|null True on success
* @since 2.0.1
*/
private function get(): ?object
{
$abbreviation = $this->config->get('translation');
$book = $this->config->get('book');
if (empty($abbreviation) || empty($book))
{
return null;
}
$cacheKey = $this->generateCacheKey($abbreviation, $book);
if (isset($this->books[$cacheKey]))
{
return $this->books[$cacheKey];
}
return $this->loadBookData($abbreviation, $book);
}
/**
* Loads the book data from the database and updates the cache
*
* @param string $abbreviation The translation abbreviation.
* @param int $book The book number.
*
* @return object|null The loaded book data, or null if not found or an error occurred.
* @since 2.0.1
*/
private function loadBookData(string $abbreviation, int $book): ?object
{
$data = $this->load->item(
['abbreviation' => $abbreviation, 'nr' => $book],
'book'
);
if (!is_object($data))
{
return null;
}
$cacheKey = $this->generateCacheKey($abbreviation, $book);
$this->books[$cacheKey] = $data;
return $this->books[$cacheKey];
}
/**
* Generates a cache key based on the abbreviation, and book
*
* @param string $abbreviation The translation abbreviation.
* @param int $book The book number.
*
* @return string The generated cache key.
* @since 2.0.1
*/
private function generateCacheKey(string $abbreviation, int $book): string
{
return $abbreviation . $book;
}

View File

@ -0,0 +1,27 @@
{
"add_head": "0",
"add_licensing_template": "2",
"extends": "0",
"guid": "fa776320-65f8-4198-a517-58cd94b3b7b7",
"implements": null,
"load_selection": null,
"name": "Book",
"power_version": "1.0.0",
"system_name": "Joomla.GetBible.Data.Book",
"type": "final class",
"use_selection": {
"use_selection0": {
"use": "c03b9c61-17d3-4774-a335-783903719f83",
"as": "default"
},
"use_selection1": {
"use": "3af7864b-f1f3-491e-b16f-0504f890086d",
"as": "default"
}
},
"namespace": "VDM\\Joomla\\GetBible\\Data.Book",
"description": "The GetBible Book Data\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": ""
}

View File

@ -489,9 +489,9 @@ class Table extends BaseTable implements Tableinterface
'store' => NULL,
'tab_name' => 'Prompt',
],
'words' => [
'name' => 'words',
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_WORDS_LABEL',
'word' => [
'name' => 'word',
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_WORD_LABEL',
'type' => 'text',
'title' => false,
'list' => 'open_ai_responses',
@ -606,9 +606,9 @@ class Table extends BaseTable implements Tableinterface
'store' => NULL,
'tab_name' => 'Prompt',
],
'selected_words' => [
'name' => 'selected_words',
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_SELECTED_WORDS_LABEL',
'selected_word' => [
'name' => 'selected_word',
'label' => 'COM_GETBIBLE_OPEN_AI_RESPONSE_SELECTED_WORD_LABEL',
'type' => 'text',
'title' => false,
'list' => 'open_ai_responses',
@ -671,6 +671,15 @@ class Table extends BaseTable implements Tableinterface
'store' => NULL,
'tab_name' => 'Message',
],
'name' => [
'name' => 'name',
'label' => 'COM_GETBIBLE_OPEN_AI_MESSAGE_NAME_LABEL',
'type' => 'text',
'title' => false,
'list' => 'open_ai_messages',
'store' => NULL,
'tab_name' => 'Message',
],
'index' => [
'name' => 'index',
'label' => 'COM_GETBIBLE_OPEN_AI_MESSAGE_INDEX_LABEL',

View File

@ -21,6 +21,17 @@
"spk": "Super__11892cfa_374e_4e3f_b0bc_531871c822d9__Power",
"guid": "11892cfa-374e-4e3f-b0bc-531871c822d9"
},
"17d87374-2953-4d6c-9fdd-4220d6ad1564": {
"name": "Scripture",
"type": "final class",
"namespace": "VDM\\Joomla\\GetBible\\Data",
"code": "src\/17d87374-2953-4d6c-9fdd-4220d6ad1564\/code.php",
"power": "src\/17d87374-2953-4d6c-9fdd-4220d6ad1564\/code.power",
"settings": "src\/17d87374-2953-4d6c-9fdd-4220d6ad1564\/settings.json",
"path": "src\/17d87374-2953-4d6c-9fdd-4220d6ad1564",
"spk": "Super__17d87374_2953_4d6c_9fdd_4220d6ad1564__Power",
"guid": "17d87374-2953-4d6c-9fdd-4220d6ad1564"
},
"3439e63b-d8f1-42ce-a765-60d56b1fbe21": {
"name": "Data",
"type": "class",
@ -142,6 +153,17 @@
"spk": "Super__8336e3c4_f11b_41bc_a2b1_976f99442a84__Power",
"guid": "8336e3c4-f11b-41bc-a2b1-976f99442a84"
},
"899551ac-943e-4f81-becd-7e15c41f1081": {
"name": "Word",
"type": "final class",
"namespace": "VDM\\Joomla\\GetBible\\Data",
"code": "src\/899551ac-943e-4f81-becd-7e15c41f1081\/code.php",
"power": "src\/899551ac-943e-4f81-becd-7e15c41f1081\/code.power",
"settings": "src\/899551ac-943e-4f81-becd-7e15c41f1081\/settings.json",
"path": "src\/899551ac-943e-4f81-becd-7e15c41f1081",
"spk": "Super__899551ac_943e_4f81_becd_7e15c41f1081__Power",
"guid": "899551ac-943e-4f81-becd-7e15c41f1081"
},
"90f2ee7a-c041-4316-ad54-af4f97fa3003": {
"name": "DailyScripture",
"type": "final class",
@ -340,8 +362,19 @@
"spk": "Super__d7a5f0c6_de60_4d31_b3e4_5d668a8f7d2e__Power",
"guid": "d7a5f0c6-de60-4d31-b3e4-5d668a8f7d2e"
},
"e3798c7e-aae1-4e38-ba78-6018ce94630b": {
"name": "Verse",
"type": "final class",
"namespace": "VDM\\Joomla\\GetBible\\Data",
"code": "src\/e3798c7e-aae1-4e38-ba78-6018ce94630b\/code.php",
"power": "src\/e3798c7e-aae1-4e38-ba78-6018ce94630b\/code.power",
"settings": "src\/e3798c7e-aae1-4e38-ba78-6018ce94630b\/settings.json",
"path": "src\/e3798c7e-aae1-4e38-ba78-6018ce94630b",
"spk": "Super__e3798c7e_aae1_4e38_ba78_6018ce94630b__Power",
"guid": "e3798c7e-aae1-4e38-ba78-6018ce94630b"
},
"ed16a9c4-e026-4d16-be60-81892ce7c6a9": {
"name": "Worker",
"name": "Engineer",
"type": "final class",
"namespace": "VDM\\Joomla\\GetBible\\AI",
"code": "src\/ed16a9c4-e026-4d16-be60-81892ce7c6a9\/code.php",
@ -384,6 +417,17 @@
"spk": "Super__f815fb33_f721_48a5_a84e_53f1986e8881__Power",
"guid": "f815fb33-f721-48a5-a84e-53f1986e8881"
},
"fa776320-65f8-4198-a517-58cd94b3b7b7": {
"name": "Book",
"type": "final class",
"namespace": "VDM\\Joomla\\GetBible\\Data",
"code": "src\/fa776320-65f8-4198-a517-58cd94b3b7b7\/code.php",
"power": "src\/fa776320-65f8-4198-a517-58cd94b3b7b7\/code.power",
"settings": "src\/fa776320-65f8-4198-a517-58cd94b3b7b7\/settings.json",
"path": "src\/fa776320-65f8-4198-a517-58cd94b3b7b7",
"spk": "Super__fa776320_65f8_4198_a517_58cd94b3b7b7__Power",
"guid": "fa776320-65f8-4198-a517-58cd94b3b7b7"
},
"fc9ab6f0-c31b-4077-bb1c-2dcddd36f6bb": {
"name": "Uri",
"type": "final class",