-
-
Notifications
You must be signed in to change notification settings - Fork 1
AI Models
Comprehensive guide to supported AI providers and model configuration.
- Supported Providers
- OpenAI
- Anthropic
- xAI (Grok)
- Google Gemini
- Meta (Llama)
- Ollama (Local)
- DeepSeek
- Custom Models
| Provider | Models | API Key | Cost | Speed | Quality |
|---|---|---|---|---|---|
| OpenAI | GPT-4, GPT-3.5 | Required | $$$ | Fast | Excellent |
| Anthropic | Claude 3, 3.5 | Required | $$$ | Fast | Excellent |
| xAI | Grok-1, Grok-2 | Required | $$ | Fast | Good |
| Gemini Pro, Flash | Required | $$ | Very Fast | Excellent | |
| Meta | Llama 3, 3.1 | Required | $ | Medium | Good |
| DeepSeek | DeepSeek V2 | Required | $ | Fast | Good |
| Ollama | Any local model | Optional | Free | Varies | Varies |
| Default | Built-in fallback | None | Free | Instant | Basic |
OpenAI provides the most popular and well-tested models including GPT-4 and GPT-3.5-turbo.
$config = [
'model' => 'openai',
'api_key' => env('OPENAI_API_KEY'),
'model_name' => 'gpt-3.5-turbo', // or gpt-4, gpt-4o, etc.
'endpoint' => 'https://api.openai.com/v1/chat/completions',
'temperature' => 0.7,
'max_tokens' => 1000,
];| Model | Context | Cost | Best For |
|---|---|---|---|
gpt-4o |
128k | High | Complex tasks, reasoning |
gpt-4o-mini |
128k | Medium | General purpose, cost-effective |
gpt-4-turbo |
128k | High | Advanced reasoning, analysis |
gpt-3.5-turbo |
16k | Low | Quick responses, simple tasks |
-
Get API Key:
- Visit OpenAI Platform
- Create new API key
- Add billing information
-
Add to Environment:
OPENAI_API_KEY=sk-your-key-here
-
Configure Model:
use Rumenx\PhpChatbot\Models\OpenAiModel; $model = new OpenAiModel([ 'api_key' => env('OPENAI_API_KEY'), 'model' => 'gpt-3.5-turbo', 'temperature' => 0.7, ]);
$config = [
'model' => 'openai',
'api_key' => env('OPENAI_API_KEY'),
'model_name' => 'gpt-4o',
'temperature' => 0.7, // Creativity (0.0-1.0)
'max_tokens' => 2000, // Response length
'top_p' => 1.0, // Nucleus sampling
'frequency_penalty' => 0, // Reduce repetition
'presence_penalty' => 0, // Encourage new topics
];Anthropic's Claude models are known for helpful, harmless, and honest responses.
$config = [
'model' => 'anthropic',
'api_key' => env('ANTHROPIC_API_KEY'),
'model_name' => 'claude-3-sonnet-20240229',
'endpoint' => 'https://api.anthropic.com/v1/messages',
'temperature' => 0.7,
'max_tokens' => 1000,
];| Model | Context | Cost | Best For |
|---|---|---|---|
claude-3-opus-20240229 |
200k | High | Complex analysis, creative tasks |
claude-3-sonnet-20240229 |
200k | Medium | Balanced performance |
claude-3-haiku-20240307 |
200k | Low | Fast responses, simple tasks |
-
Get API Key:
- Visit Anthropic Console
- Generate API key
- Set up billing
-
Configure:
ANTHROPIC_API_KEY=your-key-here
-
Use Model:
use Rumenx\PhpChatbot\Models\AnthropicModel; $model = new AnthropicModel([ 'api_key' => env('ANTHROPIC_API_KEY'), 'model' => 'claude-3-sonnet-20240229', ]);
xAI's Grok models provide real-time information and conversational AI.
$config = [
'model' => 'xai',
'api_key' => env('XAI_API_KEY'),
'model_name' => 'grok-beta',
'endpoint' => 'https://api.x.ai/v1/chat/completions',
'temperature' => 0.7,
];| Model | Features | Best For |
|---|---|---|
grok-beta |
Real-time data, web access | Current events, research |
grok-vision-beta |
Image understanding | Visual analysis |
XAI_API_KEY=your-xai-key-hereGoogle's Gemini models offer fast, multimodal AI capabilities.
$config = [
'model' => 'gemini',
'api_key' => env('GEMINI_API_KEY'),
'model_name' => 'gemini-1.5-pro',
'endpoint' => 'https://generativelanguage.googleapis.com/v1beta/models/',
'temperature' => 0.7,
];| Model | Context | Speed | Best For |
|---|---|---|---|
gemini-1.5-pro |
2M | Fast | Complex reasoning |
gemini-1.5-flash |
1M | Very Fast | Quick responses |
gemini-1.0-pro |
32k | Fast | General purpose |
-
Get API Key:
- Visit Google AI Studio
- Create API key
-
Configure:
GEMINI_API_KEY=your-gemini-key-here
Meta's Llama models via hosted providers.
$config = [
'model' => 'meta',
'api_key' => env('META_API_KEY'),
'model_name' => 'llama-3.1-70b-instruct',
'endpoint' => 'https://api.together.xyz/v1/chat/completions',
];| Model | Size | Performance |
|---|---|---|
llama-3.1-405b-instruct |
405B | Best |
llama-3.1-70b-instruct |
70B | Excellent |
llama-3.1-8b-instruct |
8B | Good |
Run AI models locally using Ollama.
-
Install Ollama:
# macOS brew install ollama # Linux curl -fsSL https://ollama.ai/install.sh | sh # Windows # Download from https://ollama.ai/download
-
Pull a Model:
ollama pull llama3.2 ollama pull mistral ollama pull phi3
$config = [
'model' => 'ollama',
'base_url' => 'http://localhost:11434',
'model_name' => 'llama3.2',
'timeout' => 30,
];| Model | Size | Best For |
|---|---|---|
llama3.2 |
3B/1B | General purpose |
mistral |
7B | Code generation |
phi3 |
3.8B | Reasoning |
codellama |
7B/13B/34B | Programming |
For remote Ollama instances:
$config = [
'model' => 'ollama',
'base_url' => 'https://your-ollama-server.com',
'api_key' => 'optional-auth-key',
'model_name' => 'llama3.2',
];DeepSeek provides cost-effective AI models.
$config = [
'model' => 'deepseek',
'api_key' => env('DEEPSEEK_API_KEY'),
'model_name' => 'deepseek-chat',
'endpoint' => 'https://api.deepseek.com/v1/chat/completions',
];DEEPSEEK_API_KEY=your-deepseek-key-hereImplement your own AI model by creating a class that implements AiModelInterface.
<?php
namespace App\Models;
use Rumenx\PhpChatbot\Contracts\AiModelInterface;
class CustomAiModel implements AiModelInterface
{
private $apiKey;
private $endpoint;
public function __construct(array $config = [])
{
$this->apiKey = $config['api_key'] ?? '';
$this->endpoint = $config['endpoint'] ?? '';
}
public function sendMessage(string $message, array $context = []): string
{
// Your custom implementation
$response = $this->callCustomAPI($message, $context);
return $response;
}
public function getModel(): string
{
return $this->model ?? 'custom-model';
}
public function setModel(string $model): void
{
$this->model = $model;
}
private function callCustomAPI(string $message, array $context): string
{
// Implement your API call logic
// Return the AI response
}
}use App\Models\CustomAiModel;
use Rumenx\PhpChatbot\PhpChatbot;
$config = [
'model' => CustomAiModel::class,
'api_key' => 'your-api-key',
'endpoint' => 'https://your-api.com/chat',
];
$model = new CustomAiModel($config);
$chatbot = new PhpChatbot($model, $config);// In your config file
return [
'model' => 'custom',
'models' => [
'custom' => [
'class' => App\Models\CustomAiModel::class,
'api_key' => env('CUSTOM_API_KEY'),
'endpoint' => 'https://api.custom.com/v1/chat',
],
],
];- Default Model: Free, instant responses for testing
- Ollama: Local development, no API costs
- OpenAI GPT-3.5: Best balance of cost/performance
- Gemini Flash: Fastest responses, good quality
- Claude Haiku: Safety-focused, reasonable cost
- Code Generation: OpenAI GPT-4, Codellama
- Creative Writing: Claude Opus, GPT-4
- Real-time Info: Grok
- Cost-sensitive: DeepSeek, Gemini Flash
| Provider | Avg Response Time | Reliability | Context Window |
|---|---|---|---|
| OpenAI | 1-3s | 99.9% | 128k |
| Anthropic | 2-4s | 99.8% | 200k |
| 0.5-2s | 99.5% | 2M | |
| xAI | 2-5s | 99.0% | 131k |
| Ollama | 5-30s | Local | Varies |
Next: Framework Integration