From f34c6872f2d8bc261c8762f5065727e09cecd3e4 Mon Sep 17 00:00:00 2001 From: splitbrain <86426+splitbrain@users.noreply.github.com> Date: Mon, 22 Jul 2024 09:43:08 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=A4=96=20Automatic=20code=20style=20fixes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Embeddings.php | 3 --- Model/AbstractModel.php | 4 ++-- ModelFactory.php | 10 ++-------- cli/dev.php | 16 +++++++--------- cli/simulate.php | 3 --- helper.php | 2 -- 6 files changed, 11 insertions(+), 27 deletions(-) diff --git a/Embeddings.php b/Embeddings.php index 7656151..72812f3 100644 --- a/Embeddings.php +++ b/Embeddings.php @@ -51,9 +51,6 @@ class Embeddings /** * Embeddings constructor. * - * @param ChatInterface $chatModel - * @param EmbeddingInterface $embedModel - * @param AbstractStorage $storage * @param array $config The plugin configuration */ public function __construct( diff --git a/Model/AbstractModel.php b/Model/AbstractModel.php index 1ed4752..87dbe6a 100644 --- a/Model/AbstractModel.php +++ b/Model/AbstractModel.php @@ -38,7 +38,7 @@ abstract class AbstractModel implements ModelInterface protected $requestStart = 0; /** @var int How often to retry a request if it fails */ - public const MAX_RETRIES = 3; + final public const MAX_RETRIES = 3; /** @var DokuHTTPClient */ protected $http; @@ -194,7 +194,7 @@ public function setDebug($debug = true) * @return mixed * @throws \Exception when the response indicates an error */ - abstract protected function parseAPIResponse($response); + abstract protected function parseAPIResponse(mixed $response); /** * Send a request to the API diff --git a/ModelFactory.php b/ModelFactory.php index 41d0dc5..3ce76c0 100644 --- a/ModelFactory.php +++ b/ModelFactory.php @@ -7,9 +7,6 @@ class ModelFactory { - /** @var array The plugin configuration */ - protected array $config; - public $chatModel; public $rephraseModel; public $embeddingModel; @@ -19,9 +16,8 @@ class ModelFactory /** * @param array $config The plugin configuration */ - public function __construct(array $config) + public function __construct(protected array $config) { - $this->config = $config; } /** @@ -39,8 +35,6 @@ public function updateConfig(array $config) /** * Set the debug flag for all models - * - * @param bool $debug */ public function setDebug(bool $debug = true) { @@ -122,7 +116,7 @@ public function getModels($availableOnly = false, $typeOnly = '') try { $info['instance'] = $this->loadModel($type, "$namespace $name"); $info['instance']->setDebug($this->debug); - } catch (\Exception $e) { + } catch (\Exception) { if ($availableOnly) continue; $info['instance'] = false; } diff --git a/cli/dev.php b/cli/dev.php index 03565cb..6448b28 100644 --- a/cli/dev.php +++ b/cli/dev.php @@ -1,5 +1,6 @@ getCmd()) { - case 'update': $this->updateModelData(); break; @@ -37,7 +37,7 @@ protected function main(Options $options) protected function updateModelData() { - $http = new \dokuwiki\HTTP\DokuHTTPClient(); + $http = new DokuHTTPClient(); $url = 'https://raw.githubusercontent.com/BerriAI/litellm/main/model_prices_and_context_window.json'; $response = $http->get($url); if ($response === false) { @@ -84,7 +84,7 @@ protected function updateModelData() if (!isset($ourProviders[$data['litellm_provider']])) continue; if (!in_array($data['mode'], ['chat', 'embedding'])) continue; $provider = $data['litellm_provider']; - $model = explode('/', $model); + $model = explode('/', (string) $model); $model = array_pop($model); if (isset($ourProviders[$provider]['skip']) && preg_match($ourProviders[$provider]['skip'], $model)) { @@ -103,13 +103,11 @@ protected function updateModelData() if ($data['mode'] === 'chat') { $newmodel['outputTokens'] = $data['max_output_tokens']; $newmodel['outputTokenPrice'] = round($data['output_cost_per_token'] * 1_000_000, 2); + } elseif (isset($oldmodel['dimensions'])) { + $newmodel['dimensions'] = $oldmodel['dimensions']; } else { - if (isset($oldmodel['dimensions'])) { - $newmodel['dimensions'] = $oldmodel['dimensions']; - } else { - $this->warning('No dimensions for ' . $provider . ' ' . $model . '. Check manually!'); - $newmodel['dimensions'] = 1536; - } + $this->warning('No dimensions for ' . $provider . ' ' . $model . '. Check manually!'); + $newmodel['dimensions'] = 1536; } $ourProviders[$provider]['models'][$data['mode']][$model] = $newmodel; } diff --git a/cli/simulate.php b/cli/simulate.php index 3c670e0..4726640 100644 --- a/cli/simulate.php +++ b/cli/simulate.php @@ -159,8 +159,6 @@ protected function records2rows(array $result): array /** * Prefix each key in the given stats array to be merged with a larger array * - * @param string $prefix - * @param array $stats * @return array */ protected function flattenStats(string $prefix, array $stats) @@ -173,7 +171,6 @@ protected function flattenStats(string $prefix, array $stats) } /** - * @param string $file * @return array * @throws Exception */ diff --git a/helper.php b/helper.php index 19fbc1f..ec62a9b 100644 --- a/helper.php +++ b/helper.php @@ -59,7 +59,6 @@ public function setLogger($logger) /** * Update the configuration * - * @param array $config * @return void */ public function updateConfig(array $config) @@ -387,7 +386,6 @@ public function getLanguageLimit() /** * Store info about the last run * - * @param array $data * @return void */ public function setRunData(array $data)