PHP 애플리케이션에 AI 제공자를 통합해 본 적이 있다면, 과정을 알고 있습니다. OpenAI SDK를 가져옵니다. 그런 다음 클라이언트가 이미지 생성을 원하므로 StabilityAI를 추가합니다 — 다른 SDK, 다른 요청 형식, 다른 오류 처리. 그런 다음 오디오 녹음을 원합니다 — Deepgram을 입력하면 또 다른 통합이 필요합니다. 이전에 알지 못했을 때, 세 가지 개별 API 통합을 유지하고 있으며, 각각 고유한 특징, 응답 형식, 재시도 논리가 있습니다.
Prisma는 이를 해결합니다. 하나의 패키지. 하나의 API. 25개 이상의 제공자. 텍스트, 이미지, 오디오, 비디오.
composer require aimeos/prisma
Prisma는 무엇인가요?
Prisma는 경량의 MIT 라이선스를 가진 PHP 패키지로, 네 가지 미디어 도메인에 걸쳐 AI 제공자와 작업하기 위한 통일된 인터페이스를 제공합니다. 프레임워크 결합 없이, 하드웨어에 Guzzle가 있으며, PHP 8.2+와 깨끗한 fluently 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}(). 단일 문자열을 변경하여 공급자를 전환합니다. 애플리케이션 코드는 동일하게 유지됩니다.
실제로 이것이 왜 중요한가요
제품 목록 도구를 만들고 있다고 상상해보세요. 다음을 수행해야 합니다.
- 이미지에서 제품 설명을 생성합니다.
- 제품 설명에서 구조화된 데이터(이름, 가격, 카테고리)를 추출합니다.
- 결측된 마케팅 이미지를 생성합니다.
Prisma가 없다면, 세 가지 다른 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();
세 제공자, 세 미디어 유형, 일관된 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에서 텍스트 제공자에 대해 지원되는 내용은 다음과 같습니다:
| Provider | 구조화 | 번역 | 쓰기 | 참조 | 커스텀 도구 | Provider 도구 | 생각 예산 |
|---|---|---|---|---|---|---|---|
| Alibaba | 네 | 네 | - | 네 | 네 | - | |
| Anthropic | 예 | 예 | 예 | 예 | 예 | 예 | |
| Bedrock | 예 | 예 | - | 예 | 예 | ||
| Cohere | 예 | 예 | - | 예 | - | ||
| Deepseek | 예 | 예 | - | 예 | - | ||
| DeepL | 예 | ||||||
| Gemini | 예 | 예 | 예 | 예 | 예 | 예 | |
| 예 | |||||||
| Groq | 예 | 예 | - | 예 | - | ||
| Mistral | 예 | 예 | - | 예 | 예 | - | |
| Ollama | 베타 | 베타 | - | 예 | - | ||
| OpenAI | 예 | 예 | 예 | 예 | 예 | 예 | |
| Openrouter | 예 | 예 | - | 예 | 예 | - | |
| Perplexity | 베타 | 베타 | 예 | 예 | - | ||
| xAI | 베타 | 베타 | 예 | 예 | 예 | 예 |
그것도 텍스트일 뿐입니다. Prisma는 9 오디오 제공자 (speak, transcribe, demix, denoise, revoice, describe), 14 이미지 제공자 (imagine, inpaint, upscale, vectorize, background, erase, 그리고 더 많은 것들), 그리고 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);
서비스 제공자가 없고, 구성 파일이 없으며, 프레임워크 종속성이 없습니다. 단지 필요한 것을 가져와 사용하세요.
Prisma는 MIT 라이선스로 개방 소스입니다. 더 알아보세요:
PHP에서 AI 제공자와 통합된 방법을 찾고 계신다면 — 특히 텍스트 외의 것까지 — 시도해 보세요. 피드백, 문제, 그리고 별은 모두 환영합니다.
Prisma를 좋아하신다면, Github 저장소에 별을 남겨주세요 :-)










