Search by

dmlab / module-typesafe-core

dmlab

TypeSafe (Jev) AI client for Magento 2: shared connection with your own encrypted API key, response cache, monthly token budget, retries and rate limiting.

Package info

github.com/dmlab-work/module-typesafe-core

Type:magento2-module

pkg:composer/dmlab/module-typesafe-core

Statistics

Installs: 3

Dependents: 1

Suggesters: 0

Stars: 0

Open Issues: 0

0.0.1 2026-10-20 09:58 UTC

This package is auto-updated.

Last update: 2026-10-20 10:04:39 UTC


README

TypeSafe (Jev) AI client for Magento 2 — one connection, cache and token budget shared by every DMLab AI module.

CI codecov Packagist Version Downloads PHP License Magento

TypeSafe answers structured questions about text — yes/no, pick one of N options, score on a scale — with calibrated probabilities instead of free-form output, at $0.042 per 1M input tokens. This module connects Magento to it. You usually get it as a dependency of a module that uses it, such as Catalog Enrich (fills empty product attributes from descriptions); on its own it adds no storefront or catalog behaviour.

TypeSafe settings

What you get

  • Your own key — register at console.typesafe.ai and pay TypeSafe directly. The key is stored encrypted in Magento; we never see it.
  • Settings in one place — enable, API key, pinned model version (jev-1.13.0), Test Connection.
  • Spend control — a monthly token budget with this month's usage and cost shown under the field; a response cache so the same question is never paid for twice.
  • Resilience — parallel requests, retries with backoff, rate-limit pauses and a circuit breaker, so an API hiccup never floods the API or your logs.

Install

composer require dmlab/module-typesafe-core
bin/magento setup:upgrade

Magento 2.4.9+, PHP 8.3–8.5 with ext-curl. Then Stores → Configuration → DMLab → TypeSafe: enable, paste the key, Test Connection.

bin/magento dmlab:typesafe:ping                     # check the connection
bin/magento dmlab:typesafe:usage [--month=YYYY-MM]  # requests, cache hits, tokens and cost per module

For developers

$response = $client->evaluate(new Request(          // DmLab\TypeSafeCore\Api\ClientInterface
    ['title' => 'Merino wool crew sweater', 'description' => '…'],
    [
        'is_apparel' => new NoulQuestion('Is this product clothing?'),
        'material' => new ChoiceQuestion('Main material', ['wool' => null, 'cotton' => null, 'synthetic' => null]),
    ],
    'my_module' // usage is accounted per consumer
));
$response->getAnswer('is_apparel')->getProbability(); // 0..1
$response->getAnswer('material')->getChoice();        // 'wool', with getConfidence()

evaluateMany() sends a batch in parallel and returns a Response or a TypeSafeException per key; it never throws. Use Api\ConfigInterface::isConfigured() / getModel() instead of your own settings, and Api\UsageInterface for the remaining budget.

Data and privacy

Only the text a consuming module puts into a request is sent to TypeSafe (US-hosted API). Request and response content is never logged. Zero data retention is available on TypeSafe's enterprise plan.

License

OSL-3.0