xref: /plugin/aichat/ModelSetting.php (revision 25892c3659bd4c3ac5c1e89f086730a13961c417)
1*25892c36SAndreas Gohr<?php
2*25892c36SAndreas Gohr
3*25892c36SAndreas Gohrnamespace dokuwiki\plugin\aichat;
4*25892c36SAndreas Gohr
5*25892c36SAndreas Gohr
6*25892c36SAndreas Gohruse dokuwiki\plugin\config\core\Setting\SettingMultichoice;
7*25892c36SAndreas Gohr
8*25892c36SAndreas Gohrclass ModelSetting extends SettingMultichoice {
9*25892c36SAndreas Gohr
10*25892c36SAndreas Gohr    /** @inheritdoc */
11*25892c36SAndreas Gohr    public function __construct($key, $params = null)
12*25892c36SAndreas Gohr    {
13*25892c36SAndreas Gohr        parent::__construct($key, $params);
14*25892c36SAndreas Gohr
15*25892c36SAndreas Gohr        $type = $params['type'] ?? 'chat';
16*25892c36SAndreas Gohr
17*25892c36SAndreas Gohr        $jsons = glob(__DIR__ . '/Model/*/models.json');
18*25892c36SAndreas Gohr        foreach ($jsons as $json) {
19*25892c36SAndreas Gohr            $models = json_decode(file_get_contents($json), true);
20*25892c36SAndreas Gohr            if(!isset($models[$type])) continue;
21*25892c36SAndreas Gohr
22*25892c36SAndreas Gohr            $namespace = basename(dirname($json));
23*25892c36SAndreas Gohr            foreach (array_keys($models[$type]) as $model) {
24*25892c36SAndreas Gohr                $this->choices[] = "$namespace $model";
25*25892c36SAndreas Gohr            }
26*25892c36SAndreas Gohr        }
27*25892c36SAndreas Gohr        sort($this->choices);
28*25892c36SAndreas Gohr    }
29*25892c36SAndreas Gohr}
30