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 core_ai\aiactions;
|
|
|
18 |
|
|
|
19 |
use core_ai\aiactions\responses\response_base;
|
|
|
20 |
|
|
|
21 |
/**
|
|
|
22 |
* Summarise text class.
|
|
|
23 |
*
|
|
|
24 |
* @package core_ai
|
|
|
25 |
* @copyright 2024 Matt Porritt <matt.porritt@moodle.com>
|
|
|
26 |
* @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
|
|
|
27 |
*/
|
|
|
28 |
class summarise_text extends base {
|
|
|
29 |
/**
|
|
|
30 |
* Create a new instance of the summarise_text action.
|
|
|
31 |
*
|
|
|
32 |
* It’s responsible for performing any setup tasks,
|
|
|
33 |
* such as getting additional data from the database etc.
|
|
|
34 |
*
|
|
|
35 |
* @param int $contextid The context id the action was created in.
|
|
|
36 |
* @param int $userid The user id making the request.
|
|
|
37 |
* @param string $prompttext The prompt text used to generate the image.
|
|
|
38 |
*/
|
|
|
39 |
public function __construct(
|
|
|
40 |
int $contextid,
|
|
|
41 |
/** @var int The user id requesting the action. */
|
|
|
42 |
protected int $userid,
|
|
|
43 |
/** @var string The prompt text used to generate the summary text */
|
|
|
44 |
protected string $prompttext,
|
|
|
45 |
) {
|
|
|
46 |
parent::__construct($contextid);
|
|
|
47 |
}
|
|
|
48 |
|
|
|
49 |
#[\Override]
|
|
|
50 |
public function store(response_base $response): int {
|
|
|
51 |
global $DB;
|
|
|
52 |
|
|
|
53 |
$responsearr = $response->get_response_data();
|
|
|
54 |
|
|
|
55 |
$record = new \stdClass();
|
|
|
56 |
$record->prompt = $this->prompttext;
|
|
|
57 |
$record->responseid = $responsearr['id']; // Can be null.
|
|
|
58 |
$record->fingerprint = $responsearr['fingerprint']; // Can be null.
|
|
|
59 |
$record->generatedcontent = $responsearr['generatedcontent']; // Can be null.
|
|
|
60 |
$record->finishreason = $responsearr['finishreason']; // Can be null.
|
|
|
61 |
$record->prompttokens = $responsearr['prompttokens']; // Can be null.
|
|
|
62 |
$record->completiontoken = $responsearr['completiontokens']; // Can be null.
|
|
|
63 |
|
|
|
64 |
return $DB->insert_record($this->get_tablename(), $record);
|
|
|
65 |
}
|
|
|
66 |
}
|