2 min read 2 days ago

PHP Classes

Meow_MWAI_Query_Text

You will find this usually named as $query and this class is used mainly for completion and chat. Here is an example on how to use it manually:

global $mwai_core;
$query = new Meow_MWAI_Query_Text( "Translate 'Hello World' into French." );
$query->set_env_id( '56xcfha6' ); // You can find this ID in your "Environments for AI"
$query->set_model( 'gpt-4-turbo' ); // Make sure this model is available in the set environment.
$reply = $mwai_core->run_query( $query );
echo $reply->result;

There are the main functions:

  • $query->set_message( $message ): Set the message (known previously as prompt).
  • $query->get_message( $message ): Get the message.
  • $query->set_messages( $messages ): Set the former messages.
  • $query->set_instructions( $instructions ): Set or override the instructions (known previously as context).
  • $query->set_env_id( $envId ): Set the environment ID. You can find it under “Environments for AI” in the AI Engine dashboard.
  • $query->set_model( $model ): Set the model.
  • $query->set_temperature( $temperature ): Set the temperature (0.8 by default).
  • $query->set_max_tokens( $maxTokens ): Set the max tokens (1024 by default).
  • $query->set_max_results( $maxResults ): Specific the number of results (1 by default).
  • $query->set_context( $context ): Add an additional context.
  • $query->replace( $search, $replace ): Replace a string by another string in the message.
  • $query->set_api_key( $apiKey ): Set it if you would like to override the API Key for this query.

Meow_MWAI_Reply

You will find it usually named as $reply. Here are the main functions:

  • $reply->result: Return simply the first (or only) result.
  • $reply->results: Return an array with all the results.
  • $reply->replace( $search, $replace ): Replace a string by another string.
  • $reply->get_in_tokens( $query = null )
  • $reply->get_out_tokens( $query = null )