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