Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🤖 Automatic code style fixes #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
4 changes: 2 additions & 2 deletions Storage/QdrantStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ protected function runQuery($endpoint, mixed $data, $method = 'POST', $retry = 0
$response = $this->http->resp_body;

if (!$response) {
if($retry < 3) {
if ($retry < 3) {
sleep(1 + $retry);
return $this->runQuery($endpoint, $data, $method, $retry + 1);
}
Expand All @@ -75,7 +75,7 @@ protected function runQuery($endpoint, mixed $data, $method = 'POST', $retry = 0
try {
$result = json_decode((string)$response, true, 512, JSON_THROW_ON_ERROR);
} catch (\Exception $e) {
if($retry < 3) {
if ($retry < 3) {
sleep(1 + $retry);
return $this->runQuery($endpoint, $data, $method, $retry + 1);
}
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 @@ -388,7 +387,6 @@ public function getLanguageLimit()
/**
* Store info about the last run
*
* @param array $data
* @return void
*/
public function setRunData(array $data)
Expand Down