admin.php
3 years ago
ai.php
3 years ago
answer.php
3 years ago
core.php
3 years ago
init.php
3 years ago
query.php
3 years ago
rest.php
3 years ago
shortcodes.php
3 years ago
ui.php
3 years ago
query.php
94 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Query { |
| 4 | |
| 5 | public $model = 'text-davinci-003'; |
| 6 | public $type = 'completion'; |
| 7 | |
| 8 | public $prompt = ''; |
| 9 | |
| 10 | public $maxTokens = 16; |
| 11 | public $temperature = 1; |
| 12 | public $maxResults = 1; |
| 13 | public $stop = null; |
| 14 | public $apiKey = null; |
| 15 | |
| 16 | public function __construct( $prompt = '', $maxTokens = 16, $model = 'text-davinci-003' ) { |
| 17 | $this->prompt = $prompt; |
| 18 | $this->maxTokens = $maxTokens; |
| 19 | $this->model = $model; |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * ID of the model to use. |
| 24 | * @param string $model ID of the model to use. |
| 25 | */ |
| 26 | public function setModel( $model ) { |
| 27 | $this->model = $model; |
| 28 | if ( $model !== 'text-davinci-003' && $this->maxTokens > 512 ) { |
| 29 | $this->maxTokens = 512; |
| 30 | } |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Given a prompt, the model will return one or more predicted completions. |
| 35 | * It can also return the probabilities of alternative tokens at each position. |
| 36 | * @param string $prompt The prompt to generate completions. |
| 37 | */ |
| 38 | public function setPrompt( $prompt ) { |
| 39 | $this->prompt = $prompt; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * The maximum number of tokens to generate in the completion. |
| 44 | * The token count of your prompt plus max_tokens cannot exceed the model's context length. |
| 45 | * Most models have a context length of 2048 tokens (except for the newest models, which support 4096). |
| 46 | * @param float $prompt The maximum number of tokens. |
| 47 | */ |
| 48 | public function setMaxTokens( $maxTokens ) { |
| 49 | $this->maxTokens = $maxTokens; |
| 50 | } |
| 51 | |
| 52 | /** |
| 53 | * Set the sampling temperature to use. Higher values means the model will take more risks. |
| 54 | * Try 0.9 for more creative applications, and 0 for ones with a well-defined answer. |
| 55 | * @param float $temperature The temperature. |
| 56 | */ |
| 57 | public function setTemperature( $temperature ) { |
| 58 | $temperature = floatval( $temperature ); |
| 59 | if ( $temperature > 1 ) { |
| 60 | $temperature = 1; |
| 61 | } |
| 62 | if ( $temperature < 0 ) { |
| 63 | $temperature = 0; |
| 64 | } |
| 65 | $this->temperature = $temperature; |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * How many completions to generate for each prompt. |
| 70 | * Because this parameter generates many completions, it can quickly consume your token quota. |
| 71 | * Use carefully and ensure that you have reasonable settings for max_tokens and stop. |
| 72 | * @param float $maxResults Number of completions. |
| 73 | */ |
| 74 | public function setMaxResults( $maxResults ) { |
| 75 | $this->maxResults = $maxResults; |
| 76 | } |
| 77 | |
| 78 | /** |
| 79 | * Up to 4 sequences where the API will stop generating further tokens. |
| 80 | * The returned text will not contain the stop sequence. |
| 81 | * @param float $stop The stop. |
| 82 | */ |
| 83 | public function setStop( $stop ) { |
| 84 | $this->stop = $stop; |
| 85 | } |
| 86 | |
| 87 | /** |
| 88 | * The API key to use. |
| 89 | * @param string $apiKey The API key. |
| 90 | */ |
| 91 | public function setApiKey( $apiKey ) { |
| 92 | $this->apiKey = $apiKey; |
| 93 | } |
| 94 | } |