| Server IP : 216.106.184.20 / Your IP : 216.73.216.234 Web Server : LiteSpeed System : Linux asmodeus.in-hell.com 5.14.0-570.58.1.el9_6.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Oct 29 06:24:11 EDT 2025 x86_64 User : sekoaid1 ( 1891) PHP Version : 7.3.33 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : OFF | Pkexec : OFF Directory : /home/sekoaid1/public_html/wp-content/plugins/ai-engine/classes/engines/ |
Upload File : |
<?php
class Meow_MWAI_Engines_Factory {
private static function get_default_env_id( $core ) : ?string {
return $core->get_option( 'ai_default_env' );
}
private static function get_default_model( $core ) : ?string {
return $core->get_option( 'ai_default_model' );
}
private static function get_env_from_id( $core, $envId ) : ?array {
$envs = $core->get_option( 'ai_envs' );
foreach ( $envs as $env ) {
if ( $env['id'] === $envId ) {
return $env;
}
}
throw new Exception( "AI Engine: No environment found for ID ($envId)." );
}
private static function get_env_from_type( $core, $type, $envId ) : ?array {
$type = is_array( $type ) ? $type : [ $type ];
// Try first to find the env with the ID provided.
if ( !empty( $envId ) ) {
$env = self::get_env_from_id( $core, $envId );
if ( in_array( $env['type'], $type ) ) {
return $env;
}
else {
throw new Exception( "AI Engine: Environment ID ($envId) is not of type ($type)." );
}
}
// If not, we will try to find the default one.
$envId = self::get_default_env_id( $core );
$env = self::get_env_from_id( $core, $envId );
if ( in_array( $env['type'], $type ) ) {
return $env;
}
// If not, we will try to find the first one.
$envs = $core->get_option( 'ai_envs' );
foreach ( $envs as $env ) {
if ( in_array( $env['type'], $type ) ) {
return $env;
}
}
throw new Exception( "AI Engine: No environment found for type ($type)." );
}
public static function get( $core, $envId = null ) : ?Meow_MWAI_Engines_Core {
// If no envId is provided, we will use the default one as well as the default model.
$model = null;
if ( empty( $envId ) ) {
$envId = self::get_default_env_id( $core );
//$model = self::get_default_model( $core );
}
$env = self::get_env_from_id( $core, $envId );
if ( $env['type'] === 'openai' || $env['type'] === 'azure' ) {
$engine = new Meow_MWAI_Engines_OpenAI( $core, $env );
return $engine;
}
else if ( $env['type'] === 'openrouter' ) {
$engine = new Meow_MWAI_Engines_OpenRouter( $core, $env );
return $engine;
}
throw new Exception( "AI Engine: Unknown engine type ({$env['type']})." );
}
public static function get_openai( $core, $envId = null ) : Meow_MWAI_Engines_OpenAI {
$env = self::get_env_from_type( $core, [ 'openai', 'azure '], $envId );
$engine = new Meow_MWAI_Engines_OpenAI( $core, $env );
return $engine;
}
}