xref: /plugin/aichat/Model/Ollama/EmbeddingModel.php (revision 4dd0657e5ac7e828b159f619391769caa2e5332f)
1074b7701SAndreas Gohr<?php
2074b7701SAndreas Gohr
3074b7701SAndreas Gohrnamespace dokuwiki\plugin\aichat\Model\Ollama;
4074b7701SAndreas Gohr
5074b7701SAndreas Gohruse dokuwiki\plugin\aichat\Model\EmbeddingInterface;
6074b7701SAndreas Gohr
7074b7701SAndreas Gohrclass EmbeddingModel extends AbstractOllama implements EmbeddingInterface
8074b7701SAndreas Gohr{
9074b7701SAndreas Gohr    /** @inheritdoc */
10074b7701SAndreas Gohr    public function getEmbedding($text): array
11074b7701SAndreas Gohr    {
12074b7701SAndreas Gohr        $data = [
13074b7701SAndreas Gohr            'model' => $this->getModelName(),
14074b7701SAndreas Gohr            'prompt' => $text,
15*4dd0657eSAndreas Gohr            'options' => [
16*4dd0657eSAndreas Gohr                'num_ctx' => $this->getMaxInputTokenLength()
17*4dd0657eSAndreas Gohr            ]
18074b7701SAndreas Gohr        ];
19074b7701SAndreas Gohr        $response = $this->request('embeddings', $data);
20074b7701SAndreas Gohr
21074b7701SAndreas Gohr        return $response['embedding'];
22074b7701SAndreas Gohr    }
23074b7701SAndreas Gohr}
24