Skip to content

Commit

Permalink
🤖 Automatic code style fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
splitbrain authored and github-actions[bot] committed Jul 22, 2024
1 parent c2f5508 commit f34c687
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 27 deletions.
3 changes: 0 additions & 3 deletions Embeddings.php
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
4 changes: 2 additions & 2 deletions Model/AbstractModel.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
Expand Down
10 changes: 2 additions & 8 deletions ModelFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,6 @@

class ModelFactory
{
/** @var array The plugin configuration */
protected array $config;

public $chatModel;
public $rephraseModel;
public $embeddingModel;
Expand All @@ -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;
}

/**
Expand All @@ -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)
{
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 7 additions & 9 deletions cli/dev.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use dokuwiki\HTTP\DokuHTTPClient;
use dokuwiki\plugin\aichat\AbstractCLI;
use splitbrain\phpcli\Options;

Expand All @@ -25,7 +26,6 @@ protected function main(Options $options)
parent::main($options);

switch ($options->getCmd()) {

case 'update':
$this->updateModelData();
break;
Expand All @@ -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) {
Expand Down Expand Up @@ -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)) {
Expand All @@ -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;
}
Expand Down
3 changes: 0 additions & 3 deletions cli/simulate.php
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -173,7 +171,6 @@ protected function flattenStats(string $prefix, array $stats)
}

/**
* @param string $file
* @return array
* @throws Exception
*/
Expand Down
2 changes: 0 additions & 2 deletions helper.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ public function setLogger($logger)
/**
* Update the configuration
*
* @param array $config
* @return void
*/
public function updateConfig(array $config)
Expand Down Expand Up @@ -387,7 +386,6 @@ public function getLanguageLimit()
/**
* Store info about the last run
*
* @param array $data
* @return void
*/
public function setRunData(array $data)
Expand Down

0 comments on commit f34c687

Please sign in to comment.