xref: /plugin/aichat/Model/Ollama/ChatModel.php (revision 7be8078ef9026e317a5c01f90a94183276bbbbd2)
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' => [
17*7be8078eSAndreas Gohr                'num_ctx' => $this->getMaxInputTokenLength() ?: 512
184dd0657eSAndreas Gohr            ]
19074b7701SAndreas Gohr        ];
20074b7701SAndreas Gohr        $response = $this->request('chat', $data);
21d481c63cSAndreas Gohr        $content = $response['message']['content'];
22d481c63cSAndreas Gohr        // remove thinking part from deepseek answers
23d481c63cSAndreas Gohr        $content = preg_replace('/^<think>.*?(?:<\/think>)/s', '', $content);
24d481c63cSAndreas Gohr        return $content;
25074b7701SAndreas Gohr    }
26074b7701SAndreas Gohr}
27