/** Datei: plugins/openai/library/ARUNOX/API/OpenAI/Responses.php **/ * @copyright 2023 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\OpenAI; use ARUNOX\API; class Responses { /* ### VARIABLES ################################################ # */ protected static $HEADER = [], $URL = "/responses"; /* ### PUBLIC FUNCTIONS ######################################### # */ public static function create( array $args ) { return API\OpenAI::post( static::$URL, $args, static::$HEADER ); } public static function get( string $response_id ) { return API\OpenAI::get( static::$URL . "/{$response_id}", [], static::$HEADER ); } public static function delete( string $response_id ) { return API\OpenAI::delete( static::$URL . "/{$response_id}", [], static::$HEADER ); } public static function items( string $response_id ) { return API\OpenAI::get( static::$URL . "/{$response_id}/input_items", [], static::$HEADER ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/openai/library/ARUNOX/API/OpenAI/OpenAI.php **/ * @copyright 2023 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API; use ARUNOX\API; class OpenAI extends API { /* ### VARIABLES ################################################ # */ protected static $CONTENTTYPE = "application/json", $ACCEPTTYPE = "application/json", $AUTHTYPE = "Bearer", $AUTHTOKEN = NULL, $APIURL = "https://api.openai.com/v1/"; /* ### PUBLIC FUNCTIONS ######################################### # */ public static function get( string $url, array | string $args = [], bool | string | array $headers = [] ) { return static::parseResponse( parent::get( $url, $args, $headers ) ); } public static function post( string $url, array | string $args = [], bool | string | array $headers = [] ) { return static::parseResponse( parent::post( $url, $args, $headers ) ); } public static function put( string $url, array | string $args = [], bool | string | array $headers = [] ) { return static::parseResponse( parent::put( $url, $args, $headers ) ); } public static function patch( string $url, array | string $args = [], bool | string | array $headers = [] ) { return static::parseResponse( parent::patch( $url, $args, $headers ) ); } public static function delete( string $url, array | string $args = [], bool | string | array $headers = [] ) { return static::parseResponse( parent::delete( $url, $args, $headers ) ); } /* ### PROTECTED FUNCTIONS ###################################### # */ protected static function parseResponse( $response ) { if( $response->error ?? FALSE ) { static::setError( $response->error ); return FALSE; } return $response->data ?? $response; } /* ### PRIVATE FUNCTIONS ######################################## # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/openai/library/ARUNOX/API/OpenAI/Threads/Runs.php **/ * @copyright 2023 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\OpenAI\Threads; use ARUNOX\API; class Runs { /* ### VARIABLES ################################################ # */ protected static $HEADER = [ "OpenAI-Beta" => "assistants=v2" ], $URL = "/threads"; /* ### PUBLIC FUNCTIONS ######################################### # */ public static function list( string $thread_id ) { return API\OpenAI::get( static::$URL . "/{$thread_id}/runs", [], static::$HEADER ); } public static function create( string $thread_id, array $args ) { return API\OpenAI::post( static::$URL . "/{$thread_id}/runs", $args, static::$HEADER ); } public static function get( string $thread_id, string $run_id ) { return API\OpenAI::get( static::$URL . "/{$thread_id}/runs/{$run_id}", [], static::$HEADER ); } public static function modify( string $thread_id, string $run_id, ?array $args = [] ) { return API\OpenAI::post( static::$URL . "/{$thread_id}/runs/{$run_id}", $args, static::$HEADER ); } public static function cancel( string $thread_id, string $run_id ) { return API\OpenAI::post( static::$URL . "/{$thread_id}/runs/{$run_id}/cancel", [], static::$HEADER ); } public static function cancelAll( string $thread_id ) { $response = static::list( $thread_id ); if( isset( $response->data ) ) { foreach( $response->data as &$item ) { if( $item->status == "requires_action" ) { $item = static::cancel( $thread_id, $item->id ); } } } return $response; } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/openai/library/ARUNOX/API/OpenAI/Threads/Outputs.php **/ * @copyright 2023 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\OpenAI\Threads; use ARUNOX\API; class Outputs { /* ### VARIABLES ################################################ # */ protected static $HEADER = [ "OpenAI-Beta" => "assistants=v2" ], $URL = "/threads"; /* ### PUBLIC FUNCTIONS ######################################### # */ public static function create( string $thread_id, string $run_id, ?array $args = [] ) { return API\OpenAI::post( static::$URL . "/{$thread_id}/runs/{$run_id}/submit_tool_outputs", [ "tool_outputs" => $args ], static::$HEADER ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/openai/library/ARUNOX/API/OpenAI/Threads/Messages.php **/ * @copyright 2023 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\OpenAI\Threads; use ARUNOX\API; class Messages { /* ### VARIABLES ################################################ # */ protected static $HEADER = [ "OpenAI-Beta" => "assistants=v2" ], $URL = "/threads"; /* ### PUBLIC FUNCTIONS ######################################### # */ public static function list( string $thread_id, array $args = [] ) { return API\OpenAI::get( static::$URL . "/{$thread_id}/messages", $args, static::$HEADER ); } public static function create( string $thread_id, array $args ) { return API\OpenAI::post( static::$URL . "/{$thread_id}/messages", $args, static::$HEADER ); } public static function get( string $thread_id, string $message_id ) { return API\OpenAI::get( static::$URL . "/{$thread_id}/messages/{$message_id}", [], static::$HEADER ); } public static function modify( string $thread_id, string $message_id, ?array $args = [] ) { return API\OpenAI::post( static::$URL . "/{$thread_id}/messages/{$message_id}", $args, static::$HEADER ); } public static function delete( string $thread_id, string $message_id ) { return API\OpenAI::delete( static::$URL . "/{$thread_id}/messages/{$message_id}", [], static::$HEADER ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/openai/library/ARUNOX/API/OpenAI/Threads/Threads.php **/ * @copyright 2023 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\OpenAI; use ARUNOX\API; class Threads { /* ### VARIABLES ################################################ # */ protected static $HEADER = [ "OpenAI-Beta" => "assistants=v2" ], $URL = "/threads"; /* ### PUBLIC FUNCTIONS ######################################### # */ public static function create( array $args ) { return API\OpenAI::post( static::$URL, $args, static::$HEADER ); } public static function get( string $thread_id ) { return API\OpenAI::get( static::$URL . "/{$thread_id}", [], static::$HEADER ); } public static function modify( string $thread_id, ?array $args = [] ) { return API\OpenAI::post( static::$URL . "/{$thread_id}", $args, static::$HEADER ); } public static function delete( string $thread_id ) { return API\OpenAI::delete( static::$URL . "/{$thread_id}", [], static::$HEADER ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/openai/library/ARUNOX/API/OpenAI/Assistants.php **/ * @copyright 2023 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\OpenAI; use ARUNOX\API; class Assistants { /* ### VARIABLES ################################################ # */ protected static $HEADER = [ "OpenAI-Beta" => "assistants=v2" ], $URL = "/assistants"; /* ### PUBLIC FUNCTIONS ######################################### # */ public static function list( ?array $args = [] ) { return API\OpenAI::get( static::$URL, $args, static::$HEADER ); } public static function create( array $args ) { return API\OpenAI::post( static::$URL, $args, static::$HEADER ); } public static function get( string $assistant_id ) { return API\OpenAI::get( static::$URL . "/{$assistant_id}", [], static::$HEADER ); } public static function modify( string $assistant_id, ?array $args = [] ) { return API\OpenAI::post( static::$URL . "/{$assistant_id}", $args, static::$HEADER ); } public static function delete( string $assistant_id ) { return API\OpenAI::delete( static::$URL . "/{$assistant_id}", [], static::$HEADER ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/openai/library/ARUNOX/API/OpenAI/Chat/Messages.php **/ * @copyright 2023 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\OpenAI\Chat; use ARUNOX\API; class Messages { /* ### VARIABLES ################################################ # */ protected static $HEADER = [], $URL = "/chat/completions"; /* ### PUBLIC FUNCTIONS ######################################### # */ public static function list( string $completion_id, array $args = [] ) { return API\OpenAI::get( static::$URL . "/{$completion_id}/messages", $args, static::$HEADER ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/openai/library/ARUNOX/API/OpenAI/Chat/Completions.php **/ * @copyright 2023 Sparky@ARUNOX * @version 1.0.0 * @since 1.0.0 File is created */ namespace ARUNOX\API\OpenAI\Chat; use ARUNOX\API; class Completions { /* ### VARIABLES ################################################ # */ protected static $HEADER = [], $URL = "/chat/completions"; /* ### PUBLIC FUNCTIONS ######################################### # */ public static function list( ?array $args = [] ) { return API\OpenAI::get( static::$URL, $args, static::$HEADER ); } public static function create( array $args ) { return API\OpenAI::post( static::$URL, $args, static::$HEADER ); } public static function get( string $completion_id ) { return API\OpenAI::get( static::$URL . "/{$completion_id}", [], static::$HEADER ); } public static function modify( string $completion_id, ?array $args = [] ) { return API\OpenAI::post( static::$URL . "/{$completion_id}", $args, static::$HEADER ); } public static function delete( string $completion_id ) { return API\OpenAI::delete( static::$URL . "/{$completion_id}", [], static::$HEADER ); } /* ### PROTECTED FUNCTIONS ###################################### # */ /* ### PRIVATE FUNCTIONS ######################################## # */ /* ### MAGIC FUNCTIONS ########################################## # */ } /** Datei: plugins/openai/library/ARUNOX/API/OpenAI/Messages/Role.php **/ [ "color" => REST\Generator\Config\Color::Secondary, "label" => "Assistant", "icon" => "bi bi-robot" ], self::Developer => [ "color" => REST\Generator\Config\Color::Warning, "label" => "Developer", "icon" => "bi bi-code-slash" ], self::System => [ "color" => REST\Generator\Config\Color::Danger, "label" => "System", "icon" => "bi bi-gear" ], self::Tool => [ "color" => REST\Generator\Config\Color::Info, "label" => "Tool", "icon" => "bi bi-wrench" ], self::User => [ "color" => REST\Generator\Config\Color::Primary, "label" => "User", "icon" => "bi bi-person" ], ]; /* ### PUBLIC FUNCTIONS ######################################### # */ /* ### MAGIC FUNCTIONS ########################################## # */ }