Textstem AI

Textstem uses a large language model for content and site checks. All of it goes through one service, Medialight\Textstem\Services\AiService, which talks to OpenAI or Anthropic. AI Provider Setup covers keys, models and queues.

What it does

  • Writing help: articles, descriptions, teasers, tags and keywords for pages and posts, and JSON-LD for pages.
  • Alt text for uploaded images.
  • SEO and accessibility analysis of pages. See SEO and Accessibility.
  • The admin chat assistant, which can read and change content.
  • Image duplicate checks by vision, when images.comparison_driver is openai (fingerprints are used otherwise).
  • Security audits, which ask the model to assess known CVEs (textstem:security-audit).

Nothing runs until a key is set. The admin's settings screen has a master switch for AI; with it off, AiService::isAvailable() returns false, and features that check it don't run.

Using it in your own code

use Medialight\Textstem\Services\AiService;

$ai = app(AiService::class);

if ($ai->isAvailable()) {
    $summary = $ai->complete(
        prompt: 'Summarise this in one sentence: '.$text,
        feature: 'my_summaries',   // shows in the usage report
        maxTokens: 200,
    );
}

chat() takes a list of messages in OpenAI's format (with optional tool definitions) and returns an LlmResponse with the content and any tool calls. Both methods record tokens and cost in ai_token_usage under the feature you pass.

Prompts

The package's prompts are kept in a prompt library rather than in code, so they can be changed without a deploy. Read one with the Prompt facade:

use Medialight\Textstem\Facades\Prompt;

$text = Prompt::get('assets.alt_text', '', ['language' => 'English']);  // ":language" is replaced

A prompt is looked up in this order, and the first value found wins:

  1. an edit made in the admin (Tools → Prompt Manager), stored as a global option in the prompts group;
  2. the site's override file, resources/prompts/textstem.php;
  3. the package defaults (src/Prompts/defaults.php);
  4. the $default you pass.

Prompt::all() lists every key with its current text.

Usage and cost

Every call is logged to ai_token_usage with its provider, model, feature, user, tokens and estimated cost. Super-admins see the report at Tools → OpenAI Usage. Cost estimates use the prices in the package's resources/llm-pricing.json, which textstem:update-llm-pricing shows and updates.

Adding a provider

Register your own LlmProvider with LlmProviderRegistry; see Custom providers.

esc