11<?php
22
3+ use dokuwiki \Extension \CLIPlugin ;
34use dokuwiki \plugin \aichat \ModelFactory ;
45use splitbrain \phpcli \Colors ;
56use splitbrain \phpcli \Options ;
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