Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
1441 ariadna 1
<?php
2
// This file is part of Moodle - http://moodle.org/
3
//
4
// Moodle is free software: you can redistribute it and/or modify
5
// it under the terms of the GNU General Public License as published by
6
// the Free Software Foundation, either version 3 of the License, or
7
// (at your option) any later version.
8
//
9
// Moodle is distributed in the hope that it will be useful,
10
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
// GNU General Public License for more details.
13
//
14
// You should have received a copy of the GNU General Public License
15
// along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
16
 
17
namespace aiprovider_ollama;
18
 
19
/**
20
 * Trait for test cases.
21
 *
22
 * @package    aiprovider_ollama
23
 * @copyright  2025 Huong Nguyen <huongnv13@gmail.com>
24
 * @license    http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
25
 */
26
trait testcase_helper_trait {
27
 
28
    /**
29
     * Create the provider object.
30
     *
31
     * @param string $actionclass The action class to use.
32
     * @param array $actionconfig The action configuration to use.
33
     */
34
    public function create_provider(
35
        string $actionclass,
36
        array $actionconfig = [],
37
    ): \core_ai\provider {
38
        $manager = \core\di::get(\core_ai\manager::class);
39
        $config = [
40
            'enableuserratelimit' => true,
41
            'userratelimit' => 1,
42
            'enableglobalratelimit' => true,
43
            'globalratelimit' => 1,
44
            'endpoint' => "http://localhost:11434/",
45
        ];
46
        $defaultactionconfig = [
47
            $actionclass => [
48
                'settings' => [
49
                    'model' => 'llama3.2',
50
                ],
51
            ],
52
        ];
53
        foreach ($actionconfig as $key => $value) {
54
            $defaultactionconfig[$actionclass]['settings'][$key] = $value;
55
        }
56
        $provider = $manager->create_provider_instance(
57
            classname: '\aiprovider_ollama\provider',
58
            name: 'dummy',
59
            config: $config,
60
            actionconfig: $defaultactionconfig,
61
        );
62
 
63
        return $provider;
64
    }
65
}