Skip to content

Commit 2071dce

Browse files
committed
automatic stylefixes
1 parent 4a647d2 commit 2071dce

File tree

12 files changed

+39
-36
lines changed

12 files changed

+39
-36
lines changed

Chunk.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@ public function __construct(
2222
protected $id,
2323
protected $text,
2424
protected $embedding,
25-
$lang = '',
26-
$created = '',
25+
$lang = '',
26+
$created = '',
2727
protected $score = 0
28-
)
29-
{
28+
) {
3029
$this->language = $lang ?: $this->determineLanguage();
3130
$this->created = $created ?: time();
3231
}

Embeddings.php

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,12 +54,11 @@ class Embeddings
5454
* @param array $config The plugin configuration
5555
*/
5656
public function __construct(
57-
ChatInterface $chatModel,
57+
ChatInterface $chatModel,
5858
EmbeddingInterface $embedModel,
59-
AbstractStorage $storage,
60-
$config
61-
)
62-
{
59+
AbstractStorage $storage,
60+
$config
61+
) {
6362
$this->chatModel = $chatModel;
6463
$this->embedModel = $embedModel;
6564
$this->storage = $storage;

Model/AbstractModel.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,8 @@ public function getModelName()
9393
*/
9494
public function resetUsageStats()
9595
{
96-
$this->tokensUsed = 0;
96+
$this->inputTokensUsed = 0;
97+
$this->outputTokensUsed = 0;
9798
$this->timeUsed = 0;
9899
$this->requestsMade = 0;
99100
}

Model/Mistral/AbstractMistralModel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ abstract class AbstractMistralModel extends AbstractModel
1515
public function __construct(string $name, array $config)
1616
{
1717
parent::__construct($name, $config);
18-
if(empty($config['mistral_apikey'])) {
18+
if (empty($config['mistral_apikey'])) {
1919
throw new \Exception('Mistral API key not configured');
2020
}
2121
$this->http->headers['Authorization'] = 'Bearer ' . $config['mistral_apikey'];

Model/ModelInterface.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,5 +50,4 @@ public function getMaxInputTokenLength(): int;
5050
* The price for 1,000,000 input tokens in USD
5151
*/
5252
public function getInputTokenPrice(): float;
53-
5453
}

Model/VoyageAI/EmbeddingModel.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,5 +58,4 @@ protected function parseAPIResponse($response)
5858

5959
return $response;
6060
}
61-
6261
}

ModelFactory.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public function __construct(array $config)
2929
*
3030
* @param bool $debug
3131
*/
32-
public function setDebug(bool $debug=true)
32+
public function setDebug(bool $debug = true)
3333
{
3434
$this->debug = $debug;
3535
$this->getChatModel()->setDebug($debug);
@@ -155,5 +155,4 @@ public function loadModel(string $type, string $name)
155155

156156
return $instance;
157157
}
158-
159158
}

ModelSetting.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,10 @@
22

33
namespace dokuwiki\plugin\aichat;
44

5-
65
use dokuwiki\plugin\config\core\Setting\SettingMultichoice;
76

8-
class ModelSetting extends SettingMultichoice {
9-
7+
class ModelSetting extends SettingMultichoice
8+
{
109
/** @inheritdoc */
1110
public function __construct($key, $params = null)
1211
{
@@ -17,7 +16,7 @@ public function __construct($key, $params = null)
1716
$jsons = glob(__DIR__ . '/Model/*/models.json');
1817
foreach ($jsons as $json) {
1918
$models = json_decode(file_get_contents($json), true);
20-
if(!isset($models[$type])) continue;
19+
if (!isset($models[$type])) continue;
2120

2221
$namespace = basename(dirname($json));
2322
foreach (array_keys($models[$type]) as $model) {

Storage/PineconeStorage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ protected function runQuery($endpoint, mixed $data, $method = 'POST')
5454
}
5555

5656
try {
57-
$result = json_decode((string)$response, true, 512, JSON_THROW_ON_ERROR);
57+
$result = json_decode((string)$response, true, 512, JSON_THROW_ON_ERROR);
5858
} catch (\JsonException $e) {
5959
throw new \Exception('Pinecone API returned invalid JSON. ' . $response, 0, $e);
6060
}

cli/simulate.php

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use dokuwiki\Extension\CLIPlugin;
34
use dokuwiki\plugin\aichat\ModelFactory;
45
use splitbrain\phpcli\Colors;
56
use splitbrain\phpcli\Options;
@@ -10,7 +11,7 @@
1011
* @license GPL 2 http://www.gnu.org/licenses/gpl-2.0.html
1112
* @author Andreas Gohr <gohr@cosmocode.de>
1213
*/
13-
class cli_plugin_aichat_simulate extends \dokuwiki\Extension\CLIPlugin
14+
class cli_plugin_aichat_simulate extends CLIPlugin
1415
{
1516
/** @var helper_plugin_aichat */
1617
protected $helper;
@@ -50,7 +51,7 @@ protected function main(Options $options)
5051
[$input, $output] = $options->getArgs();
5152
$questions = $this->readInputFile($input);
5253
$outfh = @fopen($output, 'w');
53-
if(!$outfh) throw new \Exception("Could not open $output for writing");
54+
if (!$outfh) throw new \Exception("Could not open $output for writing");
5455

5556
$models = $this->helper->factory->getModels(true, 'chat');
5657

@@ -92,7 +93,7 @@ protected function simulate($questions, $model)
9293
'question' => $q,
9394
'rephrased' => $result['question'],
9495
'answer' => $result['answer'],
95-
'source.list' => join("\n", $result['sources']),
96+
'source.list' => implode("\n", $result['sources']),
9697
'source.time' => $this->helper->getEmbeddings()->timeSpent,
9798
...$this->flattenStats('stats.embedding', $this->helper->getEmbeddingModel()->getUsageStats()),
9899
...$this->flattenStats('stats.rephrase', $this->helper->getRephraseModel()->getUsageStats()),
@@ -132,13 +133,13 @@ protected function records2rows(array $result): array
132133
$rows[] = $row;
133134

134135
// write rows
135-
for($i=0; $i<$numberOfRecords; $i++) {
136-
foreach($rowkeys as $type => $keys) {
136+
for ($i = 0; $i < $numberOfRecords; $i++) {
137+
foreach ($rowkeys as $type => $keys) {
137138
$row = [];
138139
$row[] = $type;
139-
foreach($models as $model) {
140+
foreach ($models as $model) {
140141
foreach ($keys as $key) {
141-
if($key) {
142+
if ($key) {
142143
$row[] = $result[$model][$i][$key];
143144
} else {
144145
$row[] = '';
@@ -161,9 +162,10 @@ protected function records2rows(array $result): array
161162
* @param array $stats
162163
* @return array
163164
*/
164-
protected function flattenStats(string $prefix, array $stats) {
165+
protected function flattenStats(string $prefix, array $stats)
166+
{
165167
$result = [];
166-
foreach($stats as $key => $value) {
168+
foreach ($stats as $key => $value) {
167169
$result["$prefix.$key"] = $value;
168170
}
169171
return $result;
@@ -183,4 +185,3 @@ protected function readInputFile(string $file): array
183185
return $questions;
184186
}
185187
}
186-

0 commit comments

Comments
 (0)