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