Proyectos de Subversion Moodle

Rev

| Ultima modificación | Ver Log |

Rev Autor Línea Nro. Línea
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\responses;
18
 
19
/**
20
 * Generate image action response class.
21
 *
22
 * Any method that processes an action must return an instance of this 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 response_generate_image extends response_base {
29
    /** @var \stored_file|null The URL of the generated image. */
30
    private ?\stored_file $draftfile = null;
31
 
32
    /** @var string|null The revised prompt generated by the AI. */
33
    private ?string $revisedprompt = null;
34
 
35
    /** @var string|null The URL of the source image used to generate the image. */
36
    private ?string $sourceurl = null;
37
 
38
    /**
39
     * Constructor.
40
     *
41
     * @param bool $success The success status of the action.
42
     * @param int $errorcode Error code. Must exist if success is false.
43
     * @param string $errormessage Error message. Must exist if success is false
44
     */
45
    public function __construct(
46
        bool $success,
47
        int $errorcode = 0,
48
        string $errormessage = '',
49
    ) {
50
        parent::__construct(
51
            success: $success,
52
            actionname: 'generate_image',
53
            errorcode: $errorcode,
54
            errormessage: $errormessage,
55
        );
56
    }
57
 
58
    #[\Override]
59
    public function set_response_data(array $response): void {
60
        $this->draftfile = $response['draftfile'] ?? null;
61
        $this->revisedprompt = $response['revisedprompt'] ?? null;
62
        $this->sourceurl = $response['sourceurl'] ?? null;
63
        $this->model = $response['model'] ?? null;
64
    }
65
 
66
    #[\Override]
67
    public function get_response_data(): array {
68
        return [
69
            'draftfile' => $this->draftfile,
70
            'revisedprompt' => $this->revisedprompt,
71
            'sourceurl' => $this->sourceurl,
72
            'model' => $this->model,
73
        ];
74
    }
75
}