xref: /plugin/aichat/RemoteResponse/LlmReply.php (revision 42b2c6e864def16df42600c2885e21d4d148fd0c)
1*42b2c6e8SAndreas Gohr<?php
2*42b2c6e8SAndreas Gohr
3*42b2c6e8SAndreas Gohrnamespace dokuwiki\plugin\aichat\RemoteResponse;
4*42b2c6e8SAndreas Gohr
5*42b2c6e8SAndreas Gohruse dokuwiki\plugin\aichat\RemoteResponse\Chunk as ChunkResponse;
6*42b2c6e8SAndreas Gohruse dokuwiki\Remote\Response\ApiResponse;
7*42b2c6e8SAndreas Gohr
8*42b2c6e8SAndreas Gohrclass LlmReply extends ApiResponse
9*42b2c6e8SAndreas Gohr{
10*42b2c6e8SAndreas Gohr    /** @var string The question as asked */
11*42b2c6e8SAndreas Gohr    public $question;
12*42b2c6e8SAndreas Gohr    /** @var string The answer provided by the LLM */
13*42b2c6e8SAndreas Gohr    public $answer;
14*42b2c6e8SAndreas Gohr    /** @var ChunkResponse[] The sources provided to the model to answer the questions */
15*42b2c6e8SAndreas Gohr    public $sources = [];
16*42b2c6e8SAndreas Gohr
17*42b2c6e8SAndreas Gohr    public function __construct($data)
18*42b2c6e8SAndreas Gohr    {
19*42b2c6e8SAndreas Gohr        $this->question = $data['question'];
20*42b2c6e8SAndreas Gohr        $this->answer = $data['answer'];
21*42b2c6e8SAndreas Gohr
22*42b2c6e8SAndreas Gohr        foreach ($data['sources'] as $source) {
23*42b2c6e8SAndreas Gohr            $this->sources[] = new ChunkResponse($source);
24*42b2c6e8SAndreas Gohr        }
25*42b2c6e8SAndreas Gohr    }
26*42b2c6e8SAndreas Gohr
27*42b2c6e8SAndreas Gohr    public function __toString()
28*42b2c6e8SAndreas Gohr    {
29*42b2c6e8SAndreas Gohr        return $this->question;
30*42b2c6e8SAndreas Gohr    }
31*42b2c6e8SAndreas Gohr}
32