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