Search by

restruct / silverstripe-ai

micschk

AI provider layer for Silverstripe (Anthropic and OpenAI): 'auto' model resolution, a token usage log per call, estimated cost and a monthly cap per feature, CMS-editable prompts with history, variant comparison, a queued-job base; Markdown pages and llms.txt when silverstripe/cms is installed

Package info

github.com/restruct/silverstripe-ai

Documentation

Type:silverstripe-vendormodule

pkg:composer/restruct/silverstripe-ai

Statistics

Installs: 25

Dependents: 0

Suggesters: 1

Stars: 0

Open Issues: 2

1.1.0 2026-12-02 15:58 UTC

This package is auto-updated.

Last update: 2026-12-02 16:01:08 UTC


README

AI provider layer for Silverstripe 5.4 and 6: Anthropic and OpenAI over plain Guzzle, with auto model resolution, a token usage log per call, an estimated cost in euros and a monthly cap per feature, prompts that editors can change in the CMS (with history), a base class for "content in, structured result out" features, a way to compare prompts, models and providers on the same input, and Markdown variants of published pages plus /llms.txt.

Requirements

  • PHP ^8.2
  • Silverstripe framework ^5.4 or ^6, with silverstripe/admin, silverstripe/versioned and symbiote/silverstripe-queuedjobs
  • An Anthropic and/or OpenAI API key
  • silverstripe/cms is optional: without it you get everything except the Markdown pages and /llms.txt

Install

composer require restruct/silverstripe-ai
vendor/bin/sake dev/build flush=1     # SS6: vendor/bin/sake db:build --flush
AI_INTEGRATION_ENABLED=1
AI_INTEGRATION_ANTHROPIC_KEY=sk-ant-...
AI_INTEGRATION_OPENAI_KEY=sk-...

Installing opens no public endpoint and sends nothing until you call it.

Quick start

An analyzer turns content into a structured result:

use Restruct\AI\Provider\AIContentAnalyzer;

class TicketClassifier extends AIContentAnalyzer
{
    private static ?string $ai_feature = 'ticket_classification';   # usage log and cap key
    private static string $anthropic_model = 'auto:haiku';           # newest Haiku

    protected function buildPrompt(string $content, array $context): string
    {
        return "Classify this support ticket. Reply with JSON {\"label\": ...}.\n\n" . $content;
    }

    protected function parseResponse(string $response): array
    {
        return $this->parseJsonResponse($response) ?? [];
    }

    protected function getTypeName(): string
    {
        return 'ticket';
    }
}
Restruct\AI\Usage\AIUsageGuard:
  features:
    ticket_classification: { label: 'Ticket classification', monthly_cap: 10 }   # estimated EUR per month
$result = TicketClassifier::singleton()->analyze($ticketText);

Every call is logged (tokens, model, status, duration; no prompt or reply text) and refused before sending once the feature's monthly cap is reached. The CMS shows usage and estimated cost under AI.

Documentation

A site search and "ask the site" assistant built on this package exists as a separate, private package.

License

MIT, see LICENSE.