Lines Matching refs:this

53         $this->modelName = $name;
54 $this->http = new DokuHTTPClient();
55 $this->http->timeout = 60;
56 $this->http->headers['Content-Type'] = 'application/json';
57 $this->http->headers['Accept'] = 'application/json';
59 $reflect = new \ReflectionClass($this);
70 $this->modelFullName = basename(dirname($reflect->getFileName()) . ' ' . $name);
72 if ($this instanceof ChatInterface) {
76 $this->modelInfo = $modelinfos['chat'][$name];
79 if ($this instanceof EmbeddingInterface) {
83 $this->modelInfo = $modelinfos['embedding'][$name];
90 return $this->modelFullName;
97 return $this->modelName;
107 $this->inputTokensUsed = 0;
108 $this->outputTokensUsed = 0;
109 $this->timeUsed = 0;
110 $this->requestsMade = 0;
114 * Get the usage statistics for this instance
122 $cost += $this->inputTokensUsed * $this->getInputTokenPrice();
123 if ($this instanceof ChatInterface) {
124 $cost += $this->outputTokensUsed * $this->getOutputTokenPrice();
128 'tokens' => $this->inputTokensUsed + $this->outputTokensUsed,
130 'time' => round($this->timeUsed, 2),
131 'requests' => $this->requestsMade,
138 return $this->modelInfo['inputTokens'];
144 return $this->modelInfo['inputTokenPrice'];
154 return $this->modelInfo['dimensions'];
163 return $this->modelInfo['outputTokens'];
168 return $this->modelInfo['outputTokenPrice'];
182 $this->debug = $debug;
187 * this method should throw an Exception with a meaningful error message.
189 * If the response returned any info on used tokens, they should be added to $this->tokensUsed
202 * Model classes should use this method to send requests to the API.
211 * @param int $retry How often this request has been retried, do not set externally
219 $this->requestStart = microtime(true);
223 $this->requestsMade++;
229 $this->timeUsed += $this->requestStart - microtime(true);
233 if ($this->debug) {
240 $this->http->sendRequest($url, $json, $method);
241 $response = $this->http->resp_body;
242 if ($response === false || $this->http->error) {
244 return $this->sendAPIRequest($method, $url, $data, $retry + 1);
246 $this->timeUsed += microtime(true) - $this->requestStart;
247 throw new \Exception('API returned no response. ' . $this->http->error);
250 if ($this->debug) {
260 $this->timeUsed += microtime(true) - $this->requestStart;
266 $result = $this->parseAPIResponse($result);
269 return $this->sendAPIRequest($method, $url, $data, $retry + 1);
271 $this->timeUsed += microtime(true) - $this->requestStart;
275 $this->timeUsed += microtime(true) - $this->requestStart;