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
79 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_QueryText extends Meow_MWAI_Query { |
| 4 | public $maxTokens = 16; |
| 5 | public $temperature = 0.8; |
| 6 | public $stop = null; |
| 7 | |
| 8 | public function __construct( $prompt = '', $maxTokens = 16, $model = 'text-davinci-003' ) { |
| 9 | $this->prompt = $prompt; |
| 10 | $this->maxTokens = $maxTokens; |
| 11 | $this->model = $model; |
| 12 | $this->mode = "completion"; |
| 13 | } |
| 14 | |
| 15 | /** |
| 16 | * The maximum number of tokens to generate in the completion. |
| 17 | * The token count of your prompt plus max_tokens cannot exceed the model's context length. |
| 18 | * Most models have a context length of 2048 tokens (except for the newest models, which support 4096). |
| 19 | * @param float $prompt The maximum number of tokens. |
| 20 | */ |
| 21 | public function setMaxTokens( $maxTokens ) { |
| 22 | $this->maxTokens = intval( $maxTokens ); |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Set the sampling temperature to use. Higher values means the model will take more risks. |
| 27 | * Try 0.9 for more creative applications, and 0 for ones with a well-defined answer. |
| 28 | * @param float $temperature The temperature. |
| 29 | */ |
| 30 | public function setTemperature( $temperature ) { |
| 31 | $temperature = floatval( $temperature ); |
| 32 | if ( $temperature > 1 ) { |
| 33 | $temperature = 1; |
| 34 | } |
| 35 | if ( $temperature < 0 ) { |
| 36 | $temperature = 0; |
| 37 | } |
| 38 | $this->temperature = $temperature; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Up to 4 sequences where the API will stop generating further tokens. |
| 43 | * The returned text will not contain the stop sequence. |
| 44 | * @param float $stop The stop. |
| 45 | */ |
| 46 | public function setStop( $stop ) { |
| 47 | if ( !empty( $stop ) ) { |
| 48 | $this->stop = $stop; |
| 49 | } |
| 50 | } |
| 51 | |
| 52 | // Based on the params of the query, update the attributes |
| 53 | public function injectParams( $params ) { |
| 54 | if ( isset( $params['model'] ) ) { |
| 55 | $this->setModel( $params['model'] ); |
| 56 | } |
| 57 | if ( isset( $params['maxTokens'] ) ) { |
| 58 | $this->setMaxTokens( $params['maxTokens'] ); |
| 59 | } |
| 60 | if ( isset( $params['temperature'] ) ) { |
| 61 | $this->setTemperature( $params['temperature'] ); |
| 62 | } |
| 63 | if ( isset( $params['stop'] ) ) { |
| 64 | $this->setStop( $params['stop'] ); |
| 65 | } |
| 66 | if ( isset( $params['apiKey'] ) ) { |
| 67 | $this->setApiKey( $params['apiKey'] ); |
| 68 | } |
| 69 | if ( isset( $params['maxResults'] ) ) { |
| 70 | $this->setMaxResults( $params['maxResults'] ); |
| 71 | } |
| 72 | if ( isset( $params['env'] ) ) { |
| 73 | $this->setEnv( $params['env'] ); |
| 74 | } |
| 75 | if ( isset( $params['session'] ) ) { |
| 76 | $this->setSession( $params['session'] ); |
| 77 | } |
| 78 | } |
| 79 | } |