xref: /plugin/aichat/Model/Ollama/ChatModel.php (revision d481c63ccb6ead31f97b7b0119104ee25a34de28)
1074b7701SAndreas Gohr<?php
2074b7701SAndreas Gohr
3074b7701SAndreas Gohrnamespace dokuwiki\plugin\aichat\Model\Ollama;
4074b7701SAndreas Gohr
5074b7701SAndreas Gohruse dokuwiki\plugin\aichat\Model\ChatInterface;
6074b7701SAndreas Gohr
7074b7701SAndreas Gohrclass ChatModel extends AbstractOllama implements ChatInterface
8074b7701SAndreas Gohr{
9074b7701SAndreas Gohr    /** @inheritdoc */
10074b7701SAndreas Gohr    public function getAnswer(array $messages): string
11074b7701SAndreas Gohr    {
12074b7701SAndreas Gohr        $data = [
13074b7701SAndreas Gohr            'messages' => $messages,
14074b7701SAndreas Gohr            'model' => $this->getModelName(),
15074b7701SAndreas Gohr            'stream' => false,
164dd0657eSAndreas Gohr            'options' => [
174dd0657eSAndreas Gohr                'num_ctx' => $this->getMaxInputTokenLength()
184dd0657eSAndreas Gohr            ]
19074b7701SAndreas Gohr        ];
20074b7701SAndreas Gohr        $response = $this->request('chat', $data);
21*d481c63cSAndreas Gohr        $content = $response['message']['content'];
22*d481c63cSAndreas Gohr        // remove thinking part from deepseek answers
23*d481c63cSAndreas Gohr        $content = preg_replace('/^<think>.*?(?:<\/think>)/s', '', $content);
24*d481c63cSAndreas Gohr        return $content;
25074b7701SAndreas Gohr    }
26074b7701SAndreas Gohr}
27