From 2244f466d415c06c0829f933607c2c042459a72e Mon Sep 17 00:00:00 2001 From: aB0t Date: Tue, 4 Jul 2023 08:26:05 +0200 Subject: [PATCH] update 2023-07-04 08:26:01 --- README.md | 67 +++++++- .../README.md | 62 +++++++- .../code.php | 82 +++++++++- .../code.power | 62 +++++++- .../settings.json | 39 ++++- .../README.md | 38 ++++- .../code.php | 34 +++- .../code.power | 19 ++- .../settings.json | 19 ++- .../README.md | 75 ++++++++- .../code.php | 105 ++++++++++++- .../code.power | 90 ++++++++++- .../settings.json | 19 ++- .../README.md | 39 ++++- .../code.php | 50 +++++- .../code.power | 35 ++++- .../settings.json | 19 ++- .../README.md | 37 ++++- .../code.php | 53 ++++++- .../code.power | 37 ++++- .../settings.json | 20 ++- .../README.md | 45 +++++- .../code.php | 57 ++++++- .../code.power | 40 ++++- .../settings.json | 32 +++- .../README.md | 57 ++++++- .../code.php | 148 +++++++++++++++++- .../code.power | 133 +++++++++++++++- .../settings.json | 19 ++- .../README.md | 67 +++++++- .../code.php | 130 ++++++++++++++- .../code.power | 113 ++++++++++++- .../settings.json | 28 +++- .../README.md | 63 +++++++- .../code.php | 132 +++++++++++++++- .../code.power | 117 +++++++++++++- .../settings.json | 19 ++- super-powers.json | 102 +++++++++++- 38 files changed, 2265 insertions(+), 38 deletions(-) diff --git a/README.md b/README.md index 433b69e..96ca0fc 100644 --- a/README.md +++ b/README.md @@ -1 +1,66 @@ -###POWERREADME### \ No newline at end of file +``` +███████╗██╗ ██╗██████╗ ███████╗██████╗ +██╔════╝██║ ██║██╔══██╗██╔════╝██╔══██╗ +███████╗██║ ██║██████╔╝█████╗ ██████╔╝ +╚════██║██║ ██║██╔═══╝ ██╔══╝ ██╔══██╗ +███████║╚██████╔╝██║ ███████╗██║ ██║ +╚══════╝ ╚═════╝ ╚═╝ ╚══════╝╚═╝ ╚═╝ +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ ███████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗██╔════╝ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝███████╗ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗╚════██║ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║███████║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝╚══════╝ +``` + +### What is JCB Super Powers? +The Joomla Component Builder (JCB) Super Power features are designed to enhance JCB's functionality and streamline the development process. These Super Powers enable developers to efficiently manage and share their custom powers across multiple JCB instances through repositories hosted on [https://git.vdm.dev/[username]/[repository-name]](https://git.vdm.dev). JCB Super Powers are managed using a combination of layers, events, tasks, methods, switches, and algorithms, which work together to provide powerful customization and extensibility options. More details on JCB Super Powers can be found in the [Super Powers Documentation](https://git.vdm.dev/joomla/super-powers/wiki). + +In summary, JCB Super Powers offer a flexible and efficient way to manage and share functionalities between JCB instances. By utilizing a sophisticated system of layers, events, tasks, methods, switches, and algorithms, developers can seamlessly integrate JCB core powers and their custom powers. For more information on how to work with JCB Super Powers, refer to the [Super Powers User Guide](https://git.vdm.dev/joomla/super-powers/wiki). + +### What can I find here? +This repository contains an index (see below) of all the approved powers within the JCB GUI. During the compilation of a component, these powers are automatically added to the repository, ensuring a well-organized and accessible collection of functionalities. + +# Index of powers + +- **Namespace**: [VDM\Joomla\Openai](#vdm-joomla-openai) + + - **class Chat** | [Details](src/c54c92da-2dd7-4136-81c9-1785f2fa0af5) | [Code](src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/code.php) | [Settings](src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/settings.json) | Super__c54c92da_2dd7_4136_81c9_1785f2fa0af5__Power + - **class Completions** | [Details](src/796cca70-2577-4f8f-9a05-ac37db1f2f02) | [Code](src/796cca70-2577-4f8f-9a05-ac37db1f2f02/code.php) | [Settings](src/796cca70-2577-4f8f-9a05-ac37db1f2f02/settings.json) | Super__796cca70_2577_4f8f_9a05_ac37db1f2f02__Power + - **class Models** | [Details](src/08abd2df-1406-4939-a1a6-94d2fce3f043) | [Code](src/08abd2df-1406-4939-a1a6-94d2fce3f043/code.php) | [Settings](src/08abd2df-1406-4939-a1a6-94d2fce3f043/settings.json) | Super__08abd2df_1406_4939_a1a6_94d2fce3f043__Power + - **class Moderate** | [Details](src/34f2c249-64a7-4229-9592-77e58f6e994f) | [Code](src/34f2c249-64a7-4229-9592-77e58f6e994f/code.php) | [Settings](src/34f2c249-64a7-4229-9592-77e58f6e994f/settings.json) | Super__34f2c249_64a7_4229_9592_77e58f6e994f__Power +- **Namespace**: [VDM\Joomla\Openai\Abstraction](#vdm-joomla-openai-abstraction) + + - **abstract class Api** | [Details](src/585de711-2784-4f89-90bf-94a8a63366f1) | [Code](src/585de711-2784-4f89-90bf-94a8a63366f1/code.php) | [Settings](src/585de711-2784-4f89-90bf-94a8a63366f1/settings.json) | Super__585de711_2784_4f89_90bf_94a8a63366f1__Power +- **Namespace**: [VDM\Joomla\Openai\Service](#vdm-joomla-openai-service) + + - **class Utilities** | [Details](src/07858e1f-5698-4227-8941-03dc93557938) | [Code](src/07858e1f-5698-4227-8941-03dc93557938/code.php) | [Settings](src/07858e1f-5698-4227-8941-03dc93557938/settings.json) | Super__07858e1f_5698_4227_8941_03dc93557938__Power +- **Namespace**: [VDM\Joomla\Openai\Utilities](#vdm-joomla-openai-utilities) + + - **final class Http** | [Details](src/4c58b254-aea5-40aa-b54d-9586a1690451) | [Code](src/4c58b254-aea5-40aa-b54d-9586a1690451/code.php) | [Settings](src/4c58b254-aea5-40aa-b54d-9586a1690451/settings.json) | Super__4c58b254_aea5_40aa_b54d_9586a1690451__Power + - **final class Response** | [Details](src/c464393e-7606-406e-8463-a86774590966) | [Code](src/c464393e-7606-406e-8463-a86774590966/code.php) | [Settings](src/c464393e-7606-406e-8463-a86774590966/settings.json) | Super__c464393e_7606_406e_8463_a86774590966__Power + - **final class Uri** | [Details](src/13ef84f4-25b0-43dd-a9f6-0722abf220c1) | [Code](src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/code.php) | [Settings](src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/settings.json) | Super__13ef84f4_25b0_43dd_a9f6_0722abf220c1__Power + +--- +``` + ██╗ ██████╗ ██████╗ ███╗ ███╗██╗ █████╗ + ██║██╔═══██╗██╔═══██╗████╗ ████║██║ ██╔══██╗ + ██║██║ ██║██║ ██║██╔████╔██║██║ ███████║ +██ ██║██║ ██║██║ ██║██║╚██╔╝██║██║ ██╔══██║ +╚█████╔╝╚██████╔╝╚██████╔╝██║ ╚═╝ ██║███████╗██║ ██║ + ╚════╝ ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚══════╝╚═╝ ╚═╝ + ██████╗ ██████╗ ███╗ ███╗██████╗ ██████╗ ███╗ ██╗███████╗███╗ ██╗████████╗ +██╔════╝██╔═══██╗████╗ ████║██╔══██╗██╔═══██╗████╗ ██║██╔════╝████╗ ██║╚══██╔══╝ +██║ ██║ ██║██╔████╔██║██████╔╝██║ ██║██╔██╗ ██║█████╗ ██╔██╗ ██║ ██║ +██║ ██║ ██║██║╚██╔╝██║██╔═══╝ ██║ ██║██║╚██╗██║██╔══╝ ██║╚██╗██║ ██║ +╚██████╗╚██████╔╝██║ ╚═╝ ██║██║ ╚██████╔╝██║ ╚████║███████╗██║ ╚████║ ██║ + ╚═════╝ ╚═════╝ ╚═╝ ╚═╝╚═╝ ╚═════╝ ╚═╝ ╚═══╝╚══════╝╚═╝ ╚═══╝ ╚═╝ +██████╗ ██╗ ██╗██╗██╗ ██████╗ ███████╗██████╗ +██╔══██╗██║ ██║██║██║ ██╔══██╗██╔════╝██╔══██╗ +██████╔╝██║ ██║██║██║ ██║ ██║█████╗ ██████╔╝ +██╔══██╗██║ ██║██║██║ ██║ ██║██╔══╝ ██╔══██╗ +██████╔╝╚██████╔╝██║███████╗██████╔╝███████╗██║ ██║ +╚═════╝ ╚═════╝ ╚═╝╚══════╝╚═════╝ ╚══════╝╚═╝ ╚═╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/07858e1f-5698-4227-8941-03dc93557938/README.md b/src/07858e1f-5698-4227-8941-03dc93557938/README.md index 433b69e..521aa6e 100644 --- a/src/07858e1f-5698-4227-8941-03dc93557938/README.md +++ b/src/07858e1f-5698-4227-8941-03dc93557938/README.md @@ -1 +1,61 @@ -###POWERREADME### \ No newline at end of file +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Utilities (Details) +> namespace: **VDM\Joomla\Openai\Service** +```uml +@startuml +class Utilities #Gold { + + register(Container $container) : void + + getUri(Container $container) : Uri + + getResponse(Container $container) : Response + + getHttp(Container $container) : Http +} + +note right of Utilities::register + Registers the service provider with a DI container. + + since: 3.2.0 + return: void +end note + +note right of Utilities::getUri + Get the Uri class + + since: 3.2.0 + return: Uri +end note + +note right of Utilities::getResponse + Get the Response class + + since: 3.2.0 + return: Response +end note + +note right of Utilities::getHttp + Get the Http class + + since: 3.2.0 + return: Http +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/07858e1f-5698-4227-8941-03dc93557938/code.php b/src/07858e1f-5698-4227-8941-03dc93557938/code.php index 26c1a50..bd75d71 100644 --- a/src/07858e1f-5698-4227-8941-03dc93557938/code.php +++ b/src/07858e1f-5698-4227-8941-03dc93557938/code.php @@ -9,4 +9,84 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -###POWERCODE### +namespace VDM\Joomla\Openai\Service; + + +use Joomla\DI\Container; +use Joomla\DI\ServiceProviderInterface; +use VDM\Joomla\Openai\Utilities\Uri; +use VDM\Joomla\Openai\Utilities\Response; +use VDM\Joomla\Openai\Utilities\Http; +use VDM\Joomla\Utilities\Component\Helper; + + +/** + * The Openai Utilities Service + * + * @since 3.2.0 + */ +class Utilities implements ServiceProviderInterface +{ + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Uri::class, 'Openai.Utilities.Uri') + ->share('Openai.Utilities.Uri', [$this, 'getUri'], true); + + $container->alias(Response::class, 'Openai.Utilities.Response') + ->share('Openai.Utilities.Response', [$this, 'getResponse'], true); + + $container->alias(Http::class, 'Openai.Utilities.Http') + ->share('Openai.Utilities.Http', [$this, 'getHttp'], true); + } + + /** + * Get the Uri class + * + * @param Container $container The DI container. + * + * @return Uri + * @since 3.2.0 + */ + public function getUri(Container $container): Uri + { + return new Uri(); + } + + /** + * Get the Response class + * + * @param Container $container The DI container. + * + * @return Response + * @since 3.2.0 + */ + public function getResponse(Container $container): Response + { + return new Response(); + } + + /** + * Get the Http class + * + * @param Container $container The DI container. + * + * @return Http + * @since 3.2.0 + */ + public function getHttp(Container $container): Http + { + return new Http( + Helper::getParams()->get('openai_token'), + Helper::getParams()->get('openai_org_token') + ); + } +} + diff --git a/src/07858e1f-5698-4227-8941-03dc93557938/code.power b/src/07858e1f-5698-4227-8941-03dc93557938/code.power index 69309b0..a0851b0 100644 --- a/src/07858e1f-5698-4227-8941-03dc93557938/code.power +++ b/src/07858e1f-5698-4227-8941-03dc93557938/code.power @@ -1 +1,61 @@ -###CODEPOWER### \ No newline at end of file + /** + * Registers the service provider with a DI container. + * + * @param Container $container The DI container. + * + * @return void + * @since 3.2.0 + */ + public function register(Container $container) + { + $container->alias(Uri::class, 'Openai.Utilities.Uri') + ->share('Openai.Utilities.Uri', [$this, 'getUri'], true); + + $container->alias(Response::class, 'Openai.Utilities.Response') + ->share('Openai.Utilities.Response', [$this, 'getResponse'], true); + + $container->alias(Http::class, 'Openai.Utilities.Http') + ->share('Openai.Utilities.Http', [$this, 'getHttp'], true); + } + + /** + * Get the Uri class + * + * @param Container $container The DI container. + * + * @return Uri + * @since 3.2.0 + */ + public function getUri(Container $container): Uri + { + return new Uri(); + } + + /** + * Get the Response class + * + * @param Container $container The DI container. + * + * @return Response + * @since 3.2.0 + */ + public function getResponse(Container $container): Response + { + return new Response(); + } + + /** + * Get the Http class + * + * @param Container $container The DI container. + * + * @return Http + * @since 3.2.0 + */ + public function getHttp(Container $container): Http + { + return new Http( + Helper::getParams()->get('openai_token'), + Helper::getParams()->get('openai_org_token') + ); + } \ No newline at end of file diff --git a/src/07858e1f-5698-4227-8941-03dc93557938/settings.json b/src/07858e1f-5698-4227-8941-03dc93557938/settings.json index 6b3b222..7b79603 100644 --- a/src/07858e1f-5698-4227-8941-03dc93557938/settings.json +++ b/src/07858e1f-5698-4227-8941-03dc93557938/settings.json @@ -1 +1,38 @@ -###POWERLINKER### \ No newline at end of file +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "07858e1f-5698-4227-8941-03dc93557938", + "implements": [ + "-1" + ], + "load_selection": null, + "name": "Utilities", + "power_version": "1.0.0", + "system_name": "Joomla.Openai.Service.Utilities", + "type": "class", + "use_selection": { + "use_selection0": { + "use": "13ef84f4-25b0-43dd-a9f6-0722abf220c1", + "as": "default" + }, + "use_selection1": { + "use": "c464393e-7606-406e-8463-a86774590966", + "as": "default" + }, + "use_selection2": { + "use": "4c58b254-aea5-40aa-b54d-9586a1690451", + "as": "default" + }, + "use_selection3": { + "use": "640b5352-fb09-425f-a26e-cd44eda03f15", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Openai\\Service.Utilities", + "description": "The Openai Utilities Service\r\n\r\n@since 3.2.0", + "implements_custom": "ServiceProviderInterface", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \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\\DI\\Container;\r\nuse Joomla\\DI\\ServiceProviderInterface;", + "composer": "" +} \ No newline at end of file diff --git a/src/08abd2df-1406-4939-a1a6-94d2fce3f043/README.md b/src/08abd2df-1406-4939-a1a6-94d2fce3f043/README.md index 433b69e..3fdadcf 100644 --- a/src/08abd2df-1406-4939-a1a6-94d2fce3f043/README.md +++ b/src/08abd2df-1406-4939-a1a6-94d2fce3f043/README.md @@ -1 +1,37 @@ -###POWERREADME### \ No newline at end of file +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Models (Details) +> namespace: **VDM\Joomla\Openai** +```uml +@startuml +class Models #Gold { + + list() : ?object +} + +note right of Models::list + List the available models from OpenAI API. + + since: 3.2.0 + return: ?object +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/08abd2df-1406-4939-a1a6-94d2fce3f043/code.php b/src/08abd2df-1406-4939-a1a6-94d2fce3f043/code.php index 26c1a50..034cdd3 100644 --- a/src/08abd2df-1406-4939-a1a6-94d2fce3f043/code.php +++ b/src/08abd2df-1406-4939-a1a6-94d2fce3f043/code.php @@ -9,4 +9,36 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -###POWERCODE### +namespace VDM\Joomla\Openai; + + +use VDM\Joomla\Openai\Abstraction\Api; + + +/** + * The Openai Models + * + * @since 3.2.0 + */ +class Models extends Api +{ + /** + * List the available models from OpenAI API. + * + * @return object|null + * @since 3.2.0 + **/ + public function list(): ?object + { + // Build the request path. + $path = "/models"; + + // Send the get request. + return $this->response->get( + $this->http->get( + $this->uri->get($path) + ) + ); + } +} + diff --git a/src/08abd2df-1406-4939-a1a6-94d2fce3f043/code.power b/src/08abd2df-1406-4939-a1a6-94d2fce3f043/code.power index 69309b0..675f17b 100644 --- a/src/08abd2df-1406-4939-a1a6-94d2fce3f043/code.power +++ b/src/08abd2df-1406-4939-a1a6-94d2fce3f043/code.power @@ -1 +1,18 @@ -###CODEPOWER### \ No newline at end of file + /** + * List the available models from OpenAI API. + * + * @return object|null + * @since 3.2.0 + **/ + public function list(): ?object + { + // Build the request path. + $path = "/models"; + + // Send the get request. + return $this->response->get( + $this->http->get( + $this->uri->get($path) + ) + ); + } \ No newline at end of file diff --git a/src/08abd2df-1406-4939-a1a6-94d2fce3f043/settings.json b/src/08abd2df-1406-4939-a1a6-94d2fce3f043/settings.json index 6b3b222..9718167 100644 --- a/src/08abd2df-1406-4939-a1a6-94d2fce3f043/settings.json +++ b/src/08abd2df-1406-4939-a1a6-94d2fce3f043/settings.json @@ -1 +1,18 @@ -###POWERLINKER### \ No newline at end of file +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "585de711-2784-4f89-90bf-94a8a63366f1", + "guid": "08abd2df-1406-4939-a1a6-94d2fce3f043", + "implements": null, + "load_selection": null, + "name": "Models", + "power_version": "1.0.0", + "system_name": "Joomla.Openai.Models", + "type": "class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Openai\\Models", + "description": "The Openai Models\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/README.md b/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/README.md index 433b69e..54950a5 100644 --- a/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/README.md +++ b/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/README.md @@ -1 +1,74 @@ -###POWERREADME### \ No newline at end of file +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# final class Uri (Details) +> namespace: **VDM\Joomla\Openai\Utilities** +```uml +@startuml +class Uri << (F,LightGreen) >> #Green { + - string $version + - string $url + + __construct(string $url = 'https://api.openai.com', string $version = 'v1') + + get(string $path) : JoomlaUri + + api() : string + - setUrl(string $url) : void + - setVersion(string $version) : void +} + +note right of Uri::__construct + Constructor +example: https://api.openai.com + + since: 3.2.0 +end note + +note right of Uri::get + Method to build and return a full request URL for the request. This method will +add appropriate pagination details if necessary and also prepend the API url +to have a complete URL for the request. + + since: 3.2.0 + return: JoomlaUri +end note + +note right of Uri::api + Get the full API URL + + since: 3.2.0 + return: string +end note + +note right of Uri::setUrl + Set the URL of the API +example: https://api.openai.com + + since: 3.2.0 + return: void +end note + +note right of Uri::setVersion + Set the version of the API + + since: 3.2.0 + return: void +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/code.php b/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/code.php index 26c1a50..ceeb5cd 100644 --- a/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/code.php +++ b/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/code.php @@ -9,4 +9,107 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -###POWERCODE### +namespace VDM\Joomla\Openai\Utilities; + + +use Joomla\Uri\Uri as JoomlaUri; + + +/** + * The Openai Uri + * + * @since 3.2.0 + */ +final class Uri +{ + /** + * The api version + * + * @var string + * @since 3.2.0 + */ + private string $version; + + /** + * The api URL + * + * @var string + * @since 3.2.0 + */ + private string $url; + + /** + * Constructor + * + * @param string $url URL to the openai system + * example: https://api.openai.com + * @param string $version Version to the openai system + * + * @since 3.2.0 + **/ + public function __construct( + string $url = 'https://api.openai.com', + string $version = 'v1') + { + // set the API details + $this->setUrl($url); + $this->setVersion($version); + } + + /** + * Method to build and return a full request URL for the request. This method will + * add appropriate pagination details if necessary and also prepend the API url + * to have a complete URL for the request. + * + * @param string $path URL to inflect + * + * @return JoomlaUri + * @since 3.2.0 + **/ + public function get(string $path): JoomlaUri + { + // Get a new Uri object focusing the api url and given path. + $uri = new JoomlaUri($this->api() . $path); + + return $uri; + } + + /** + * Get the full API URL + * + * @return string + * @since 3.2.0 + **/ + public function api(): string + { + return $this->url . '/' . $this->version; + } + + /** + * Set the URL of the API + * + * @param string $url URL to your openai system + * example: https://api.openai.com + * + * @return void + * @since 3.2.0 + **/ + private function setUrl(string $url) + { + return $this->url = $url; + } + + /** + * Set the version of the API + * + * @param string $version version to your openai API + * + * @return void + * @since 3.2.0 + **/ + private function setVersion($version) + { + return $this->version = $version; + } +} + diff --git a/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/code.power b/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/code.power index 69309b0..e23c7ed 100644 --- a/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/code.power +++ b/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/code.power @@ -1 +1,89 @@ -###CODEPOWER### \ No newline at end of file + /** + * The api version + * + * @var string + * @since 3.2.0 + */ + private string $version; + + /** + * The api URL + * + * @var string + * @since 3.2.0 + */ + private string $url; + + /** + * Constructor + * + * @param string $url URL to the openai system + * example: https://api.openai.com + * @param string $version Version to the openai system + * + * @since 3.2.0 + **/ + public function __construct( + string $url = 'https://api.openai.com', + string $version = 'v1') + { + // set the API details + $this->setUrl($url); + $this->setVersion($version); + } + + /** + * Method to build and return a full request URL for the request. This method will + * add appropriate pagination details if necessary and also prepend the API url + * to have a complete URL for the request. + * + * @param string $path URL to inflect + * + * @return JoomlaUri + * @since 3.2.0 + **/ + public function get(string $path): JoomlaUri + { + // Get a new Uri object focusing the api url and given path. + $uri = new JoomlaUri($this->api() . $path); + + return $uri; + } + + /** + * Get the full API URL + * + * @return string + * @since 3.2.0 + **/ + public function api(): string + { + return $this->url . '/' . $this->version; + } + + /** + * Set the URL of the API + * + * @param string $url URL to your openai system + * example: https://api.openai.com + * + * @return void + * @since 3.2.0 + **/ + private function setUrl(string $url) + { + return $this->url = $url; + } + + /** + * Set the version of the API + * + * @param string $version version to your openai API + * + * @return void + * @since 3.2.0 + **/ + private function setVersion($version) + { + return $this->version = $version; + } \ No newline at end of file diff --git a/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/settings.json b/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/settings.json index 6b3b222..506ba40 100644 --- a/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/settings.json +++ b/src/13ef84f4-25b0-43dd-a9f6-0722abf220c1/settings.json @@ -1 +1,18 @@ -###POWERLINKER### \ No newline at end of file +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "13ef84f4-25b0-43dd-a9f6-0722abf220c1", + "implements": null, + "load_selection": null, + "name": "Uri", + "power_version": "1.0.0", + "system_name": "Joomla.Openai.Utilities.Uri", + "type": "final class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Openai\\Utilities.Uri", + "description": "The Openai Uri\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \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\\Uri\\Uri as JoomlaUri;", + "composer": "" +} \ No newline at end of file diff --git a/src/34f2c249-64a7-4229-9592-77e58f6e994f/README.md b/src/34f2c249-64a7-4229-9592-77e58f6e994f/README.md index 433b69e..ee7991e 100644 --- a/src/34f2c249-64a7-4229-9592-77e58f6e994f/README.md +++ b/src/34f2c249-64a7-4229-9592-77e58f6e994f/README.md @@ -1 +1,38 @@ -###POWERREADME### \ No newline at end of file +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Moderate (Details) +> namespace: **VDM\Joomla\Openai** +```uml +@startuml +class Moderate #Gold { + + text(string|array $input, ?string $model = null) : ?object +} + +note right of Moderate::text + Classify if text violates OpenAI's Content Policy. +API Ref: https://platform.openai.com/docs/api-reference/moderations/create + + since: 3.2.0 + return: ?object +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/34f2c249-64a7-4229-9592-77e58f6e994f/code.php b/src/34f2c249-64a7-4229-9592-77e58f6e994f/code.php index 26c1a50..5f02896 100644 --- a/src/34f2c249-64a7-4229-9592-77e58f6e994f/code.php +++ b/src/34f2c249-64a7-4229-9592-77e58f6e994f/code.php @@ -9,4 +9,52 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -###POWERCODE### +namespace VDM\Joomla\Openai; + + +use VDM\Joomla\Openai\Abstraction\Api; + + +/** + * The Openai Moderate + * + * @since 3.2.0 + */ +class Moderate extends Api +{ + /** + * Classify if text violates OpenAI's Content Policy. + * API Ref: https://platform.openai.com/docs/api-reference/moderations/create + * + * @param string|array $input The input text to classify. + * @param string|null $model The moderation model (optional). + * + * @return object|null + * @since 3.2.0 + **/ + public function text( + $input, + ?string $model = null + ): ?object + { + // Build the request path. + $path = "/moderations"; + + // Set the moderation data. + $data = new \stdClass(); + $data->input = $input; + + if ($model !== null) + { + $data->model = $model; + } + + // Send the post request. + return $this->response->get( + $this->http->post( + $this->uri->get($path), json_encode($data) + ) + ); + } +} + diff --git a/src/34f2c249-64a7-4229-9592-77e58f6e994f/code.power b/src/34f2c249-64a7-4229-9592-77e58f6e994f/code.power index 69309b0..45c7e7f 100644 --- a/src/34f2c249-64a7-4229-9592-77e58f6e994f/code.power +++ b/src/34f2c249-64a7-4229-9592-77e58f6e994f/code.power @@ -1 +1,34 @@ -###CODEPOWER### \ No newline at end of file + /** + * Classify if text violates OpenAI's Content Policy. + * API Ref: https://platform.openai.com/docs/api-reference/moderations/create + * + * @param string|array $input The input text to classify. + * @param string|null $model The moderation model (optional). + * + * @return object|null + * @since 3.2.0 + **/ + public function text( + $input, + ?string $model = null + ): ?object + { + // Build the request path. + $path = "/moderations"; + + // Set the moderation data. + $data = new \stdClass(); + $data->input = $input; + + if ($model !== null) + { + $data->model = $model; + } + + // Send the post request. + return $this->response->get( + $this->http->post( + $this->uri->get($path), json_encode($data) + ) + ); + } \ No newline at end of file diff --git a/src/34f2c249-64a7-4229-9592-77e58f6e994f/settings.json b/src/34f2c249-64a7-4229-9592-77e58f6e994f/settings.json index 6b3b222..7f8512e 100644 --- a/src/34f2c249-64a7-4229-9592-77e58f6e994f/settings.json +++ b/src/34f2c249-64a7-4229-9592-77e58f6e994f/settings.json @@ -1 +1,18 @@ -###POWERLINKER### \ No newline at end of file +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "585de711-2784-4f89-90bf-94a8a63366f1", + "guid": "34f2c249-64a7-4229-9592-77e58f6e994f", + "implements": null, + "load_selection": null, + "name": "Moderate", + "power_version": "1.0.0", + "system_name": "Joomla.Openai.Moderate", + "type": "class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Openai\\Moderate", + "description": "The Openai Moderate\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/4c58b254-aea5-40aa-b54d-9586a1690451/README.md b/src/4c58b254-aea5-40aa-b54d-9586a1690451/README.md index 433b69e..0658582 100644 --- a/src/4c58b254-aea5-40aa-b54d-9586a1690451/README.md +++ b/src/4c58b254-aea5-40aa-b54d-9586a1690451/README.md @@ -1 +1,36 @@ -###POWERREADME### \ No newline at end of file +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# final class Http (Details) +> namespace: **VDM\Joomla\Openai\Utilities** +```uml +@startuml +class Http << (F,LightGreen) >> #Green { + + __construct(?string $token, ?string $org = null) +} + +note right of Http::__construct + Constructor. + + since: 3.2.0 +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/4c58b254-aea5-40aa-b54d-9586a1690451/code.php b/src/4c58b254-aea5-40aa-b54d-9586a1690451/code.php index 26c1a50..7ebb977 100644 --- a/src/4c58b254-aea5-40aa-b54d-9586a1690451/code.php +++ b/src/4c58b254-aea5-40aa-b54d-9586a1690451/code.php @@ -9,4 +9,55 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -###POWERCODE### +namespace VDM\Joomla\Openai\Utilities; + + +use Joomla\CMS\Http\Http as JoomlaHttp; +use Joomla\Registry\Registry; + + +/** + * The Openai Http + * + * @since 3.2.0 + */ +final class Http extends JoomlaHttp +{ + /** + * Constructor. + * + * @param string|null $token The Openai API token. + * @param string|null $org The Openai API Organization token. + * + * @since 3.2.0 + * @throws \InvalidArgumentException + **/ + public function __construct(?string $token, ?string $org = null) + { + // setup config + $config = [ + 'userAgent' => 'JoomlaOpenai/3.0', + 'headers' => [ + 'Content-Type' => 'application/json' + ] + ]; + + // add the token if given + if (is_string($token)) + { + $config['headers']['Authorization'] = 'Bearer ' . $token; + } + + // add the organization token if given + if (is_string($org)) + { + $config['headers']['OpenAI-Organization'] = $org; + } + + $options = new Registry($config); + + // run parent constructor + parent::__construct($options); + } +} + diff --git a/src/4c58b254-aea5-40aa-b54d-9586a1690451/code.power b/src/4c58b254-aea5-40aa-b54d-9586a1690451/code.power index 69309b0..6519ef6 100644 --- a/src/4c58b254-aea5-40aa-b54d-9586a1690451/code.power +++ b/src/4c58b254-aea5-40aa-b54d-9586a1690451/code.power @@ -1 +1,36 @@ -###CODEPOWER### \ No newline at end of file + /** + * Constructor. + * + * @param string|null $token The Openai API token. + * @param string|null $org The Openai API Organization token. + * + * @since 3.2.0 + * @throws \InvalidArgumentException + **/ + public function __construct(?string $token, ?string $org = null) + { + // setup config + $config = [ + 'userAgent' => 'JoomlaOpenai/3.0', + 'headers' => [ + 'Content-Type' => 'application/json' + ] + ]; + + // add the token if given + if (is_string($token)) + { + $config['headers']['Authorization'] = 'Bearer ' . $token; + } + + // add the organization token if given + if (is_string($org)) + { + $config['headers']['OpenAI-Organization'] = $org; + } + + $options = new Registry($config); + + // run parent constructor + parent::__construct($options); + } \ No newline at end of file diff --git a/src/4c58b254-aea5-40aa-b54d-9586a1690451/settings.json b/src/4c58b254-aea5-40aa-b54d-9586a1690451/settings.json index 6b3b222..b5fd086 100644 --- a/src/4c58b254-aea5-40aa-b54d-9586a1690451/settings.json +++ b/src/4c58b254-aea5-40aa-b54d-9586a1690451/settings.json @@ -1 +1,19 @@ -###POWERLINKER### \ No newline at end of file +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "-1", + "guid": "4c58b254-aea5-40aa-b54d-9586a1690451", + "implements": null, + "load_selection": null, + "name": "Http", + "power_version": "1.0.0", + "system_name": "Joomla.Openai.Utilities.Http", + "type": "final class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Openai\\Utilities.Http", + "description": "The Openai Http\r\n\r\n@since 3.2.0", + "extends_custom": "JoomlaHttp", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \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\\CMS\\Http\\Http as JoomlaHttp;\r\nuse Joomla\\Registry\\Registry;", + "composer": "" +} \ No newline at end of file diff --git a/src/585de711-2784-4f89-90bf-94a8a63366f1/README.md b/src/585de711-2784-4f89-90bf-94a8a63366f1/README.md index 433b69e..f46c8db 100644 --- a/src/585de711-2784-4f89-90bf-94a8a63366f1/README.md +++ b/src/585de711-2784-4f89-90bf-94a8a63366f1/README.md @@ -1 +1,44 @@ -###POWERREADME### \ No newline at end of file +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# abstract class Api (Details) +> namespace: **VDM\Joomla\Openai\Abstraction** +```uml +@startuml +abstract Api #Orange { + # Http $http + # Uri $uri + # Response $response + + __construct(Http $http, Uri $uri, ...) +} + +note right of Api::__construct + Constructor. + + since: 3.2.0 + + arguments: + Http $http + Uri $uri + Response $response +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/585de711-2784-4f89-90bf-94a8a63366f1/code.php b/src/585de711-2784-4f89-90bf-94a8a63366f1/code.php index 26c1a50..2824706 100644 --- a/src/585de711-2784-4f89-90bf-94a8a63366f1/code.php +++ b/src/585de711-2784-4f89-90bf-94a8a63366f1/code.php @@ -9,4 +9,59 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -###POWERCODE### +namespace VDM\Joomla\Openai\Abstraction; + + +use VDM\Joomla\Openai\Utilities\Http; +use VDM\Joomla\Openai\Utilities\Uri; +use VDM\Joomla\Openai\Utilities\Response; + + +/** + * The Openai Api + * + * @since 3.2.0 + */ +abstract class Api +{ + /** + * The Http class + * + * @var Http + * @since 3.2.0 + */ + protected Http $http; + + /** + * The Uri class + * + * @var Uri + * @since 3.2.0 + */ + protected Uri $uri; + + /** + * The Response class + * + * @var Response + * @since 3.2.0 + */ + protected Response $response; + + /** + * Constructor. + * + * @param Http $http The http class. + * @param Uri $uri The uri class. + * @param Response $response The response class. + * + * @since 3.2.0 + **/ + public function __construct(Http $http, Uri $uri, Response $response) + { + $this->http = $http; + $this->uri = $uri; + $this->response = $response; + } +} + diff --git a/src/585de711-2784-4f89-90bf-94a8a63366f1/code.power b/src/585de711-2784-4f89-90bf-94a8a63366f1/code.power index 69309b0..7f1d19e 100644 --- a/src/585de711-2784-4f89-90bf-94a8a63366f1/code.power +++ b/src/585de711-2784-4f89-90bf-94a8a63366f1/code.power @@ -1 +1,39 @@ -###CODEPOWER### \ No newline at end of file + /** + * The Http class + * + * @var Http + * @since 3.2.0 + */ + protected Http $http; + + /** + * The Uri class + * + * @var Uri + * @since 3.2.0 + */ + protected Uri $uri; + + /** + * The Response class + * + * @var Response + * @since 3.2.0 + */ + protected Response $response; + + /** + * Constructor. + * + * @param Http $http The http class. + * @param Uri $uri The uri class. + * @param Response $response The response class. + * + * @since 3.2.0 + **/ + public function __construct(Http $http, Uri $uri, Response $response) + { + $this->http = $http; + $this->uri = $uri; + $this->response = $response; + } \ No newline at end of file diff --git a/src/585de711-2784-4f89-90bf-94a8a63366f1/settings.json b/src/585de711-2784-4f89-90bf-94a8a63366f1/settings.json index 6b3b222..46c75ec 100644 --- a/src/585de711-2784-4f89-90bf-94a8a63366f1/settings.json +++ b/src/585de711-2784-4f89-90bf-94a8a63366f1/settings.json @@ -1 +1,31 @@ -###POWERLINKER### \ No newline at end of file +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "0", + "guid": "585de711-2784-4f89-90bf-94a8a63366f1", + "implements": null, + "load_selection": null, + "name": "Api", + "power_version": "1.0.0", + "system_name": "Joomla.Openai.Abstraction.Api", + "type": "abstract class", + "use_selection": { + "use_selection0": { + "use": "4c58b254-aea5-40aa-b54d-9586a1690451", + "as": "default" + }, + "use_selection1": { + "use": "13ef84f4-25b0-43dd-a9f6-0722abf220c1", + "as": "default" + }, + "use_selection2": { + "use": "c464393e-7606-406e-8463-a86774590966", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Openai\\Abstraction.Api", + "description": "The Openai Api\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/README.md b/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/README.md index 433b69e..e6445db 100644 --- a/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/README.md +++ b/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/README.md @@ -1 +1,56 @@ -###POWERREADME### \ No newline at end of file +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Completions (Details) +> namespace: **VDM\Joomla\Openai** +```uml +@startuml +class Completions #Gold { + + create(string $model, string|array $prompt, ...) : ?object +} + +note right of Completions::create + Create a completion using the OpenAI API. +API Ref: https://platform.openai.com/docs/api-reference/completions + + since: 3.2.0 + return: ?object + + arguments: + string $model + string|array $prompt + ?int $maxTokens = null + ?string $suffix = null + ?float $temperature = null + ?float $topP = null + ?int $n = null + ?bool $stream = null + ?int $logprobs = null + ?bool $echo = null + string|null $stop = null + ?float $presencePenalty = null + ?float $frequencyPenalty = null + ?int $bestOf = null + ?array $logitBias = null + ?string $user = null +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/code.php b/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/code.php index 26c1a50..65769df 100644 --- a/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/code.php +++ b/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/code.php @@ -9,4 +9,150 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -###POWERCODE### +namespace VDM\Joomla\Openai; + + +use VDM\Joomla\Openai\Abstraction\Api; + + +/** + * The Openai Completions + * + * @since 3.2.0 + */ +class Completions extends Api +{ + /** + * Create a completion using the OpenAI API. + * API Ref: https://platform.openai.com/docs/api-reference/completions + * + * @param string $model The ID of the model to use. + * @param string|array $prompt The prompt(s) to generate completions for. + * @param int|null $maxTokens The maximum number of tokens to generate (optional). + * @param float|null $temperature The sampling temperature to use (optional). + * @param string $suffix The suffix that comes after a completion of inserted text. (optional). + * @param float|null $topP The top_p value for nucleus sampling (optional). + * @param int|null $n How many completions to generate (optional). + * @param bool|null $stream Whether to stream back partial progress (optional). + * @param int|null $logprobs Include the log probabilities on the most likely tokens (optional). + * @param bool|null $echo Echo back the prompt in addition to the completion (optional). + * @param string|null $stop Up to 4 sequences where the API will stop generating (optional). + * @param float|null $presencePenalty The presence penalty to use (optional). + * @param float|null $frequencyPenalty The frequency penalty to use (optional). + * @param int|null $bestOf Generates best_of completions server-side (optional). + * @param array|null $logitBias Modify the likelihood of specified tokens (optional). + * @param string|null $user A unique identifier representing your end-user (optional). + * + * @return object|null + * @since 3.2.0 + **/ + public function create( + string $model, + $prompt, + ?int $maxTokens = null, + ?string $suffix = null, + ?float $temperature = null, + ?float $topP = null, + ?int $n = null, + ?bool $stream = null, + ?int $logprobs = null, + ?bool $echo = null, + $stop = null, + ?float $presencePenalty = null, + ?float $frequencyPenalty = null, + ?int $bestOf = null, + ?array $logitBias = null, + ?string $user = null + ): ?object + { + // Build the request path. + $path = "/completions"; + + // Set the completion data. + $data = new \stdClass(); + $data->model = $model; + $data->prompt = $prompt; + + if ($maxTokens !== null) + { + $data->max_tokens = $maxTokens; + } + + if ($temperature !== null) + { + $data->temperature = $temperature; + } + + if ($suffix !== null) + { + $data->suffix = $suffix; + } + + if ($topP !== null) + { + $data->top_p = $topP; + } + + if ($n !== null) + { + $data->n = $n; + } + + if ($stream !== null) + { + $data->stream = $stream; + } + + if ($logprobs !== null) + { + $data->logprobs = $logprobs; + } + + if ($echo !== null) + { + $data->echo = $echo; + } + + if ($stop !== null) + { + $data->stop = $stop; + } + + if ($presencePenalty !== null) + { + $data->presence_penalty = $presencePenalty; + } + + if ($frequencyPenalty !== null) + { + $data->frequency_penalty = $frequencyPenalty; + } + + if ($bestOf !== null) + { + $data->best_of = $bestOf; + } + + if ($logitBias !== null) + { + $data->logit_bias = new \stdClass(); + foreach ($logitBias as $key => $val) + { + $data->logit_bias->$key = $val; + } + } + + if ($user !== null) + { + $data->user = $user; + } + + // Send the post request. + return $this->response->get( + $this->http->post( + $this->uri->get($path), json_encode($data) + ) + ); + } +} + diff --git a/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/code.power b/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/code.power index 69309b0..d687050 100644 --- a/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/code.power +++ b/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/code.power @@ -1 +1,132 @@ -###CODEPOWER### \ No newline at end of file + /** + * Create a completion using the OpenAI API. + * API Ref: https://platform.openai.com/docs/api-reference/completions + * + * @param string $model The ID of the model to use. + * @param string|array $prompt The prompt(s) to generate completions for. + * @param int|null $maxTokens The maximum number of tokens to generate (optional). + * @param float|null $temperature The sampling temperature to use (optional). + * @param string $suffix The suffix that comes after a completion of inserted text. (optional). + * @param float|null $topP The top_p value for nucleus sampling (optional). + * @param int|null $n How many completions to generate (optional). + * @param bool|null $stream Whether to stream back partial progress (optional). + * @param int|null $logprobs Include the log probabilities on the most likely tokens (optional). + * @param bool|null $echo Echo back the prompt in addition to the completion (optional). + * @param string|null $stop Up to 4 sequences where the API will stop generating (optional). + * @param float|null $presencePenalty The presence penalty to use (optional). + * @param float|null $frequencyPenalty The frequency penalty to use (optional). + * @param int|null $bestOf Generates best_of completions server-side (optional). + * @param array|null $logitBias Modify the likelihood of specified tokens (optional). + * @param string|null $user A unique identifier representing your end-user (optional). + * + * @return object|null + * @since 3.2.0 + **/ + public function create( + string $model, + $prompt, + ?int $maxTokens = null, + ?string $suffix = null, + ?float $temperature = null, + ?float $topP = null, + ?int $n = null, + ?bool $stream = null, + ?int $logprobs = null, + ?bool $echo = null, + $stop = null, + ?float $presencePenalty = null, + ?float $frequencyPenalty = null, + ?int $bestOf = null, + ?array $logitBias = null, + ?string $user = null + ): ?object + { + // Build the request path. + $path = "/completions"; + + // Set the completion data. + $data = new \stdClass(); + $data->model = $model; + $data->prompt = $prompt; + + if ($maxTokens !== null) + { + $data->max_tokens = $maxTokens; + } + + if ($temperature !== null) + { + $data->temperature = $temperature; + } + + if ($suffix !== null) + { + $data->suffix = $suffix; + } + + if ($topP !== null) + { + $data->top_p = $topP; + } + + if ($n !== null) + { + $data->n = $n; + } + + if ($stream !== null) + { + $data->stream = $stream; + } + + if ($logprobs !== null) + { + $data->logprobs = $logprobs; + } + + if ($echo !== null) + { + $data->echo = $echo; + } + + if ($stop !== null) + { + $data->stop = $stop; + } + + if ($presencePenalty !== null) + { + $data->presence_penalty = $presencePenalty; + } + + if ($frequencyPenalty !== null) + { + $data->frequency_penalty = $frequencyPenalty; + } + + if ($bestOf !== null) + { + $data->best_of = $bestOf; + } + + if ($logitBias !== null) + { + $data->logit_bias = new \stdClass(); + foreach ($logitBias as $key => $val) + { + $data->logit_bias->$key = $val; + } + } + + if ($user !== null) + { + $data->user = $user; + } + + // Send the post request. + return $this->response->get( + $this->http->post( + $this->uri->get($path), json_encode($data) + ) + ); + } \ No newline at end of file diff --git a/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/settings.json b/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/settings.json index 6b3b222..44f7aec 100644 --- a/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/settings.json +++ b/src/796cca70-2577-4f8f-9a05-ac37db1f2f02/settings.json @@ -1 +1,18 @@ -###POWERLINKER### \ No newline at end of file +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "585de711-2784-4f89-90bf-94a8a63366f1", + "guid": "796cca70-2577-4f8f-9a05-ac37db1f2f02", + "implements": null, + "load_selection": null, + "name": "Completions", + "power_version": "1.0.0", + "system_name": "Joomla.Openai.Completions", + "type": "class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Openai\\Completions", + "description": "The Openai Completions\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/src/c464393e-7606-406e-8463-a86774590966/README.md b/src/c464393e-7606-406e-8463-a86774590966/README.md index 433b69e..26fac87 100644 --- a/src/c464393e-7606-406e-8463-a86774590966/README.md +++ b/src/c464393e-7606-406e-8463-a86774590966/README.md @@ -1 +1,66 @@ -###POWERREADME### \ No newline at end of file +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# final class Response (Details) +> namespace: **VDM\Joomla\Openai\Utilities** +```uml +@startuml +class Response << (F,LightGreen) >> #Green { + + get(JoomlaResponse $response, int $expectedCode = 200, ...) : mixed + + get_(JoomlaResponse $response, array $validate = [200 => null]) : mixed + # body(JoomlaResponse $response, mixed $default = null) : mixed + # error(JoomlaResponse $response) : string +} + +note right of Response::get + Process the response and decode it. + + since: 3.2.0 + return: mixed + + arguments: + JoomlaResponse $response + int $expectedCode = 200 + mixed $default = null +end note + +note right of Response::get_ + Process the response and decode it. (when we have multiple success codes) + + since: 3.2.0 + return: mixed +end note + +note right of Response::body + Return the body from the response + + since: 3.2.0 + return: mixed +end note + +note right of Response::error + Get the error message from the OpenAI API response + + since: 3.2.0 + return: string +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/c464393e-7606-406e-8463-a86774590966/code.php b/src/c464393e-7606-406e-8463-a86774590966/code.php index 26c1a50..b07d31d 100644 --- a/src/c464393e-7606-406e-8463-a86774590966/code.php +++ b/src/c464393e-7606-406e-8463-a86774590966/code.php @@ -9,4 +9,132 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -###POWERCODE### +namespace VDM\Joomla\Openai\Utilities; + + +use Joomla\CMS\Http\Response as JoomlaResponse; +use VDM\Joomla\Utilities\JsonHelper; +use VDM\Joomla\Utilities\StringHelper; + + +/** + * The Openai Response + * + * @since 3.2.0 + */ +final class Response +{ + /** + * Process the response and decode it. + * + * @param JoomlaResponse $response The response. + * @param integer $expectedCode The expected "good" code. + * @param mixed $default The default if body not have length + * + * @return mixed + * + * @since 3.2.0 + * @throws \DomainException + **/ + public function get(JoomlaResponse $response, int $expectedCode = 200, $default = null) + { + // Validate the response code. + if ($response->code != $expectedCode) + { + // Decode the error response and throw an exception. + $message = $this->error($response); + + // Throw an exception with the OpenAI error message and code. + throw new \DomainException($message, $response->code); + } + + return $this->body($response, $default); + } + + /** + * Process the response and decode it. (when we have multiple success codes) + * + * @param JoomlaResponse $response The response. + * @param array [$expectedCode => $default] The expected "good" code. and The default if body not have length + * + * @return mixed + * + * @since 3.2.0 + * @throws \DomainException + **/ + public function get_(JoomlaResponse $response, array $validate = [200 => null]) + { + // Validate the response code. + if (!isset($validate[$response->code])) + { + // Decode the error response and throw an exception. + $message = $this->error($response); + + // Throw an exception with the OpenAI error message and code. + throw new \DomainException($message, $response->code); + + } + + return $this->body($response, $validate[$response->code]); + } + + /** + * Return the body from the response + * + * @param JoomlaResponse $response The response. + * @param mixed $default The default if body not have length + * + * @return mixed + * @since 3.2.0 + **/ + protected function body(JoomlaResponse $response, $default = null) + { + // check that we have a body and that its JSON + if (isset($response->body) && StringHelper::check($response->body)) + { + if (JsonHelper::check($response->body)) + { + return json_decode((string) $response->body); + } + + return $response->body; + } + + return $default; + } + + /** + * Get the error message from the OpenAI API response + * + * @param JoomlaResponse $response The response. + * + * @return string + * @since 3.2.0 + **/ + protected function error(JoomlaResponse $response): string + { + // do we have a json string + if (isset($response->body) && JsonHelper::check($response->body)) + { + $error = json_decode($response->body); + } + else + { + return 'Invalid or empty response body.'; + } + + // check if OpenAI returned an error object + if (isset($error->error)) + { + // error object found, extract message and code + $errorMessage = isset($error->error->message) ? $error->error->message : 'Unknown error.'; + $errorCode = isset($error->error->code) ? $error->error->code : 'Unknown error code.'; + + // return formatted error message + return 'OpenAI Error: ' . $errorMessage . ' Code: ' . $errorCode; + } + + return 'No error information found in response.'; + } +} + diff --git a/src/c464393e-7606-406e-8463-a86774590966/code.power b/src/c464393e-7606-406e-8463-a86774590966/code.power index 69309b0..417bedc 100644 --- a/src/c464393e-7606-406e-8463-a86774590966/code.power +++ b/src/c464393e-7606-406e-8463-a86774590966/code.power @@ -1 +1,112 @@ -###CODEPOWER### \ No newline at end of file + /** + * Process the response and decode it. + * + * @param JoomlaResponse $response The response. + * @param integer $expectedCode The expected "good" code. + * @param mixed $default The default if body not have length + * + * @return mixed + * + * @since 3.2.0 + * @throws \DomainException + **/ + public function get(JoomlaResponse $response, int $expectedCode = 200, $default = null) + { + // Validate the response code. + if ($response->code != $expectedCode) + { + // Decode the error response and throw an exception. + $message = $this->error($response); + + // Throw an exception with the OpenAI error message and code. + throw new \DomainException($message, $response->code); + } + + return $this->body($response, $default); + } + + /** + * Process the response and decode it. (when we have multiple success codes) + * + * @param JoomlaResponse $response The response. + * @param array [$expectedCode => $default] The expected "good" code. and The default if body not have length + * + * @return mixed + * + * @since 3.2.0 + * @throws \DomainException + **/ + public function get_(JoomlaResponse $response, array $validate = [200 => null]) + { + // Validate the response code. + if (!isset($validate[$response->code])) + { + // Decode the error response and throw an exception. + $message = $this->error($response); + + // Throw an exception with the OpenAI error message and code. + throw new \DomainException($message, $response->code); + + } + + return $this->body($response, $validate[$response->code]); + } + + /** + * Return the body from the response + * + * @param JoomlaResponse $response The response. + * @param mixed $default The default if body not have length + * + * @return mixed + * @since 3.2.0 + **/ + protected function body(JoomlaResponse $response, $default = null) + { + // check that we have a body and that its JSON + if (isset($response->body) && StringHelper::check($response->body)) + { + if (JsonHelper::check($response->body)) + { + return json_decode((string) $response->body); + } + + return $response->body; + } + + return $default; + } + + /** + * Get the error message from the OpenAI API response + * + * @param JoomlaResponse $response The response. + * + * @return string + * @since 3.2.0 + **/ + protected function error(JoomlaResponse $response): string + { + // do we have a json string + if (isset($response->body) && JsonHelper::check($response->body)) + { + $error = json_decode($response->body); + } + else + { + return 'Invalid or empty response body.'; + } + + // check if OpenAI returned an error object + if (isset($error->error)) + { + // error object found, extract message and code + $errorMessage = isset($error->error->message) ? $error->error->message : 'Unknown error.'; + $errorCode = isset($error->error->code) ? $error->error->code : 'Unknown error code.'; + + // return formatted error message + return 'OpenAI Error: ' . $errorMessage . ' Code: ' . $errorCode; + } + + return 'No error information found in response.'; + } \ No newline at end of file diff --git a/src/c464393e-7606-406e-8463-a86774590966/settings.json b/src/c464393e-7606-406e-8463-a86774590966/settings.json index 6b3b222..16f89db 100644 --- a/src/c464393e-7606-406e-8463-a86774590966/settings.json +++ b/src/c464393e-7606-406e-8463-a86774590966/settings.json @@ -1 +1,27 @@ -###POWERLINKER### \ No newline at end of file +{ + "add_head": "1", + "add_licensing_template": "2", + "extends": "0", + "guid": "c464393e-7606-406e-8463-a86774590966", + "implements": null, + "load_selection": null, + "name": "Response", + "power_version": "1.0.0", + "system_name": "Joomla.Openai.Utilities.Response", + "type": "final class", + "use_selection": { + "use_selection0": { + "use": "4b225c51-d293-48e4-b3f6-5136cf5c3f18", + "as": "default" + }, + "use_selection1": { + "use": "1f28cb53-60d9-4db1-b517-3c7dc6b429ef", + "as": "default" + } + }, + "namespace": "VDM\\Joomla\\Openai\\Utilities.Response", + "description": "The Openai Response\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \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\\CMS\\Http\\Response as JoomlaResponse;", + "composer": "" +} \ No newline at end of file diff --git a/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/README.md b/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/README.md index 433b69e..09d7df8 100644 --- a/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/README.md +++ b/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/README.md @@ -1 +1,62 @@ -###POWERREADME### \ No newline at end of file +``` +██████╗ ██████╗ ██╗ ██╗███████╗██████╗ +██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ +██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ +██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ +██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ +╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ +``` +# class Chat (Details) +> namespace: **VDM\Joomla\Openai** +```uml +@startuml +class Chat #Gold { + + create(string $model, array $messages, ...) : ?object +} + +note right of Chat::create + Create a chat completion with the OpenAI API. +API Ref: https://platform.openai.com/docs/api-reference/chat/create +Each item in the array is an object with the following: +- role (string) Required +The role of the author of this message. +One of system, user, or assistant. +- content (string) Required +The contents of the message. +- name (string) Optional +The name of the author of this message. +May contain a-z, A-Z, 0-9, and underscores, +with a maximum length of 64 characters. + + since: 3.2.0 + return: ?object + + arguments: + string $model + array $messages + ?int $maxTokens = null + ?float $temperature = null + ?float $topP = null + ?int $n = null + ?bool $stream = null + mixed|null $stop = null + ?float $presencePenalty = null + ?float $frequencyPenalty = null + ?array $logitBias = null + ?string $user = null +end note + +@enduml +``` + +--- +``` + ██╗ ██████╗██████╗ + ██║██╔════╝██╔══██╗ + ██║██║ ██████╔╝ +██ ██║██║ ██╔══██╗ +╚█████╔╝╚██████╗██████╔╝ + ╚════╝ ╚═════╝╚═════╝ +``` +> Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder) + diff --git a/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/code.php b/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/code.php index 26c1a50..deb9097 100644 --- a/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/code.php +++ b/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/code.php @@ -9,4 +9,134 @@ * @license GNU General Public License version 2 or later; see LICENSE.txt */ -###POWERCODE### +namespace VDM\Joomla\Openai; + + +use VDM\Joomla\Openai\Abstraction\Api; + + +/** + * The Openai Chat + * + * @since 3.2.0 + */ +class Chat extends Api +{ + /** + * Create a chat completion with the OpenAI API. + * API Ref: https://platform.openai.com/docs/api-reference/chat/create + * + * @param string $model The model to use for completion. + * @param array $messages A list of messages describing the conversation so far. + * + * Each item in the array is an object with the following: + * - role (string) Required + * The role of the author of this message. + * One of system, user, or assistant. + * - content (string) Required + * The contents of the message. + * - name (string) Optional + * The name of the author of this message. + * May contain a-z, A-Z, 0-9, and underscores, + * with a maximum length of 64 characters. + * + * @param int|null $maxTokens Maximum number of tokens to generate (optional). + * @param float|null $temperature The sampling temperature to use (optional). + * @param float|null $topP The nucleus sampling parameter (optional). + * @param int|null $n The number of chat completion choices to generate (optional). + * @param bool|null $stream Partial message deltas (optional). + * @param mixed|null $stop Sequences where the API will stop generating tokens (optional). + * @param float|null $presencePenalty Penalty for new tokens based on whether they appear in the text (optional). + * @param float|null $frequencyPenalty Penalty for new tokens based on their frequency in the text (optional). + * @param array|null $logitBias Modify the likelihood of specified tokens appearing (optional). + * @param string|null $user A unique identifier representing the end-user (optional). + * + * @return object|null + * @since 3.2.0 + **/ + public function create( + string $model, + array $messages, + ?int $maxTokens = null, + ?float $temperature = null, + ?float $topP = null, + ?int $n = null, + ?bool $stream = null, + $stop = null, + ?float $presencePenalty = null, + ?float $frequencyPenalty = null, + ?array $logitBias = null, + ?string $user = null + ): ?object + { + // Build the request path. + $path = "/chat/completions"; + + // Set the request data. + $data = new \stdClass(); + $data->model = $model; + $data->messages = $messages; + + if ($maxTokens !== null) + { + $data->max_tokens = $maxTokens; + } + + if ($temperature !== null) + { + $data->temperature = $temperature; + } + + if ($topP !== null) + { + $data->top_p = $topP; + } + + if ($n !== null) + { + $data->n = $n; + } + + if ($stream !== null) + { + $data->stream = $stream; + } + + if ($stop !== null) + { + $data->stop = $stop; + } + + if ($presencePenalty !== null) + { + $data->presence_penalty = $presencePenalty; + } + + if ($frequencyPenalty !== null) + { + $data->frequency_penalty = $frequencyPenalty; + } + + if ($logitBias !== null) + { + $data->logit_bias = new \stdClass(); + foreach ($logitBias as $key => $val) + { + $data->logit_bias->$key = $val; + } + } + + if ($user !== null) + { + $data->user = $user; + } + + // Send the post request. + return $this->response->get( + $this->http->post( + $this->uri->get($path), json_encode($data) + ) + ); + } +} + diff --git a/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/code.power b/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/code.power index 69309b0..15fcd5f 100644 --- a/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/code.power +++ b/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/code.power @@ -1 +1,116 @@ -###CODEPOWER### \ No newline at end of file + /** + * Create a chat completion with the OpenAI API. + * API Ref: https://platform.openai.com/docs/api-reference/chat/create + * + * @param string $model The model to use for completion. + * @param array $messages A list of messages describing the conversation so far. + * + * Each item in the array is an object with the following: + * - role (string) Required + * The role of the author of this message. + * One of system, user, or assistant. + * - content (string) Required + * The contents of the message. + * - name (string) Optional + * The name of the author of this message. + * May contain a-z, A-Z, 0-9, and underscores, + * with a maximum length of 64 characters. + * + * @param int|null $maxTokens Maximum number of tokens to generate (optional). + * @param float|null $temperature The sampling temperature to use (optional). + * @param float|null $topP The nucleus sampling parameter (optional). + * @param int|null $n The number of chat completion choices to generate (optional). + * @param bool|null $stream Partial message deltas (optional). + * @param mixed|null $stop Sequences where the API will stop generating tokens (optional). + * @param float|null $presencePenalty Penalty for new tokens based on whether they appear in the text (optional). + * @param float|null $frequencyPenalty Penalty for new tokens based on their frequency in the text (optional). + * @param array|null $logitBias Modify the likelihood of specified tokens appearing (optional). + * @param string|null $user A unique identifier representing the end-user (optional). + * + * @return object|null + * @since 3.2.0 + **/ + public function create( + string $model, + array $messages, + ?int $maxTokens = null, + ?float $temperature = null, + ?float $topP = null, + ?int $n = null, + ?bool $stream = null, + $stop = null, + ?float $presencePenalty = null, + ?float $frequencyPenalty = null, + ?array $logitBias = null, + ?string $user = null + ): ?object + { + // Build the request path. + $path = "/chat/completions"; + + // Set the request data. + $data = new \stdClass(); + $data->model = $model; + $data->messages = $messages; + + if ($maxTokens !== null) + { + $data->max_tokens = $maxTokens; + } + + if ($temperature !== null) + { + $data->temperature = $temperature; + } + + if ($topP !== null) + { + $data->top_p = $topP; + } + + if ($n !== null) + { + $data->n = $n; + } + + if ($stream !== null) + { + $data->stream = $stream; + } + + if ($stop !== null) + { + $data->stop = $stop; + } + + if ($presencePenalty !== null) + { + $data->presence_penalty = $presencePenalty; + } + + if ($frequencyPenalty !== null) + { + $data->frequency_penalty = $frequencyPenalty; + } + + if ($logitBias !== null) + { + $data->logit_bias = new \stdClass(); + foreach ($logitBias as $key => $val) + { + $data->logit_bias->$key = $val; + } + } + + if ($user !== null) + { + $data->user = $user; + } + + // Send the post request. + return $this->response->get( + $this->http->post( + $this->uri->get($path), json_encode($data) + ) + ); + } \ No newline at end of file diff --git a/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/settings.json b/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/settings.json index 6b3b222..456d89b 100644 --- a/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/settings.json +++ b/src/c54c92da-2dd7-4136-81c9-1785f2fa0af5/settings.json @@ -1 +1,18 @@ -###POWERLINKER### \ No newline at end of file +{ + "add_head": "0", + "add_licensing_template": "2", + "extends": "585de711-2784-4f89-90bf-94a8a63366f1", + "guid": "c54c92da-2dd7-4136-81c9-1785f2fa0af5", + "implements": null, + "load_selection": null, + "name": "Chat", + "power_version": "1.0.0", + "system_name": "Joomla.Openai.Chat", + "type": "class", + "use_selection": null, + "namespace": "VDM\\Joomla\\Openai\\Chat", + "description": "The Openai Chat\r\n\r\n@since 3.2.0", + "licensing_template": "\/**\r\n * @package Joomla.Component.Builder\r\n *\r\n * @created 4th September, 2022\r\n * @author Llewellyn van der Merwe \r\n * @git Joomla Component Builder \r\n * @copyright Copyright (C) 2015 Vast Development Method. All rights reserved.\r\n * @license GNU General Public License version 2 or later; see LICENSE.txt\r\n *\/\r\n", + "head": "", + "composer": "" +} \ No newline at end of file diff --git a/super-powers.json b/super-powers.json index 18f683b..7c908d0 100644 --- a/super-powers.json +++ b/super-powers.json @@ -1 +1,101 @@ -###POWERINDEX### \ No newline at end of file +{ + "07858e1f-5698-4227-8941-03dc93557938": { + "name": "Utilities", + "type": "class", + "namespace": "VDM\\Joomla\\Openai\\Service", + "code": "src\/07858e1f-5698-4227-8941-03dc93557938\/code.php", + "power": "src\/07858e1f-5698-4227-8941-03dc93557938\/code.power", + "settings": "src\/07858e1f-5698-4227-8941-03dc93557938\/settings.json", + "path": "src\/07858e1f-5698-4227-8941-03dc93557938", + "spk": "Super__07858e1f_5698_4227_8941_03dc93557938__Power", + "guid": "07858e1f-5698-4227-8941-03dc93557938" + }, + "08abd2df-1406-4939-a1a6-94d2fce3f043": { + "name": "Models", + "type": "class", + "namespace": "VDM\\Joomla\\Openai", + "code": "src\/08abd2df-1406-4939-a1a6-94d2fce3f043\/code.php", + "power": "src\/08abd2df-1406-4939-a1a6-94d2fce3f043\/code.power", + "settings": "src\/08abd2df-1406-4939-a1a6-94d2fce3f043\/settings.json", + "path": "src\/08abd2df-1406-4939-a1a6-94d2fce3f043", + "spk": "Super__08abd2df_1406_4939_a1a6_94d2fce3f043__Power", + "guid": "08abd2df-1406-4939-a1a6-94d2fce3f043" + }, + "13ef84f4-25b0-43dd-a9f6-0722abf220c1": { + "name": "Uri", + "type": "final class", + "namespace": "VDM\\Joomla\\Openai\\Utilities", + "code": "src\/13ef84f4-25b0-43dd-a9f6-0722abf220c1\/code.php", + "power": "src\/13ef84f4-25b0-43dd-a9f6-0722abf220c1\/code.power", + "settings": "src\/13ef84f4-25b0-43dd-a9f6-0722abf220c1\/settings.json", + "path": "src\/13ef84f4-25b0-43dd-a9f6-0722abf220c1", + "spk": "Super__13ef84f4_25b0_43dd_a9f6_0722abf220c1__Power", + "guid": "13ef84f4-25b0-43dd-a9f6-0722abf220c1" + }, + "34f2c249-64a7-4229-9592-77e58f6e994f": { + "name": "Moderate", + "type": "class", + "namespace": "VDM\\Joomla\\Openai", + "code": "src\/34f2c249-64a7-4229-9592-77e58f6e994f\/code.php", + "power": "src\/34f2c249-64a7-4229-9592-77e58f6e994f\/code.power", + "settings": "src\/34f2c249-64a7-4229-9592-77e58f6e994f\/settings.json", + "path": "src\/34f2c249-64a7-4229-9592-77e58f6e994f", + "spk": "Super__34f2c249_64a7_4229_9592_77e58f6e994f__Power", + "guid": "34f2c249-64a7-4229-9592-77e58f6e994f" + }, + "4c58b254-aea5-40aa-b54d-9586a1690451": { + "name": "Http", + "type": "final class", + "namespace": "VDM\\Joomla\\Openai\\Utilities", + "code": "src\/4c58b254-aea5-40aa-b54d-9586a1690451\/code.php", + "power": "src\/4c58b254-aea5-40aa-b54d-9586a1690451\/code.power", + "settings": "src\/4c58b254-aea5-40aa-b54d-9586a1690451\/settings.json", + "path": "src\/4c58b254-aea5-40aa-b54d-9586a1690451", + "spk": "Super__4c58b254_aea5_40aa_b54d_9586a1690451__Power", + "guid": "4c58b254-aea5-40aa-b54d-9586a1690451" + }, + "585de711-2784-4f89-90bf-94a8a63366f1": { + "name": "Api", + "type": "abstract class", + "namespace": "VDM\\Joomla\\Openai\\Abstraction", + "code": "src\/585de711-2784-4f89-90bf-94a8a63366f1\/code.php", + "power": "src\/585de711-2784-4f89-90bf-94a8a63366f1\/code.power", + "settings": "src\/585de711-2784-4f89-90bf-94a8a63366f1\/settings.json", + "path": "src\/585de711-2784-4f89-90bf-94a8a63366f1", + "spk": "Super__585de711_2784_4f89_90bf_94a8a63366f1__Power", + "guid": "585de711-2784-4f89-90bf-94a8a63366f1" + }, + "796cca70-2577-4f8f-9a05-ac37db1f2f02": { + "name": "Completions", + "type": "class", + "namespace": "VDM\\Joomla\\Openai", + "code": "src\/796cca70-2577-4f8f-9a05-ac37db1f2f02\/code.php", + "power": "src\/796cca70-2577-4f8f-9a05-ac37db1f2f02\/code.power", + "settings": "src\/796cca70-2577-4f8f-9a05-ac37db1f2f02\/settings.json", + "path": "src\/796cca70-2577-4f8f-9a05-ac37db1f2f02", + "spk": "Super__796cca70_2577_4f8f_9a05_ac37db1f2f02__Power", + "guid": "796cca70-2577-4f8f-9a05-ac37db1f2f02" + }, + "c464393e-7606-406e-8463-a86774590966": { + "name": "Response", + "type": "final class", + "namespace": "VDM\\Joomla\\Openai\\Utilities", + "code": "src\/c464393e-7606-406e-8463-a86774590966\/code.php", + "power": "src\/c464393e-7606-406e-8463-a86774590966\/code.power", + "settings": "src\/c464393e-7606-406e-8463-a86774590966\/settings.json", + "path": "src\/c464393e-7606-406e-8463-a86774590966", + "spk": "Super__c464393e_7606_406e_8463_a86774590966__Power", + "guid": "c464393e-7606-406e-8463-a86774590966" + }, + "c54c92da-2dd7-4136-81c9-1785f2fa0af5": { + "name": "Chat", + "type": "class", + "namespace": "VDM\\Joomla\\Openai", + "code": "src\/c54c92da-2dd7-4136-81c9-1785f2fa0af5\/code.php", + "power": "src\/c54c92da-2dd7-4136-81c9-1785f2fa0af5\/code.power", + "settings": "src\/c54c92da-2dd7-4136-81c9-1785f2fa0af5\/settings.json", + "path": "src\/c54c92da-2dd7-4136-81c9-1785f2fa0af5", + "spk": "Super__c54c92da_2dd7_4136_81c9_1785f2fa0af5__Power", + "guid": "c54c92da-2dd7-4136-81c9-1785f2fa0af5" + } +} \ No newline at end of file