modules
3 years ago
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
queryimage.php
3 years ago
querytext.php
3 years ago
rest.php
3 years ago
ui.php
3 years ago
querytext.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_QueryText extends Meow_MWAI_Query { |
| 4 | |
| 5 | public $model = 'text-davinci-003'; |
| 6 | public $type = 'completion'; |
| 7 | |
| 8 | public $maxTokens = 16; |
| 9 | public $temperature = 1; |
| 10 | public $stop = null; |
| 11 | |
| 12 | public function __construct( $prompt = '', $maxTokens = 16, $model = 'text-davinci-003' ) { |
| 13 | $this->prompt = $prompt; |
| 14 | $this->maxTokens = $maxTokens; |
| 15 | $this->model = $model; |
| 16 | } |
| 17 | |
| 18 | /** |
| 19 | * ID of the model to use. |
| 20 | * @param string $model ID of the model to use. |
| 21 | */ |
| 22 | public function setModel( $model ) { |
| 23 | $this->model = $model; |
| 24 | if ( $model !== 'text-davinci-003' && $this->maxTokens > 512 ) { |
| 25 | $this->maxTokens = 512; |
| 26 | } |
| 27 | } |
| 28 | |
| 29 | /** |
| 30 | * The maximum number of tokens to generate in the completion. |
| 31 | * The token count of your prompt plus max_tokens cannot exceed the model's context length. |
| 32 | * Most models have a context length of 2048 tokens (except for the newest models, which support 4096). |
| 33 | * @param float $prompt The maximum number of tokens. |
| 34 | */ |
| 35 | public function setMaxTokens( $maxTokens ) { |
| 36 | $this->maxTokens = $maxTokens; |
| 37 | } |
| 38 | |
| 39 | /** |
| 40 | * Set the sampling temperature to use. Higher values means the model will take more risks. |
| 41 | * Try 0.9 for more creative applications, and 0 for ones with a well-defined answer. |
| 42 | * @param float $temperature The temperature. |
| 43 | */ |
| 44 | public function setTemperature( $temperature ) { |
| 45 | $temperature = floatval( $temperature ); |
| 46 | if ( $temperature > 1 ) { |
| 47 | $temperature = 1; |
| 48 | } |
| 49 | if ( $temperature < 0 ) { |
| 50 | $temperature = 0; |
| 51 | } |
| 52 | $this->temperature = $temperature; |
| 53 | } |
| 54 | |
| 55 | /** |
| 56 | * Up to 4 sequences where the API will stop generating further tokens. |
| 57 | * The returned text will not contain the stop sequence. |
| 58 | * @param float $stop The stop. |
| 59 | */ |
| 60 | public function setStop( $stop ) { |
| 61 | $this->stop = $stop; |
| 62 | } |
| 63 | } |