Overview
Replicate provides on-demand inference for open-source LLMs including Llama, Mistral, and other models. The provider implements custom prompt formatting for different model families.Installation
Basic Usage
Constructor Options
keyof typeof ALL_AVAILABLE_REPLICATE_MODELS
default:"llama-3-70b-instruct"
Replicate model name from available models
number
Sampling temperature (minimum 0.01 for Replicate)
number
default:1
Nucleus sampling parameter (Llama 3 defaults to 0.9)
number
Maximum tokens in response (defaults to model’s context window)
ReplicateChatStrategy
Chat prompt formatting strategy (auto-detected from model)
ReplicateSession
Custom Replicate session with API token
boolean
Suppress default model warning
Supported Models
Llama 3
llama-3-70b-instruct: 70B parameter, 8K context (default)llama-3-8b-instruct: 8B parameter, 8K context
Llama 2
Llama-2-70b-chat-4bit: 70B 4-bit quantized, 4K contextLlama-2-70b-chat-old: 70B old version, 4K contextLlama-2-13b-chat-4bit: 13B 4-bit quantized, 4K contextLlama-2-13b-chat-old: 13B old version, 4K contextLlama-2-7b-chat-4bit: 7B 4-bit quantized, 4K contextLlama-2-7b-chat-old: 7B old version, 4K context
Chat Strategies
Replicate uses different prompt formats for different model versions:LLAMA3: Llama 3 format with special tokensMETA: Standard Llama 2 formatMETAWBOS: Llama 2 with BOS/EOS tokensA16Z: A16Z-Infra formatREPLICATE4BIT: 4-bit model formatREPLICATE4BITWNEWLINES: 4-bit format with newlines
Streaming
Custom API Token
With LlamaIndex
Convenience Function
Configuration
Environment Variables
Global Settings
Model Metadata
Access model information:System Messages
System messages are handled differently based on chat strategy:Model Selection Guide
Performance Considerations
- Cold starts: First request may take longer
- Streaming: Better UX for long responses
- 4-bit models: Faster but slightly lower quality
- Context window: Llama 3 has 8K, Llama 2 has 4K
Error Handling
Legacy Aliases
For backwards compatibility:Advanced: Custom Prompt Formatting
The provider handles complex prompt formatting automatically:Best Practices
- Use Llama 3 for new projects: Better quality and 8K context
- Set appropriate maxTokens: Default can be high, adjust for your use case
- Handle cold starts: First request takes longer, consider warming up
- Use streaming: Better UX for chat applications
- Choose right model size: Balance quality vs. cost and speed
- Leverage system messages: Properly format instructions