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