| 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_Core {
protected $core = null;
public $env = null;
public $envId = null;
public $envType = null;
public function __construct( $core, $env ) {
$this->core = $core;
$this->env = $env;
$this->envId = $env['id'];
$this->envType = $env['type'];
}
public function run( $query, $streamCallback = null ) {
// Check if the query is allowed.
$limits = $this->core->get_option( 'limits' );
$allowed = apply_filters( 'mwai_ai_allowed', true, $query, $limits );
if ( $allowed !== true ) {
$message = is_string( $allowed ) ? $allowed : 'Unauthorized query.';
throw new Exception( $message );
}
// Allow to modify the query before it is sent. It should not be a Meow_MWAI_Query_Embed.
if ( !( $query instanceof Meow_MWAI_Query_Embed ) ) {
$query = apply_filters( 'mwai_ai_query', $query );
}
// Important as it makes sure everything is consolidated in the query and the engine.
$this->final_checks( $query );
// Run the query
$reply = null;
if ( $query instanceof Meow_MWAI_Query_Text ) {
$reply = $this->run_completion_query( $query, $streamCallback );
}
else if ( $query instanceof Meow_MWAI_Query_Assistant ) {
$reply = null;
$reply = apply_filters( 'mwai_ai_query_assistant', $reply, $query );
if ( $reply === null ) {
throw new Exception( 'Assistants are not supported in this version of AI Engine.' );
}
}
else if ( $query instanceof Meow_MWAI_Query_Embed ) {
$reply = $this->run_embedding_query( $query );
}
else if ( $query instanceof Meow_MWAI_Query_Image ) {
$reply = $this->run_images_query( $query );
}
else if ( $query instanceof Meow_MWAI_Query_Transcribe ) {
$reply = $this->run_transcribe_query( $query );
}
else {
throw new Exception( 'Unknown query type.' );
}
// Allow to modify the reply before it is sent.
$reply = apply_filters( 'mwai_ai_reply', $reply, $query );
return $reply;
}
public function retrieve_model_info( $model ) {
$models = $this->get_models();
foreach ( $models as $currentModel ) {
if ( $currentModel['model'] === $model ) {
return $currentModel;
}
}
return false;
}
public function final_checks( Meow_MWAI_Query_Base $query ) {
$query->final_checks();
//$found = false;
// Check if the model is available, except if it's an assistant
if ( !( $query instanceof Meow_MWAI_Query_Assistant ) ) {
// TODO: Avoid checking on the finetuned models for now.
if ( substr( $query->model, 0, 3 ) === 'ft:' ) {
return;
}
$model_info = $this->retrieve_model_info( $query->model );
if ( $model_info === false ) {
throw new Exception( "AI Engine: The model '{$query->model}' is not available." );
}
if ( isset( $model_info['mode'] ) ) {
$query->mode = $model_info['mode'];
}
// TODO: I am not sure this is actually useful, and it breaks the mechanics of picking a model.
// if ( !$found && ( $query instanceof Meow_MWAI_Query_Embed ) ) {
// $ai_embeddings_default_env = $this->core->get_option( 'ai_embeddings_default_env' );
// $ai_embeddings_default_model = $this->core->get_option( 'ai_embeddings_default_model' );
// if ( empty( $ai_embeddings_default_env ) || empty( $ai_embeddings_default_model ) ) {
// throw new Exception( 'AI Engine: The default environment and model for embeddings are not set.' );
// }
// $query->set_env_id( $ai_embeddings_default_env );
// $query->set_model( $ai_embeddings_default_model );
// $found = true;
// }
}
}
public function get_models() {
throw new Exception( 'Not implemented.' );
}
public function retrieve_models() {
throw new Exception( 'Not implemented.' );
}
public function run_completion_query( Meow_MWAI_Query_Base $query, $streamCallback = null ) : Meow_MWAI_Reply {
throw new Exception( 'Not implemented.' );
}
public function run_embedding_query( Meow_MWAI_Query_Base $query ) {
throw new Exception( 'Not implemented.' );
}
public function run_images_query( Meow_MWAI_Query_Base $query ) {
throw new Exception( 'Not implemented.' );
}
public function run_transcribe_query( Meow_MWAI_Query_Base $query ) {
throw new Exception( 'Not implemented.' );
}
public function get_price( Meow_MWAI_Query_Base $query, Meow_MWAI_Reply $reply ) {
throw new Exception( 'Not implemented.' );
}
}