modules
3 years ago
admin.php
3 years ago
ai.php
3 years ago
answer.php
3 years ago
api.php
3 years ago
core.php
3 years ago
init.php
3 years ago
openai.php
3 years ago
query.php
3 years ago
queryembed.php
3 years ago
queryimage.php
3 years ago
querytext.php
3 years ago
querytranscribe.php
3 years ago
rest.php
3 years ago
security.php
3 years ago
query.php
133 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Query { |
| 4 | public $env = ''; |
| 5 | public $prompt = ''; |
| 6 | public $model = ''; |
| 7 | public $mode = ''; |
| 8 | public $session = null; |
| 9 | public $maxResults = 1; |
| 10 | |
| 11 | // OpenAI |
| 12 | public $apiKey = null; |
| 13 | public $service = null; |
| 14 | public $azureEndpoint = null; |
| 15 | public $azureApiKey = null; |
| 16 | public $azureDeployment = null; |
| 17 | |
| 18 | public function __construct( $prompt = '' ) { |
| 19 | global $mwai_core; |
| 20 | $this->setPrompt( $prompt ); |
| 21 | $this->session = $mwai_core->get_session_id(); |
| 22 | } |
| 23 | |
| 24 | public function replace( $search, $replace ) { |
| 25 | $this->prompt = str_replace( $search, $replace, $this->prompt ); |
| 26 | } |
| 27 | |
| 28 | public function getLastPrompt() { |
| 29 | return $this->prompt; |
| 30 | } |
| 31 | |
| 32 | /** |
| 33 | * The environment, like "chatbot", "imagesbot", "chatbot-007", "textwriter", etc... |
| 34 | * Used for statistics, mainly. |
| 35 | * @param string $env The environment. |
| 36 | */ |
| 37 | public function setEnv( $env ) { |
| 38 | $this->env = $env; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * ID of the model to use. |
| 43 | * @param string $model ID of the model to use. |
| 44 | */ |
| 45 | public function setModel( $model ) { |
| 46 | $this->model = $model; |
| 47 | } |
| 48 | |
| 49 | /** |
| 50 | * The mode |
| 51 | * @param string $mode. |
| 52 | */ |
| 53 | public function setMode( $mode ) { |
| 54 | $this->mode = $mode; |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Given a prompt, the model will return one or more predicted completions. |
| 59 | * It can also return the probabilities of alternative tokens at each position. |
| 60 | * @param string $prompt The prompt to generate completions. |
| 61 | */ |
| 62 | public function setPrompt( $prompt ) { |
| 63 | $this->prompt = $prompt; |
| 64 | } |
| 65 | |
| 66 | public function getPrompt() { |
| 67 | return $this->prompt; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * The API key to use. |
| 72 | * @param string $apiKey The API key. |
| 73 | */ |
| 74 | public function setApiKey( $apiKey ) { |
| 75 | $this->apiKey = $apiKey; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * The service to use. |
| 80 | * @param string $service The service. |
| 81 | */ |
| 82 | public function setService( $service ) { |
| 83 | $this->service = $service; |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * The Azure endpoint to use. |
| 88 | * @param string $endpoint The endpoint. |
| 89 | */ |
| 90 | public function setAzureEndpoint( $endpoint ) { |
| 91 | $this->azureEndpoint = $endpoint; |
| 92 | } |
| 93 | |
| 94 | /** |
| 95 | * The Azure API key to use. |
| 96 | * @param string $apiKey The API key. |
| 97 | */ |
| 98 | public function setAzureApiKey( $apiKey ) { |
| 99 | $this->azureApiKey = $apiKey; |
| 100 | } |
| 101 | |
| 102 | /** |
| 103 | * The Azure deployment to use. |
| 104 | * @param string $deployment The deployment. |
| 105 | */ |
| 106 | public function setAzureDeployment( $deployment ) { |
| 107 | $this->azureDeployment = $deployment; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * The session ID to use. |
| 112 | * @param string $session The session ID. |
| 113 | */ |
| 114 | public function setSession( $session ) { |
| 115 | $this->session = $session; |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * How many completions to generate for each prompt. |
| 120 | * Because this parameter generates many completions, it can quickly consume your token quota. |
| 121 | * Use carefully and ensure that you have reasonable settings for max_tokens and stop. |
| 122 | * @param float $maxResults Number of completions. |
| 123 | */ |
| 124 | public function setMaxResults( $maxResults ) { |
| 125 | $this->maxResults = intval( $maxResults ); |
| 126 | } |
| 127 | |
| 128 | // ** |
| 129 | // * Check if everything is correct, otherwise fix it (like the max number of tokens). |
| 130 | // */ |
| 131 | public function checkFix() { |
| 132 | } |
| 133 | } |