/
MeasurableSettings.php
97 lines (88 loc) · 3.53 KB
/
MeasurableSettings.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
<?php
/**
* Matomo - free/libre analytics platform
*
* @link https://matomo.org
* @license http://www.gnu.org/licenses/gpl-3.0.html GPL v3 or later
*/
namespace Piwik\Plugins\MistralAI;
use Piwik\Settings\Setting;
use Piwik\Settings\FieldConfig;
use Piwik\Validators\NotEmpty;
/**
* Defines Settings for MistralAI.
*
* Usage like this:
* // require Piwik\Plugin\SettingsProvider via Dependency Injection eg in constructor of your class
* $settings = $settingsProvider->getMeasurableSettings('ChatGPT', $idSite);
* $settings->appId->getValue();
* $settings->contactEmails->getValue();
*/
class MeasurableSettings extends \Piwik\Settings\Measurable\MeasurableSettings
{
/** @var Setting */
public $host;
public $apiKey;
public $model;
public $chatBasePrompt;
public $insightBasePrompt;
protected function init()
{
// System setting --> allows selection of a single value
$this->host = $this->createHostSetting();
$this->apiKey = $this->createApiKeySetting();
$this->model = $this->createModelSetting();
$this->chatBasePrompt = $this->createChatBasePromptSetting();
$this->insightBasePrompt = $this->createInsightBasePromptSetting();
}
private function createHostSetting()
{
return $this->makeSetting('host', $default = '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Host';
$field->uiControl = FieldConfig::UI_CONTROL_URL;
$field->description = 'Change the host to connect your own Mistral instance';
});
}
private function createApiKeySetting()
{
return $this->makeSetting('apiKey', $default = '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'API Key';
$field->uiControl = FieldConfig::UI_CONTROL_PASSWORD;
$field->description = 'Add your Mistral AI API Key here';
});
}
private function createModelSetting()
{
return $this->makeSetting('model', $default = '', FieldConfig::TYPE_ARRAY, function (FieldConfig $field) {
$field->title = 'Model';
$field->uiControl = FieldConfig::UI_CONTROL_SINGLE_SELECT;
$field->description = 'Select the model you want to use';
$field->availableValues = array(
'' => '',
'open-mistral-7b' => 'Open Mistral 7b',
'open-mixtral-8x7b' => 'Open Mixtral 8x7b',
'mistral-tiny' => 'Tiny',
'mistral-small-latest' => 'Small latest',
'mistral-medium-latest' => 'Medium latest',
'mistral-large-latest' => 'Large latest'
);
$field->validators[] = new NotEmpty();
});
}
private function createChatBasePromptSetting()
{
return $this->makeSetting('chatBasePrompt', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Chat base prompt';
$field->uiControl = FieldConfig::UI_CONTROL_TEXTAREA;
$field->description = 'Adapt the prompt to get more precise answer in the chat feature';
});
}
private function createInsightBasePromptSetting()
{
return $this->makeSetting('insightBasePrompt', '', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Insight base prompt';
$field->uiControl = FieldConfig::UI_CONTROL_TEXTAREA;
$field->description = 'Adapt the prompt to get more precise insights for your reports';
});
}
}