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
answer.php
46 lines
| 1 | <?php |
| 2 | |
| 3 | class Meow_MWAI_Answer { |
| 4 | |
| 5 | public $result = ''; |
| 6 | public $results = []; |
| 7 | public $usage = [ 'prompt_tokens' => 0, 'completion_tokens' => 0, 'total_tokens' => 0 ]; |
| 8 | public $query = null; |
| 9 | |
| 10 | public function __construct( $query = null ) { |
| 11 | $this->query = $query; |
| 12 | } |
| 13 | |
| 14 | public function setQuery( $query ) { |
| 15 | $this->query = $query; |
| 16 | } |
| 17 | |
| 18 | public function setUsage( $usage ) { |
| 19 | $this->usage = $usage; |
| 20 | } |
| 21 | |
| 22 | public function getTotalTokens() { |
| 23 | return $this->usage['total_tokens']; |
| 24 | } |
| 25 | |
| 26 | /** |
| 27 | * Set the choices from OpenAI as the results. |
| 28 | * The last (or only) result is set as the result. |
| 29 | * @param array $choices ID of the model to use. |
| 30 | */ |
| 31 | public function setChoices( $choices ) { |
| 32 | $this->results = []; |
| 33 | foreach ( $choices as $choice ) { |
| 34 | if ( isset( $choice['text'] ) ) { |
| 35 | $text = trim( $choice['text'] ); |
| 36 | $this->results[] = $text; |
| 37 | $this->result = $text; |
| 38 | } |
| 39 | if ( isset( $choice['url'] ) ) { |
| 40 | $url = trim( $choice['url'] ); |
| 41 | $this->results[] = $url; |
| 42 | $this->result = $url; |
| 43 | } |
| 44 | } |
| 45 | } |
| 46 | } |