xref: /plugin/aichat/ModelSetting.php (revision 2071dced6f96936ea7b9bf5dbe8a117eef598448)
125892c36SAndreas Gohr<?php
225892c36SAndreas Gohr
325892c36SAndreas Gohrnamespace dokuwiki\plugin\aichat;
425892c36SAndreas Gohr
525892c36SAndreas Gohruse dokuwiki\plugin\config\core\Setting\SettingMultichoice;
625892c36SAndreas Gohr
7*2071dcedSAndreas Gohrclass ModelSetting extends SettingMultichoice
8*2071dcedSAndreas Gohr{
925892c36SAndreas Gohr    /** @inheritdoc */
1025892c36SAndreas Gohr    public function __construct($key, $params = null)
1125892c36SAndreas Gohr    {
1225892c36SAndreas Gohr        parent::__construct($key, $params);
1325892c36SAndreas Gohr
1425892c36SAndreas Gohr        $type = $params['type'] ?? 'chat';
1525892c36SAndreas Gohr
1625892c36SAndreas Gohr        $jsons = glob(__DIR__ . '/Model/*/models.json');
1725892c36SAndreas Gohr        foreach ($jsons as $json) {
1825892c36SAndreas Gohr            $models = json_decode(file_get_contents($json), true);
1925892c36SAndreas Gohr            if (!isset($models[$type])) continue;
2025892c36SAndreas Gohr
2125892c36SAndreas Gohr            $namespace = basename(dirname($json));
2225892c36SAndreas Gohr            foreach (array_keys($models[$type]) as $model) {
2325892c36SAndreas Gohr                $this->choices[] = "$namespace $model";
2425892c36SAndreas Gohr            }
2525892c36SAndreas Gohr        }
2625892c36SAndreas Gohr        sort($this->choices);
2725892c36SAndreas Gohr    }
2825892c36SAndreas Gohr}
29