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
answer.php
37 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['prompt_tokens'] = $usage['prompt_tokens']; |
| 20 | $this->usage['completion_tokens'] = $usage['completion_tokens']; |
| 21 | $this->usage['total_tokens'] = $usage['total_tokens']; |
| 22 | } |
| 23 | |
| 24 | /** |
| 25 | * Set the choices from OpenAI as the results. |
| 26 | * The last (or only) result is set as the result. |
| 27 | * @param array $choices ID of the model to use. |
| 28 | */ |
| 29 | public function setChoices( $choices ) { |
| 30 | $this->results = []; |
| 31 | foreach ( $choices as $choice ) { |
| 32 | $text = trim( $choice['text'] ); |
| 33 | $this->results[] = $text; |
| 34 | $this->result = $text; |
| 35 | } |
| 36 | } |
| 37 | } |