| 1 |
<?php |
| 2 |
|
| 3 |
namespace WPDeveloper\BetterDocs\AI\Contracts; |
| 4 |
|
| 5 |
/** |
| 6 |
* Contract every AI chat provider must fulfil. |
| 7 |
* |
| 8 |
* A provider wraps a single platform's chat-completion API (OpenAI, Gemini, |
| 9 |
* Claude, DeepSeek, OpenRouter, …). The rest of BetterDocs talks to providers |
| 10 |
* only through this interface, so adding a platform is a new class — not a new |
| 11 |
* conditional sprinkled across the content-suite features. |
| 12 |
* |
| 13 |
* @since 4.4.0 |
| 14 |
*/ |
| 15 |
interface AIProvider { |
| 16 |
|
| 17 |
/** |
| 18 |
* Stable platform identifier stored in settings, e.g. 'openai'. |
| 19 |
* |
| 20 |
* @return string |
| 21 |
*/ |
| 22 |
public function id(); |
| 23 |
|
| 24 |
/** |
| 25 |
* Human-readable platform name for the UI, e.g. 'OpenAI'. |
| 26 |
* |
| 27 |
* @return string |
| 28 |
*/ |
| 29 |
public function label(); |
| 30 |
|
| 31 |
/** |
| 32 |
* Send a chat-completion request. |
| 33 |
* |
| 34 |
* Messages use the normalized shape: |
| 35 |
* array( array( 'role' => 'system'|'user'|'assistant', 'content' => string ), … ) |
| 36 |
* |
| 37 |
* Options (all optional): |
| 38 |
* - model string Overrides the provider's configured model. |
| 39 |
* - max_tokens int Output cap (floored by the feature min-token policy). |
| 40 |
* - temperature float Sampling temperature (ignored where unsupported). |
| 41 |
* - context string Feature key for min-token enforcement, e.g. 'write_with_ai'. |
| 42 |
* - timeout int Request timeout in seconds. |
| 43 |
* |
| 44 |
* On success returns the normalized result: |
| 45 |
* array( |
| 46 |
* 'success' => true, |
| 47 |
* 'content' => string, |
| 48 |
* 'model' => string, |
| 49 |
* 'usage' => array( 'prompt_tokens'=>int|null, 'completion_tokens'=>int|null, 'total_tokens'=>int|null ), |
| 50 |
* 'finish_reason' => string|null, |
| 51 |
* ) |
| 52 |
* |
| 53 |
* @param array $messages |
| 54 |
* @param array $options |
| 55 |
* @return array|\WP_Error Normalized result or a WP_Error on failure. |
| 56 |
*/ |
| 57 |
public function chat( $messages, $options = array() ); |
| 58 |
|
| 59 |
/** |
| 60 |
* Validate an API key against the platform. |
| 61 |
* |
| 62 |
* @param string $api_key Key to test; falls back to the configured key when empty. |
| 63 |
* @return array array( 'valid' => bool, 'message' => string ) |
| 64 |
*/ |
| 65 |
public function validate_key( $api_key = '' ); |
| 66 |
|
| 67 |
/** |
| 68 |
* Curated model list for this platform. |
| 69 |
* |
| 70 |
* @return array<string,string> model_id => label |
| 71 |
*/ |
| 72 |
public function models(); |
| 73 |
|
| 74 |
/** |
| 75 |
* Default model id for this platform. |
| 76 |
* |
| 77 |
* @return string |
| 78 |
*/ |
| 79 |
public function default_model(); |
| 80 |
} |
| 81 |
|