慣性聚合 関心のあるブログ、ニュース、テクノロジーを効率的に追跡
原文を読む 慣性聚合で開く

おすすめ購読元

V
V2EX
博客园 - 叶小钗
Y
Y Combinator Blog
大猫的无限游戏
大猫的无限游戏
博客园 - 【当耐特】
酷 壳 – CoolShell
酷 壳 – CoolShell
D
Docker
WordPress大学
WordPress大学
Blog — PlanetScale
Blog — PlanetScale
博客园 - Franky
G
Google Developers Blog
爱范儿
爱范儿
Google DeepMind News
Google DeepMind News
Stack Overflow Blog
Stack Overflow Blog
云风的 BLOG
云风的 BLOG
Engineering at Meta
Engineering at Meta
aimingoo的专栏
aimingoo的专栏
V
Visual Studio Blog
M
MIT News - Artificial intelligence
Hugging Face - Blog
Hugging Face - Blog

DEV Community

Authentication Security Deep Dive: From Brute Force to Salted Hashing (With Java Examples) Why AI Systems Don’t Fail — They Drift Spilling beans for how i learn for exam😁"Reinforcement Learning Cheat Sheet" I Replaced Chrome with Safari for AI Browser Automation. Here's What Broke (and What Finally Worked) How Python Borrows Other People's Work The $40 Architecture: Processing 1 Billion API Requests with 99.99% Uptime Vibe Coding: A Workflow Guide (From Zero to SaaS) Most webhook security guides protect the wrong side. The scary part is delivery. Headless CMS for TanStack Start: Build a Blog with Cosmic EU Age Verification App "Hacked in 2 Minutes" — What Actually Happened Comfy Cloud’s delete function does not actually remove files Running AI Models on GPU Cloud Servers: A Beginner Guide Event-driven media intelligence with AWS Step Functions and Bedrock I scored 500 AI prompts across 8 quality dimensions — here's what broke How to Call Google Gemini API from Next.js (Free Tier, No Backend Needed) The Portal Protocol: Reclaiming Human Connection in the Age of AI How to Fix Your Team's Scattered Knowledge Problem With a Self-Hosted Forum Intro to tc Cloud Functors: A Graph-First Mental Model for the Modern Cloud Designing Multi-Tenant Backends With Both Ownership and Team Access I Built a Neumorphic CSS Library with 77+ Components — Here's What I Learned PostgreSQL Performance Optimization: Why Connection Pooling Is Critical at Scale Cómo construí un SaaS multi-rubro para gestionar expensas en Argentina con FastAPI + Vue 3 🚀 I Built an Ethical Hacking Scanner Tool – Open Source Project I Replaced /usage and /context in Claude Code With a Single Statusline A Pythonic Way to Handle Emails (IMAP/SMTP) with Auto-Discovery and AI-Ready Design I Collected 8.9 Million Polymarket Price Points — Here's What I Found About How Markets Really Move EcoTrack AI — Carbon Footprint Tracker & Dashboard Everyone's Using AI. No One Agrees How. 5 self-hosted ebook managers worth trying in 2026 Building Your First AI Agent with LangChain: From Chatbot to Autonomous Assistant Common SOC 2 Failures (Real World) Stop Vibe-Checking Your AI App: A Practical Guide to Evals How to Use SonarQube and SonarScanner Locally to Level Up Your Code Quality Your Next To-Do App Is Dead — I Replaced Mine with an OpenClaw AI Sign a Nostr event in 60 lines of Python using coincurve — no nostr-sdk, no nbxplorer, no rust toolchain ITGC Audit Explained Like You’re in Big 4 Patch Tuesday abril 2026: Microsoft parcha 163 vulnerabilidades y un zero-day en SharePoint Stop scraping everything: a better way to track competitor price changes Listing on MCPize + the Official MCP Registry while routing payments OUTSIDE the marketplace — how I kept 100% of my x402 revenue Building an AI-Powered Risk Intelligence System Using Serverless Architecture Why We Ripped Function Overloading Out of Our AI Toolchain Testing AI-Generated Code: How to Actually Know If It Works SaaS Churn Is Killing Your Business. Here Is What to Do About It (Without a Support Team) The Speed of AI Is No Longer Linear - And Self-Improving Models Are Why How to Implement RBAC for MCP Tools: A Practical Guide for Engineering Teams From Standard Quote to Persuasive Proposal: AI Automation for Arborists I built a CLI that scaffolds complete multi-tenant SaaS apps Axios CVE-2025–62718: The Silent SSRF Bug That Could Be Hiding in Your Node.js App Right Now The dashboard that ended our friendship Data Pipelines Explained Simply (and How to Build Them with Python)
PHPでAI SDKのバランスを取るのをやめ、Prismaに会いなさい
Aimeos · 2026-05-22 · via DEV Community

AIプロバイダをPHPアプリケーションに統合したことがあるなら、そのプロセスはおそらくご存知でしょう。OpenAI SDKを取り込みます。その後、クライアントが画像生成を要求するので、StabilityAIを追加します——異なるSDK、異なるリクエスト形式、異なるエラーハンドリング。次に、音声認識を要求するので、Deepgramを導入します——また別の統合。あっという間に、それぞれ異なる特徴、レスポンス形式、リトライロジックを持つ3つの独立したAPI統合をメンテナンスすることに。

Prismaはこれを修正します.一つのパッケージ。一つのAPI。25以上のプロバイダー。テキスト、画像、オーディオ、ビデオ.

composer require aimeos/prisma

フルスクリーンモードに入る フルスクリーンモードから退出する

Prismaとは何ですか?

Prisma軽量でMITライセンスのPHPパッケージで、4つのメディアドメインのAIプロバイダーと連携するための統一インターフェースを提供しています。フレームワークの結合はありません。Guzzleが下で動いており、PHP 8.2以降とクリーンなフラットAPIです。

ここに核心的な考え方があります——すべてのプロバイダは同じインターフェースを通じて動作します:

use Aimeos\Prisma\Prisma;

// Generate text with OpenAI
$text = Prisma::text()
    ->using('openai', ['api_key' => '...'])
    ->write('Summarize the benefits of renewable energy')
    ->text();

// Generate an image with StabilityAI
$image = Prisma::image()
    ->using('stabilityai', ['api_key' => '...'])
    ->imagine('a mountain landscape at sunset')
    ->binary();

// Transcribe audio with Deepgram
$transcript = Prisma::audio()
    ->using('deepgram', ['api_key' => '...'])
    ->transcribe($audioFile)
    ->text();

// Describe a video with Gemini
$description = Prisma::video()
    ->using('gemini', ['api_key' => '...'])
    ->describe($videoFile)
    ->text();

フルスクリーンモードに入る フルスクリーンモードを終了する

同じパターンがどこにでも見られます:Prisma::{domain}()->using(provider, config)->{method}(). 1つの文字列を変更してプロバイダを切り替えます。アプリケーションコードはそのままです。

実践でこれが重要な理由

製品リストツールを作成していると想像してください。次のことが必要です:

  1. 画像から製品の説明文を生成
  2. 説明文から構造化データ(名前、価格、カテゴリ)を抽出
  3. 欠落しているマーケティング画像を生成

Prismaを使用しないと、それは3つの異なるSDK統合です。Prismaを使用すると:

use Aimeos\Prisma\Prisma;
use Aimeos\Prisma\Schema\Schema;

// 1. Describe a product image
$description = Prisma::image()
    ->using('openai', ['api_key' => '...'])
    ->describe($productPhoto)
    ->text();

// 2. Extract structured data
$schema = Schema::for('product', [
    'name' => Schema::string()->required(),
    'price' => Schema::number(),
    'category' => Schema::string()->enum(['electronics', 'clothing', 'food', 'other']),
]);

$product = Prisma::text()
    ->using('gemini', ['api_key' => '...'])
    ->structured("Extract product info from: {$description}", $schema)
    ->structured();
// ['name' => 'Wireless Headphones', 'price' => 79.99, 'category' => 'electronics']

// 3. Generate a product image
$image = Prisma::image()
    ->using('stabilityai', ['api_key' => '...'])
    ->imagine("Professional illustration of {$product['name']}")
    ->binary();

フルスクリーンモードを開始 フルスクリーンモードを終了

3つのプロバイダー、3つのメディアタイプ、一貫したAPI。そして明日、GeminiをAnthropicに交換したいなら、一行を変更するだけでよい。

プロバイダーの機能を実行時に確認することもできます:

$provider = Prisma::image()->using('clipdrop', ['api_key' => '...']);

if ($provider->has('upscale')) {
    $image = $provider->upscale($lowResImage)->binary();
}

// Or throw if the capability is missing
$provider->ensure('upscale'); // throws NotImplementedException if not supported

フルスクリーンモードを開始 フルスクリーンモードを終了

0.4の新機能

バージョン0.4は、テキスト生成、構造化出力、ツール呼び出し、多くの追加機能を含むメジャーリリースです。以下に追加された内容があります.

14のプロバイダー間のテキスト生成

Thewrite()このメソッドは、OpenAI、Anthropic、Gemini、Bedrock、Mistral、Groq、Cohere、Deepseek、Alibaba、xAI、Perplexity、OpenRouter、Ollama、およびDeepseekにテキスト生成をサポートしてPrismaに導入します。すべての多モーダル — プロンプトと一緒に画像、音声、または文書を渡すことができます。

use Aimeos\Prisma\Base\File;

$response = Prisma::text()
    ->using('anthropic', ['api_key' => '...'])
    ->withSystemPrompt('You are a helpful assistant')
    ->write('Describe this image', [File::from('photo.jpg')]);

echo $response->text();

フルスクリーンモードに入る フルスクリーンモードを終了する

構造化された出力

LLMから流暢なスキーマビルダーを使用してタイプ付きJSONレスポンスを取得します。Prismaは各プロバイダのネイティブ構造化出力APIを使用します—プロンプトエンジニアリングのハックは不要です:

use Aimeos\Prisma\Schema\Schema;

$schema = Schema::for('event', [
    'title' => Schema::string()->required(),
    'date' => Schema::string()->format('date')->required(),
    'attendees' => Schema::array()->items(Schema::string()),
    'location' => Schema::object([
        'city' => Schema::string()->required(),
        'country' => Schema::string(),
    ]),
]);

$response = Prisma::text()
    ->using('openai', ['api_key' => '...'])
    ->structured('Parse: Team meetup on June 15 in Berlin with Alice and Bob', $schema);

$event = $response->structured();
// [
//     'title' => 'Team meetup',
//     'date' => '2026-06-15',
//     'attendees' => ['Alice', 'Bob'],
//     'location' => ['city' => 'Berlin', 'country' => 'Germany'],
// ]

フルスクリーンモードを入力 フルスクリーンモードを退出

スキーマビルダーは文字列、整数、数値、ブーリアン、配列、オブジェクト、列挙型(PHPのBackedEnumを含む)、ネストされたオブジェクトをサポートしますrequired()nullable()min()/max()、正規表現pattern()、その他も含めます。生のJSONスキーマ配列もSchema::fromArray()を介して渡すことができます.

ツール呼び出しは自動実行されます

面白い部分に出会います。Prismaは自動実行ループを備えた完全なエージェントツール呼び出しをサポートしています。ツールを定義し、モデルがそれらを呼び出し、Prismaがハンドラを実行して結果をフィードバックする——すべて自動的に:

use Aimeos\Prisma\Tools;
use Aimeos\Prisma\Schema\Schema;

$searchTool = Tools::make(
    'search_products',
    'Search the product database',
    Schema::for('search', [
        'query' => Schema::string()->description('Search query')->required(),
        'limit' => Schema::integer()->description('Max results')->min(1)->max(50),
    ]),
    function(array $args): string {
        $results = ProductSearch::query($args['query'], $args['limit'] ?? 10);
        return json_encode($results);
    }
);

$response = Prisma::text()
    ->using('openai', ['api_key' => '...'])
    ->withTools([$searchTool])
    ->withMaxSteps(5)
    ->write('Find me the top 3 wireless headphones under $100');

echo $response->text();
// The model searched, got results, and wrote a summary

フルスクリーンモードに入る フルスクリーンモードから退出する

ツールループ中に何が起こったかを確認できます:

foreach ($response->steps() as $step) {
    echo $step->name();      // 'search_products'
    echo $step->arguments(); // ['query' => 'wireless headphones', 'limit' => 3]
    echo $step->result();    // '[ ... search results ... ]'
}

フルスクリーンモードに入る フルスクリーンモードを終了

ツールもサポートしています:

  • 各ツールの呼び出し制限: Tools::make(...)->max(3) — ツールは最大3回まで呼び出せます
  • カスタムエラーハンドラ: ->failed(fn($e, $args) => 'Fallback message') — 例外を優雅に捕捉
  • 並列実行: ->concurrent() — ツールが並列で実行されますpcntl_fork
  • デコレータ:ロギングやキャッシング、または任意のカスタム挙動でツールをラップします
  • ツールの選択->withToolChoice(Provider::REQ)を使用を強制

プロバイダツール

一部のプロバイダはウェブ検索やコード実行などのサーバーサイドツールを提供しています。Prismaもこれらを標準化します

use Aimeos\Prisma\Tools;

$response = Prisma::text()
    ->using('anthropic', ['api_key' => '...'])
    ->withTools([
        Tools::provider('web_search'),
        Tools::provider('code_execution'),
    ])
    ->write('Search for the latest PHP version and verify it');

フルスクリーンモードに入る フルスクリーンモードから退出する

利用可能なプロバイダツールにはweb_search,code_execution,file_search,web_fetch,image_generation、そしてdocument_library— それぞれがそれをサポートするプロバイダにマッピングされます。同じリクエスト内でカスタムおよびプロバイダツールを組み合わせることができます。

フレームワークツールアダプタ

Laravel AI または Symfony のためのツールは既に構築済みですか?直接再利用してください:

// Laravel AI / Prism tools
$tool = Tools::laravel(new MyLaravelTool());

// Symfony #[AsTool] classes
$tool = Tools::symfony(MySymfonyTool::class);

フルスクリーンモードを開始 フルスクリーンモードを終了

費用計画を考える

それに対応しているモデルには拡張推論を有効にします。Prismaはトークン数を各プロバイダーのネイティブ形式に自動的にマッピングします:

$response = Prisma::text()
    ->using('anthropic', ['api_key' => '...'])
    ->withThinkingBudget(5000)
    ->withMaxTokens(4096)
    ->write('Solve this step by step: ...');

// Access the model's reasoning
$thinking = $response->meta()['thinking'] ?? null;

フルスクリーンモードを開始 フルスクリーンモードを終了

引用

プロバイダーでサポートされている(Anthropic、OpenAI、Gemini、Perplexity、xAI)の正規化された引用オブジェクト:

foreach ($response->citations() as $citation) {
    $citation->title();  // source title
    $citation->url();    // source URL
    $citation->text();   // output text that cites this source
    $citation->source(); // verbatim quote from the source
}

フルスクリーンモードに入る フルスクリーンモードから退出する

レートリミットとリトライ処理

// Automatic retry with exponential backoff
$response = Prisma::text()
    ->using('openai', ['api_key' => '...'])
    ->withClientRetry(3, fn($attempt, $resp) => 100 * pow(2, $attempt))
    ->write('...');

// Inspect rate limit headers
$limit = $response->rateLimit();
$limit->remaining();  // requests left
$limit->retryAfter(); // seconds until reset

フルスクリーンモードに入る フルスクリーンモードから退出する

プロバイダーのカバレッジ

0.4でテキストプロバイダーにサポートされているものは以下の通り:

プロバイダ 構造化 翻訳 書き込み 出典 カスタムツール プロバイダツール 思考予算
Alibaba はい はい - はい はい -
アンソプティック はい はい はい はい はい はい
ベドロック はい はい - はい はい
コアハイ はい はい - はい -
Deepseek はい はい - はい -
DeepL はい
Gemini はい はい はい はい はい はい
Google はい
Groq はい はい - はい -
Mistral はい はい - はい はい -
Ollama ベータ ベータ - はい -
OpenAI はい はい はい はい はい はい
Openrouter はい はい - はい はい -
Perplexity ベータ ベータ はい はい -
xAI ベータ ベータ はい はい はい はい

はただのテキストです。Prismaはまた、9オーディオプロバイダー(話す、転写、デミックス、ノイズ除去、リボーカー、説明)、14画像プロバイダー(想像、インペイント、アップスケール、ベクタライズ、背景除去、さらに多くのもの)、およびビデオ説明をGeminiを通じて提供します.

スタートアップ

composer require aimeos/prisma

フルスクリーンモードを開始 フルスクリーンモードを終了

最小限の例:

<?php

use Aimeos\Prisma\Prisma;

// Text
echo Prisma::text()
    ->using('openai', ['api_key' => getenv('OPENAI_API_KEY')])
    ->write('What makes PHP great?')
    ->text();

// Image
$binary = Prisma::image()
    ->using('openai', ['api_key' => getenv('OPENAI_API_KEY')])
    ->imagine('a PHP elephant wearing sunglasses')
    ->binary();

file_put_contents('elephant.png', $binary);

フルスクリーンモードを開始 フルスクリーンモードを終了

サービスプロバイダがなく、設定ファイルがなく、フレームワークの依存関係もない。ただし、requireして使用するだけ.


PrismaはMITライセンスでオープンソースです。詳細はこちらをご覧ください:

PHPでAIプロバイダーと統合的に作業する方法を探しているなら——特にテキストだけではなく——試してみてください。フィードバック、問題報告、スターログはすべて歓迎します.

Prismaが好きなら、Githubリポジトリに星を付けてください :-)