Files
prautoblogger/includes/providers/interface-llm-provider.php
peptiderepo b5cbbef804 feat: v0.2.1 — fix encryption, diverse multi-topic generation, UX fixes
- Rewrite encryption with "enc:" prefix to permanently eliminate
  the double-encryption bug on settings save
- Add one-time migration to clear legacy non-prefixed encrypted values
- Rewrite content analyzer prompts to request N distinct diverse topics
  across 5 categories (question, complaint, comparison, news, guide)
- Pass target_count*2 from pipeline to analyzer for headroom
- Add skip_dedup flag so manual Generate Now always produces content
- Generate Now button now sends force=1 to clear stale locks
- Rename OpenRouter provider files to PSR-4 convention (hyphenated)
- Switch default models to google/gemini-2.5-flash-lite
- Clean up reddit_debug log channel to standard 'reddit'
- Bump version to 0.2.1

Cost: ~$0.003/article with Gemini 2.0 Flash, ~34s pipeline.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-04-12 13:36:36 +07:00

72 lines
2.3 KiB
PHP
Executable File

<?php
declare(strict_types=1);
/**
* Contract for any LLM provider integration (OpenRouter, direct Anthropic, OpenAI, etc.).
*
* Any class implementing this interface can be swapped in without changing the
* content generation, analysis, or editor logic.
*
* @see class-open-router-provider.php — Primary implementation (OpenRouter).
* @see CONVENTIONS.md — "How To: Add a New LLM Provider".
* @see ARCHITECTURE.md — External API integrations table.
*/
interface PRAutoBlogger_LLM_Provider_Interface {
/**
* Send a chat completion request to the LLM.
*
* @param array<int, array{role: string, content: string}> $messages Chat messages array.
* @param string $model Model identifier (e.g., 'anthropic/claude-sonnet-4').
* @param array{
* temperature?: float,
* max_tokens?: int,
* response_format?: array{type: string},
* } $options Optional parameters for the API call.
*
* @return array{
* content: string,
* model: string,
* prompt_tokens: int,
* completion_tokens: int,
* total_tokens: int,
* finish_reason: string,
* } Normalized response.
*
* @throws \RuntimeException On API error after retries exhausted.
*/
public function send_chat_completion( array $messages, string $model, array $options = [] ): array;
/**
* Get the list of available models from the provider.
*
* @return array<int, array{id: string, name: string, context_length: int, pricing: array{prompt: float, completion: float}}> Available models.
*/
public function get_available_models(): array;
/**
* Estimate the cost of an API call based on token counts.
*
* @param string $model Model identifier.
* @param int $prompt_tokens Number of input tokens.
* @param int $completion_tokens Number of output tokens.
*
* @return float Estimated cost in USD.
*/
public function estimate_cost( string $model, int $prompt_tokens, int $completion_tokens ): float;
/**
* Get the human-readable name of this provider.
*
* @return string Provider name (e.g., 'OpenRouter').
*/
public function get_provider_name(): string;
/**
* Validate that the provider's credentials are configured and working.
*
* @return bool True if credentials are valid.
*/
public function validate_credentials(): bool;
}