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_openai\test;
|
|
|
18 |
|
|
|
19 |
/**
|
|
|
20 |
* Trait for test cases.
|
|
|
21 |
*
|
|
|
22 |
* @package aiprovider_openai
|
|
|
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 |
'apikey' => '123',
|
|
|
41 |
'enableuserratelimit' => true,
|
|
|
42 |
'userratelimit' => 1,
|
|
|
43 |
'enableglobalratelimit' => true,
|
|
|
44 |
'globalratelimit' => 1,
|
|
|
45 |
];
|
|
|
46 |
$defaultactionconfig = [
|
|
|
47 |
$actionclass => [
|
|
|
48 |
'settings' => [
|
|
|
49 |
'model' => 'gpt-4o',
|
|
|
50 |
'endpoint' => "https://api.openai.com/v1/chat/completions",
|
|
|
51 |
],
|
|
|
52 |
],
|
|
|
53 |
];
|
|
|
54 |
foreach ($actionconfig as $key => $value) {
|
|
|
55 |
$defaultactionconfig[$actionclass]['settings'][$key] = $value;
|
|
|
56 |
}
|
|
|
57 |
$provider = $manager->create_provider_instance(
|
|
|
58 |
classname: '\aiprovider_openai\provider',
|
|
|
59 |
name: 'dummy',
|
|
|
60 |
config: $config,
|
|
|
61 |
actionconfig: $defaultactionconfig,
|
|
|
62 |
);
|
|
|
63 |
|
|
|
64 |
return $provider;
|
|
|
65 |
}
|
|
|
66 |
}
|