feat(replicate): add complete Replicate provider with all features #757
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Pull Request: Complete Replicate Provider Implementation
Summary
This PR adds complete support for the Replicate provider to Prism, including all core features: text generation, streaming, structured output, embeddings, image generation, and audio (TTS/STT). This brings Replicate support to production-ready status.
What Changed
Complete Provider Implementation
This PR implements the Replicate provider from scratch with all major features:
Text Generation (
src/Providers/Replicate/Handlers/Text.php)Streaming (
src/Providers/Replicate/Handlers/Stream.php)Structured Output (
src/Providers/Replicate/Handlers/Structured.php)Embeddings (
src/Providers/Replicate/Handlers/Embeddings.php)Image Generation (
src/Providers/Replicate/Handlers/Images.php)Audio (
src/Providers/Replicate/Handlers/Audio.php)Core Infrastructure
Provider Class (
src/Providers/Replicate/Replicate.php)Prediction Handling (
src/Providers/Replicate/Concerns/HandlesPredictions.php)Prefer: waitheader for lower latencyMessage Mapping (
src/Providers/Replicate/Maps/MessageMap.php)Additional Improvements
While implementing the provider, we standardized model version handling across all handlers:
Testing
21 comprehensive tests covering all features:
Audio Tests (5 tests)
Embeddings Tests (3 tests)
Image Tests (3 tests)
Text Tests (3 tests)
Stream Tests (4 tests)
SSE Stream Integration Tests (3 tests)
Structured Output Tests (3 tests)
Test Results:
Implementation Approach
Async Prediction Management
Replicate uses an asynchronous prediction-based architecture. Prism handles this transparently:
Prefer: waitheader for lower latencySSE Streaming
Replicate uses Server-Sent Events (SSE) for streaming, which required:
Features Supported
Core Functionality
Quality Features
Example Usage
Text Generation
Streaming
Structured Output
Image Generation
Embeddings
Audio (TTS)
Audio (STT)
Files Changed
Core Provider Files:
src/Providers/Replicate/Replicate.php(provider class)src/Providers/Replicate/Concerns/HandlesPredictions.php(async predictions)src/PrismManager.php(register provider)config/prism.php(add provider config)Handlers (6 files):
src/Providers/Replicate/Handlers/Text.phpsrc/Providers/Replicate/Handlers/Stream.phpsrc/Providers/Replicate/Handlers/Structured.phpsrc/Providers/Replicate/Handlers/Embeddings.phpsrc/Providers/Replicate/Handlers/Images.phpsrc/Providers/Replicate/Handlers/Audio.phpMappers (2 files):
src/Providers/Replicate/Maps/MessageMap.phpsrc/Providers/Replicate/Maps/FinishReasonMap.phpValue Objects:
src/Providers/Replicate/ValueObjects/ReplicatePrediction.phpTests (21 tests across 7 test files):
tests/Providers/Replicate/ReplicateTextTest.phptests/Providers/Replicate/ReplicateStreamTest.phptests/Providers/Replicate/ReplicateSSEStreamTest.phptests/Providers/Replicate/ReplicateStructuredTest.phptests/Providers/Replicate/ReplicateEmbeddingsTest.phptests/Providers/Replicate/ReplicateImagesTest.phptests/Providers/Replicate/ReplicateAudioTest.phpFixtures:
Documentation:
docs/providers/replicate.md(455 lines of comprehensive documentation)Code Quality
Backward Compatibility
Provider Feature Matrix
Result: 7/7 core features fully implemented 🎉
Testing
All test categories passing:
Checklist
Note: This is a complete provider implementation validated with real Replicate API testing. Tool calling is not supported as Replicate does not have a native tool calling API, and prompt engineering approaches were not reliable enough for production use.