1<?php 2 3namespace dokuwiki\plugin\aichat\Model; 4 5abstract class AbstractModel 6{ 7 /** @var int total tokens used by this instance */ 8 protected $tokensUsed = 0; 9 /** @var int total cost used by this instance (multiplied by 1000*10000) */ 10 protected $costEstimate = 0; 11 /** @var int total time spent in requests by this instance */ 12 protected $timeUsed = 0; 13 /** @var int total number of requests made by this instance */ 14 protected $requestsMade = 0; 15 16 /** 17 * @param array $authConfig Any configuration this Model/Service may need to authenticate 18 */ 19 abstract public function __construct($authConfig); 20 21 /** 22 * The name as used by the LLM provider 23 * 24 * @return string 25 */ 26 abstract public function getModelName(); 27 28 /** 29 * Get the price for 1000 tokens 30 * 31 * @return float 32 */ 33 abstract public function get1kTokenPrice(); 34 35 /** 36 * Reset the usage statistics 37 * 38 * Usually not needed when only handling one operation per request, but useful in CLI 39 */ 40 public function resetUsageStats() 41 { 42 $this->tokensUsed = 0; 43 $this->costEstimate = 0; 44 $this->timeUsed = 0; 45 $this->requestsMade = 0; 46 } 47 48 /** 49 * Get the usage statistics for this instance 50 * 51 * @return string[] 52 */ 53 public function getUsageStats() 54 { 55 return [ 56 'tokens' => $this->tokensUsed, 57 'cost' => round($this->costEstimate / 1000 / 10000, 4), 58 'time' => round($this->timeUsed, 2), 59 'requests' => $this->requestsMade, 60 ]; 61 } 62} 63