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 |
* Generate images 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 generate_image extends base {
|
|
|
29 |
/**
|
|
|
30 |
* Create a new instance of the generate_image 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 |
* @param string $quality The quality of the generated image.
|
|
|
39 |
* @param string $aspectratio The aspect ratio of the generated image.
|
|
|
40 |
* @param int $numimages The number of images to generate.
|
|
|
41 |
* @param string $style The visual style of the generated image.
|
|
|
42 |
*/
|
|
|
43 |
public function __construct(
|
|
|
44 |
int $contextid,
|
|
|
45 |
/** @var int The user id requesting the action. */
|
|
|
46 |
protected int $userid,
|
|
|
47 |
/** @var string The prompt text used to generate the image */
|
|
|
48 |
protected string $prompttext,
|
|
|
49 |
/** @var string The quality of the generated image */
|
|
|
50 |
protected string $quality,
|
|
|
51 |
/** @var string The aspect ratio of the generated image */
|
|
|
52 |
protected string $aspectratio,
|
|
|
53 |
/** @var int The number of images to generate */
|
|
|
54 |
protected int $numimages,
|
|
|
55 |
/** @var string The visual style of the generated image */
|
|
|
56 |
protected string $style,
|
|
|
57 |
) {
|
|
|
58 |
parent::__construct($contextid);
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
#[\Override]
|
|
|
62 |
public function store(response_base $response): int {
|
|
|
63 |
global $DB;
|
|
|
64 |
|
|
|
65 |
$responsearr = $response->get_response_data();
|
|
|
66 |
|
|
|
67 |
$record = new \stdClass();
|
|
|
68 |
$record->prompt = $this->prompttext;
|
|
|
69 |
$record->numberimages = $this->numimages;
|
|
|
70 |
$record->quality = $this->quality;
|
|
|
71 |
$record->aspectratio = $this->aspectratio;
|
|
|
72 |
$record->style = $this->style;
|
|
|
73 |
$record->sourceurl = $responsearr['sourceurl']; // Can be null.
|
|
|
74 |
$record->revisedprompt = $responsearr['revisedprompt']; // Can be null.
|
|
|
75 |
|
|
|
76 |
return $DB->insert_record($this->get_tablename(), $record);
|
|
|
77 |
}
|
|
|
78 |
}
|