forked from reply2future/xExtension-NewsAssistant
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extension.php
54 lines (44 loc) · 2.01 KB
/
extension.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
<?php
// doc: https://freshrss.github.io/FreshRSS/en/developers/03_Backend/05_Extensions.html
class NewsAssistantExtension extends Minz_Extension
{
public function init()
{
$this->registerTranslates();
$this->registerController('assistant');
$this->registerViews();
$this->registerHook('nav_menu', array($this, 'addSummaryBtn'));
}
public function addSummaryBtn()
{
$cat_id = $this->getCategoryId();
$state = $this->getState();
$url = Minz_Url::display(array('c' => 'assistant', 'a' => 'summary', 'params' => array('cat_id' => $cat_id, 'state' => $state)));
$icon_url = $this->getFileUrl('filter.svg', 'svg');
return '<a id="summary" class="btn" href="' . $url . '" title="Get the summary news">
<img class="icon" src="' . $icon_url . '" loading="lazy" alt="️☀️">
</a>';
}
public function handleConfigureAction()
{
$this->registerTranslates();
if (Minz_Request::isPost()) {
FreshRSS_Context::$system_conf->openai_api_key = Minz_Request::param('openai_api_key', '');
FreshRSS_Context::$system_conf->max_tokens = filter_var(Minz_Request::param('max_tokens', 7), FILTER_VALIDATE_INT);
FreshRSS_Context::$system_conf->temperature = filter_var(Minz_Request::param('temperature', 1), FILTER_VALIDATE_FLOAT);;
FreshRSS_Context::$system_conf->limit = filter_var(Minz_Request::param('limit', 30), FILTER_VALIDATE_FLOAT);;
FreshRSS_Context::$system_conf->model = Minz_Request::param('model', 'text-davinci-003');
FreshRSS_Context::$system_conf->prompt = Minz_Request::param('prompt', 'Summarize this as you are news editor, you should merge the similar topic.');
FreshRSS_Context::$system_conf->field = Minz_Request::param('field', 'content');
FreshRSS_Context::$system_conf->save();
}
}
private function getCategoryId(): int {
if (!FreshRSS_Context::isCategory()) return 0;
return FreshRSS_Context::$current_get['category'];
}
private function getState(): int {
if (FreshRSS_Context::$state == 0) return FreshRSS_Entry::STATE_NOT_READ;
return FreshRSS_Context::$state;
}
}