|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
/* For licensing terms, see /license.txt */ |
|
6
|
|
|
|
|
7
|
|
|
namespace Chamilo\CoreBundle\Settings; |
|
8
|
|
|
|
|
9
|
|
|
use Sylius\Bundle\SettingsBundle\Schema\AbstractSettingsBuilder; |
|
10
|
|
|
use Symfony\Component\Form\Extension\Core\Type\TextareaType; |
|
11
|
|
|
use Symfony\Component\Form\FormBuilderInterface; |
|
12
|
|
|
use Chamilo\CoreBundle\Form\Type\YesNoType; |
|
13
|
|
|
|
|
14
|
|
|
class AiHelpersSettingsSchema extends AbstractSettingsSchema |
|
15
|
|
|
{ |
|
16
|
|
|
public function buildSettings(AbstractSettingsBuilder $builder): void |
|
17
|
|
|
{ |
|
18
|
|
|
$builder |
|
19
|
|
|
->setDefaults( |
|
20
|
|
|
[ |
|
21
|
|
|
'enable_ai_helpers' => 'false', |
|
22
|
|
|
'ai_providers' => '', |
|
23
|
|
|
'learning_path_generator' => 'false', |
|
24
|
|
|
'exercise_generator' => 'false', |
|
25
|
|
|
'open_answers_grader' => 'false', |
|
26
|
|
|
'tutor_chatbot' => 'false', |
|
27
|
|
|
'task_grader' => 'false', |
|
28
|
|
|
'content_analyser' => 'false', |
|
29
|
|
|
'image_generator' => 'false', |
|
30
|
|
|
] |
|
31
|
|
|
); |
|
32
|
|
|
} |
|
33
|
|
|
|
|
34
|
|
|
public function buildForm(FormBuilderInterface $builder): void |
|
35
|
|
|
{ |
|
36
|
|
|
$builder |
|
37
|
|
|
->add('enable_ai_helpers', YesNoType::class) |
|
38
|
|
|
->add('ai_providers', TextareaType::class, [ |
|
39
|
|
|
'help_html' => true, |
|
40
|
|
|
'help' => $this->settingArrayHelpValue('ai_providers'), |
|
41
|
|
|
'attr' => ['rows' => 10, 'style' => 'font-family: monospace;'] |
|
42
|
|
|
]) |
|
43
|
|
|
->add('learning_path_generator', YesNoType::class) |
|
44
|
|
|
->add('exercise_generator', YesNoType::class) |
|
45
|
|
|
->add('open_answers_grader', YesNoType::class) |
|
46
|
|
|
->add('tutor_chatbot', YesNoType::class) |
|
47
|
|
|
->add('task_grader', YesNoType::class) |
|
48
|
|
|
->add('content_analyser', YesNoType::class) |
|
49
|
|
|
->add('image_generator', YesNoType::class); |
|
50
|
|
|
|
|
51
|
|
|
$this->updateFormFieldsFromSettingsInfo($builder); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
private function settingArrayHelpValue(string $variable): string |
|
55
|
|
|
{ |
|
56
|
|
|
$values = [ |
|
57
|
|
|
'ai_providers' => "<pre> |
|
58
|
|
|
{ |
|
59
|
|
|
\"openai\": { |
|
60
|
|
|
\"url\": \"https://api.openai.com/v1/chat/completions\", |
|
61
|
|
|
\"api_key\": \"your-key\", |
|
62
|
|
|
\"model\": \"gpt-4o\", |
|
63
|
|
|
\"temperature\": 0.7, |
|
64
|
|
|
\"organization_id\": \"org123\", |
|
65
|
|
|
\"monthly_token_limit\": 10000 |
|
66
|
|
|
}, |
|
67
|
|
|
\"deepseek\": { |
|
68
|
|
|
\"url\": \"https://api.deepseek.com/chat/completions\", |
|
69
|
|
|
\"api_key\": \"your-key\", |
|
70
|
|
|
\"model\": \"deepseek-chat\", |
|
71
|
|
|
\"temperature\": 0.7, |
|
72
|
|
|
\"organization_id\": \"org456\", |
|
73
|
|
|
\"monthly_token_limit\": 5000 |
|
74
|
|
|
} |
|
75
|
|
|
} |
|
76
|
|
|
</pre>", |
|
77
|
|
|
]; |
|
78
|
|
|
|
|
79
|
|
|
$returnValue = []; |
|
80
|
|
|
if (isset($values[$variable])) { |
|
81
|
|
|
$returnValue = $values[$variable]; |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
return $returnValue; |
|
|
|
|
|
|
85
|
|
|
} |
|
86
|
|
|
} |
|
87
|
|
|
|