xref: /plugin/aichat/Model/ModelInterface.php (revision 7be8078ef9026e317a5c01f90a94183276bbbbd2)
14373d2bfSAndreas Gohr<?php
24373d2bfSAndreas Gohr
34373d2bfSAndreas Gohrnamespace dokuwiki\plugin\aichat\Model;
44373d2bfSAndreas Gohr
54373d2bfSAndreas Gohr/**
64373d2bfSAndreas Gohr * Interface for all models
74373d2bfSAndreas Gohr *
84373d2bfSAndreas Gohr * Model classes should inherit from AbstractModel, to avoid handling the statistics themselves.
94373d2bfSAndreas Gohr */
104373d2bfSAndreas Gohrinterface ModelInterface
114373d2bfSAndreas Gohr{
124373d2bfSAndreas Gohr    /**
13dce0dee5SAndreas Gohr     * Initialize the model
14dce0dee5SAndreas Gohr     *
15dce0dee5SAndreas Gohr     * @param string $name The name of the model as used by the LLM provider
16dce0dee5SAndreas Gohr     * @param array $config The plugin configuration
17dce0dee5SAndreas Gohr     * @throws \Exception when the model cannot be initialized
18dce0dee5SAndreas Gohr     */
19dce0dee5SAndreas Gohr    public function __construct(string $name, array $config);
20dce0dee5SAndreas Gohr
21dce0dee5SAndreas Gohr    /**
22b446155bSAndreas Gohr     * Get the full model name as used in the configuration
23b446155bSAndreas Gohr     */
24b446155bSAndreas Gohr    public function __toString(): string;
25b446155bSAndreas Gohr
26b446155bSAndreas Gohr    /**
274373d2bfSAndreas Gohr     * The name as used by the LLM provider
284373d2bfSAndreas Gohr     *
294373d2bfSAndreas Gohr     * @return string
304373d2bfSAndreas Gohr     */
314373d2bfSAndreas Gohr    public function getModelName();
324373d2bfSAndreas Gohr
334373d2bfSAndreas Gohr    /**
344373d2bfSAndreas Gohr     * Reset the usage statistics
354373d2bfSAndreas Gohr     *
364373d2bfSAndreas Gohr     * Usually not needed when only handling one operation per request, but useful in CLI
374373d2bfSAndreas Gohr     */
384373d2bfSAndreas Gohr    public function resetUsageStats();
394373d2bfSAndreas Gohr
404373d2bfSAndreas Gohr    /**
414373d2bfSAndreas Gohr     * Get the usage statistics for this instance
424373d2bfSAndreas Gohr     *
434373d2bfSAndreas Gohr     * @return string[]
444373d2bfSAndreas Gohr     */
454373d2bfSAndreas Gohr    public function getUsageStats();
46dce0dee5SAndreas Gohr
47dce0dee5SAndreas Gohr    /**
48dce0dee5SAndreas Gohr     * Maximum number of tokens the model can handle as input.
49dce0dee5SAndreas Gohr     *
50dce0dee5SAndreas Gohr     * This is the absolute limit, including any context, prompts, questions etc.
51*7be8078eSAndreas Gohr     *
52*7be8078eSAndreas Gohr     * The method may return 0 if the limit is unknown. In that case we will simply send what
53*7be8078eSAndreas Gohr     * we have and hope for the best
54dce0dee5SAndreas Gohr     */
55dce0dee5SAndreas Gohr    public function getMaxInputTokenLength(): int;
56dce0dee5SAndreas Gohr
57dce0dee5SAndreas Gohr    /**
58dce0dee5SAndreas Gohr     * The price for 1,000,000 input tokens in USD
59dce0dee5SAndreas Gohr     */
60dce0dee5SAndreas Gohr    public function getInputTokenPrice(): float;
614dd0657eSAndreas Gohr
624dd0657eSAndreas Gohr    /**
634dd0657eSAndreas Gohr     * Load the model info if no data is in the model.json
644dd0657eSAndreas Gohr     *
654dd0657eSAndreas Gohr     * Either fetch the info via API or return sensible defaults.
664dd0657eSAndreas Gohr     * @return array
674dd0657eSAndreas Gohr     */
684dd0657eSAndreas Gohr    function loadUnknownModelInfo(): array;
694373d2bfSAndreas Gohr}
70