-
Notifications
You must be signed in to change notification settings - Fork 2
/
SystemSettings.php
97 lines (88 loc) · 3.69 KB
/
SystemSettings.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\ChatGPT;
use Piwik\Settings\Setting;
use Piwik\Settings\FieldConfig;
use Piwik\Validators\NotEmpty;
/**
* Defines Settings for ChatGPT.
*
* Usage like this:
* $settings = new SystemSettings();
* $settings->metric->getValue();
* $settings->description->getValue();
*/
class SystemSettings extends \Piwik\Settings\Plugin\SystemSettings
{
/** @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 = 'https://api.openai.com/v1/chat/completions', FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'Host';
$field->uiControl = FieldConfig::UI_CONTROL_URL;
$field->description = 'Change the host to connect your own GPT instance';
$field->validators[] = new NotEmpty();
});
}
private function createApiKeySetting()
{
return $this->makeSetting('apiKey', $default = null, FieldConfig::TYPE_STRING, function (FieldConfig $field) {
$field->title = 'API Key';
$field->uiControl = FieldConfig::UI_CONTROL_PASSWORD;
$field->description = 'Add your ChatGPT API Key here';
$field->validators[] = new NotEmpty();
});
}
private function createModelSetting()
{
return $this->makeSetting('model', $default = 'gpt-3.5-turbo', 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(
'gpt-3.5-turbo' => 'GPT 3.5 turbo',
'gpt-4' => 'GPT 4',
'gpt-4-turbo' => 'GPT 4 Turbo',
'gpt-4o' => 'GPT 4o',
);
$field->validators[] = new NotEmpty();
});
}
private function createChatBasePromptSetting()
{
return $this->makeSetting('chatBasePrompt', $default = 'You are a Matomo expert and know everything about digital analytics. Your answer should be complete and precise.', 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';
$field->validators[] = new NotEmpty();
});
}
private function createInsightBasePromptSetting()
{
return $this->makeSetting('insightBasePrompt', $default = 'Give me insights from the dataset formatted in JSON provided below, add bold style to most important metrics of your answer :', 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';
$field->validators[] = new NotEmpty();
});
}
}