feat(replicate): add language model support #10854
Open
+418
−20
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.
Adds language model support to Replicate provider with support for popular models including Meta Llama 3.x, Mistral, DeepSeek, and Qwen.
Fixes #10257
Background
Replicate has been adding many language models (Meta Llama 3.x, Mistral, DeepSeek, etc.) that weren't supported in the AI SDK. The Replicate provider only supported image generation, nd the
languageModel()method threw aNoSuchModelError. This prevented users/developers from using Replicate's extensive catalog of language models through the AI SDK.Summary
This PR adds comprehensive language model support to the Replicate provider by:
ReplicateLanguageModelclass that implementsLanguageModelV3ReplicateLanguageModelIdtype with 20+ popular models pre-configured ( open for reviewers to change later )doGenerate()for non-streaming text generation via Replicate's predictions APIdoStream()with basic streaming support (marked as experimental)providerOptions.replicateFiles Changed:
packages/replicate/src/replicate-language-model.ts(new)packages/replicate/src/replicate-language-settings.ts(new) - Model type definitionspackages/replicate/src/replicate-provider.ts(modified) - Added languageModel() methodpackages/replicate/src/index.ts(modified) - Exported new typespackages/replicate/README.md(modified) - Added language model documentationVerification Steps:
✅ Built the package successfully:
pnpm --filter @ai-sdk/replicate build # Build completed with no errors✅ Verified module exports and types:
returns proper model instance
methods: doGenerate, doStream, supportedUrls
✅ Tested with multiple model IDs:
✅ Verified backward compatibility:
✅ Verified error handling:
✅ Ran quality checks:
Checklist
pnpm changesetin the project root)Note on testing: Automated unit tests have not been added yet. The implementation has been manually tested. I'm happy to add unit tests following the patterns in
replicate-image-model.test.tsif the maintainers would like and my approach and is correct!!!Future Work
I believe following enhancements could be added in future PRs if desired:
ReplicateLanguageModelIdas new models are released (also reviewers can change existing models as well